Skip to content

Commit

Permalink
SNA (#29)
Browse files Browse the repository at this point in the history
* Implemented breadth-first-search.

I implemented a function to compute all reachable nodes from a starting node via breadth-first-search. As it may be useful to also have the distances to the starting node (computing average-shortest-paths for example!) The new function returns a map with reachable nodes as keys and the distances to the starting point as values.

* New functionality: Compute the connected components of an undirected graph.

* Implemented k-cores

The new functionality allows to compute the k-cores of a given graph.
The k-cores of a graph g are the connected components of the maximal subgraph in which
each node has at least k neighbours.

* Created tests for k-cores

* Implemented k-cores for contexts

* Implemented tests for k-cores for contexts

Implemented tests for the k-cores-functions of context-to-graph-projections.

* Small cosmetics

* Added average-shortest-path-via-bfs

Added the functionality to compute the average shortest path length of a graph or context via breadth-first search.

* Created tests for avg-shortest-path-via-bfs

* Added functionality to compute clustering coefficients for graphs

Conflicts:
	src/main/clojure/conexp/fca/applications/socialanalytics.clj

* Created tests for clustering coefficients

Conflicts:
	src/test/clojure/conexp/fca/applications/socialanalytics_test.clj

* Implemented clustering-coefficient for bipartite graphs

* Created tests for two-mode clustering

Conflicts:
	src/test/clojure/conexp/fca/applications/socialanalytics_test.clj

* Implemented betweenes-centrality

* Implemented function ``close?`` to compare doubles

If functions which operate with doubles are tested, it is possible that rounding errors occur and tests like (is (= a b)) will fail.
For this reason I implemented a function ``close?`` that takes arguments x,y and epsilon and checks if |x-y| <= epsilon.

* Added tests for betweenes-centrality

* Added betweenes-centrality for contexts

* Implemented tests for betweenes-centrality for contexts

* Small cosmetics in tests

* Restructuring

I moved all stuff concerning basic graph structuring, such as breadth-first search or computing graphs from contexts into a seperated file ``structure``.

* Overwrite of adjacency-matrices and average-shortest-path

The new version stores the whole adjacency-matrix and works also for directed graphs.
Using the whole matrix and not just the upper triangle makes the code much smaller but
slows down the computation with factor 2 as a drawback.

* Added needed dependencies

* Restructured average-shortest-path

* Formatting

* Updated Contribution

* close? -> near?

---------

Co-authored-by: Maximilian Stubbemann <[email protected]>
Co-authored-by: Maximilian Stubbemann <[email protected]>
Co-authored-by: Tom Hanika <[email protected]>
  • Loading branch information
4 people authored Jan 10, 2025
1 parent 71f4995 commit aef2285
Show file tree
Hide file tree
Showing 8 changed files with 1,445 additions and 476 deletions.
4 changes: 2 additions & 2 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Additional Contributors are
* Johannes Hirth (pq-cores, Ordinal Motifs, scale-measures)
* Gleb Kanterov (interval-scale)
* Maximilian Marx (Wikidata)
* Jannik Nordmeyer (Metric Contexts, Causal Implications)
* Maximilian Stubbemann (concept-robustness)
* Maximilian Stubbemann (concept robustness, social analytics)
* Jannik Nordmeyer (Metric Contexts, Causal Implications, Fuzzy recovered)
* Anselm von Wangenheim (DimDraw)
* Johannes Wollbold (bug reports, feature requests)

15 changes: 15 additions & 0 deletions src/main/clojure/conexp/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ metadata (as provided by def) merged into the metadata of the original."
(clojure.test/is true))))
body)))

(defn near?
"Tests if the distance of `x' and `y' is not greater
then the given tolerance `epsilon'.
If no third parameter `epsilon' is provided,
epsilon is set to 0.0001
Inspired by:
https://stackoverflow.com/questions/17711308/
how-to-test-if-two-numbers-are-close-in-clojure"
([x y epsilon]
(<= (Math/abs (double (- x y))) epsilon))
([x y]
(near? x y 0.0001)))

;;; Types

(def clojure-set clojure.lang.PersistentHashSet)
Expand Down
Loading

0 comments on commit aef2285

Please sign in to comment.