# graph_tool.dynamics.VoterState#

class graph_tool.dynamics.VoterState(g, q=2, r=0.0, s=None)[source]#

Generalized q-state voter model dynamics.

Parameters:
gGraph

Graph to be used for the dynamics

qint (optional, default: 2)

Number of opinions.

rfloat (optional, default: 0.)

Random opinion probability.

sVertexPropertyMap (optional, default: None)

Initial global state. If not provided, a random state will be chosen.

Notes

This implements the voter model dynamics [clifford-model-1973] [holley-ergodic-1075] on a network.

If a node $$i$$ is updated at time $$t$$, the transition probabilities from state $$s_i(t)$$ to state $$s_i(t+1)$$ are given as follows:

1. With a probability $$r$$ one of the $$q$$ opinions, $$x$$, is chosen uniformly at random, and assigned to $$i$$, i.e. $$s_i(t+1) = x$$.

2. Otherwise, a random (in-)neighbour $$j$$ is chosen. and its opinion is copied, i.e. $$s_i(t+1) = s_j(t)$$.

References

Clifford, P., Sudbury, A., “A model for spatial conflict”, Biometrika 60, 581–588 (1973). DOI: 10.1093/biomet/60.3.581 [sci-hub, @tor].

Holley, R. A., Liggett, T. M., “Ergodic Theorems for Weakly Interacting Infinite Systems and the Voter Model”, Ann. Probab. 3, 643–663 (1975). DOI: 10.1214/aop/1176996306 [sci-hub, @tor].

Examples

>>> g = gt.collection.data["pgp-strong-2009"]
>>> state = gt.VoterState(g, q=4)
>>> x = [[] for r in range(4)]
>>> for t in range(2000):
...     ret = state.iterate_sync()
...     s = state.get_state().fa
...     for r in range(4):
...         x[r].append((s == r).sum())
>>> figure(figsize=(6, 4))
<...>
>>> for r in range(4):
...     plot(x[r], label="Opinion %d" % r)
[...]
>>> xlabel(r"Time")
Text(...)
>>> ylabel(r"Number of nodes")
Text(...)
>>> legend(loc="best")
<...>
>>> tight_layout()
>>> savefig("voter.svg") Number of nodes with a given opinion vs. time for a voter model dynamics with $$q=4$$ opinions.#

Methods

 Return a copy of the state. Returns list of "active" nodes, for states where this concept is used. Returns the internal VertexPropertyMap with the current state. iterate_async([niter]) Updates nodes asynchronously (i.e. iterate_sync([niter]) Updates nodes synchronously (i.e. Resets list of "active" nodes, for states where this concept is used.
copy()#

Return a copy of the state.

get_active()#

Returns list of “active” nodes, for states where this concept is used.

get_state()#

Returns the internal VertexPropertyMap with the current state.

iterate_async(niter=1)#

Updates nodes asynchronously (i.e. single vertex chosen randomly), niter number of times. This function returns the number of nodes that changed state.

iterate_sync(niter=1)#

Updates nodes synchronously (i.e. a full “sweep” of all nodes in parallel), niter number of times. This function returns the number of nodes that changed state.

If enabled during compilation, this algorithm runs in parallel (i.e. using more than one thread.)

reset_active()#

Resets list of “active” nodes, for states where this concept is used.