# MajorityVoterState#

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

Generalized q-state majority 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 majority voter model dynamics [oliveira-isotropic-1992] 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, the majority opinion $$x$$ held by all (in-)neighbours of $$i$$ is chosen. In case of a tie between two or more opinions, a random choice between them is made. The chosen opinion is then copied, i.e. $$s_i(t+1) = x$$.

References

de Oliveira, M.J., “Isotropic majority-vote model on a square lattice”, J Stat Phys 66: 273 (1992). DOI: 10.1007/BF01060069 [sci-hub, @tor].

Examples

>>> g = gt.collection.data["pgp-strong-2009"]
>>> state = gt.MajorityVoterState(g, q=4)
>>> x = [[] for r in range(4)]
>>> for t in range(2000):
...     ret = state.iterate_async(niter=g.num_vertices())
...     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("majority-voter.svg")


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. single vertex chosen randomly), niter number of times. iterate_sync([niter]) Updates nodes synchronously (i.e. a full "sweep" of all nodes in parallel), niter number of times. Resets list of "active" nodes, for states where this concept is used. set_active(active) Sets the 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.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

reset_active()#

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

set_active(active)#

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