Finding communities in graphs based on statistical meachanicsSource:
This function tries to find communities in graphs via a spin-glass model and simulated annealing.
The input graph, can be directed but the direction of the edges is neglected.
The weights of the edges. It must be a positive numeric vector,
NA. If it is
NULLand the input graph has a ‘weight’ edge attribute, then that attribute will be used. If
NULLand no such attribute is present, then the edges will have equal weights. Set this to
NAif the graph was a ‘weight’ edge attribute, but you don't want to use it for community detection. A larger edge weight means a stronger connection for this function.
This parameter can be used to calculate the community of a given vertex without calculating all communities. Note that if this argument is present then some other arguments are ignored.
Integer constant, the number of spins to use. This is the upper limit for the number of communities. It is not a problem to supply a (reasonably) big number here, in which case some spin states will be unpopulated.
Logical constant, whether to update the spins of the vertices in parallel (synchronously) or not. This argument is ignored if the second form of the function is used (i.e. the ‘
vertex’ argument is present). It is also not implemented in the “neg” implementation.
Real constant, the start temperature. This argument is ignored if the second form of the function is used (i.e. the ‘
vertex’ argument is present).
Real constant, the stop temperature. The simulation terminates if the temperature lowers below this level. This argument is ignored if the second form of the function is used (i.e. the ‘
vertex’ argument is present).
Cooling factor for the simulated annealing. This argument is ignored if the second form of the function is used (i.e. the ‘
vertex’ argument is present).
Character constant giving the ‘null-model’ of the simulation. Possible values: “simple” and “config”. “simple” uses a random graph with the same number of edges as the baseline probability and “config” uses a random graph with the same vertex degrees as the input graph.
Real constant, the gamma argument of the algorithm. This specifies the balance between the importance of present and non-present edges in a community. Roughly, a comunity is a set of vertices having many edges inside the community and few edges outside the community. The default 1.0 value makes existing and non-existing links equally important. Smaller values make the existing links, greater values the missing links more important.
Character scalar. Currently igraph contains two implementations for the Spin-glass community finding algorithm. The faster original implementation is the default. The other implementation, that takes into account negative weights, can be chosen by supplying ‘neg’ here.
Real constant, the gamma.minus parameter of the algorithm. This specifies the balance between the importance of present and non-present negative weighted edges in a community. Smaller values of gamma.minus, leads to communities with lesser negative intra-connectivity. If this argument is set to zero, the algorithm reduces to a graph coloring algorithm, using the number of spins as the number of colors. This argument is ignored if the ‘orig’ implementation is chosen.
vertex argument is not given, i.e. the first form is
used then a
cluster_spinglass() returns a
vertex argument is present, i.e. the second form is used then a
named list is returned with the following components:
Numeric vector giving the ids of the vertices in the same community as
The cohesion score of the result, see references.
The adhesion score of the result, see references.
The number of edges within the community of
The number of edges between the community of
vertexand the rest of the graph.
This function tries to find communities in a graph. A community is a set of nodes with many edges inside the community and few edges between outside it (i.e. between the community itself and the rest of the graph.)
This idea is reversed for edges having a negative weight, i.e. few negative edges inside a community and many negative edges between communities. Note that only the ‘neg’ implementation supports negative edge weights.
spinglass.cummunity function can solve two problems related to
community detection. If the
vertex argument is not given (or it is
NULL), then the regular community detection problem is solved
(approximately), i.e. partitioning the vertices into communities, by
optimizing the an energy function.
vertex argument is given and it is not
NULL, then it
must be a vertex id, and the same energy function is used to find the
community of the the given vertex. See also the examples below.
J. Reichardt and S. Bornholdt: Statistical Mechanics of Community Detection, Phys. Rev. E, 74, 016110 (2006), https://arxiv.org/abs/cond-mat/0603718
M. E. J. Newman and M. Girvan: Finding and evaluating community structure in networks, Phys. Rev. E 69, 026113 (2004)
V.A. Traag and Jeroen Bruggeman: Community detection in networks with positive and negative links, https://arxiv.org/abs/0811.2329 (2008).
Jorg Reichardt for the original code and Gabor Csardi firstname.lastname@example.org for the igraph glue code.
Changes to the original function for including the possibility of negative ties were implemented by Vincent Traag (http://www.traag.net/).
g <- sample_gnp(10, 5 / 10) %du% sample_gnp(9, 5 / 9) g <- add_edges(g, c(1, 12)) g <- induced_subgraph(g, subcomponent(g, 1)) cluster_spinglass(g, spins = 2) #> IGRAPH clustering spinglass, groups: 2, mod: 0.48 #> + groups: #> $`1` #>  1 2 3 4 5 6 7 8 9 10 #> #> $`2` #>  11 12 13 14 15 16 17 18 19 #> cluster_spinglass(g, vertex = 1) #> $community #>  1 2 5 6 9 7 8 10 4 3 #> #> $cohesion #>  11.66837 #> #> $adhesion #>  -23.33673 #> #> $inner.links #>  26 #> #> $outer.links #>  1 #>