graph_tool.dynamics.PottsMetropolisState#

class graph_tool.dynamics.PottsMetropolisState(g, f, w=1, h=0, s=None)[source]#

Bases: DiscreteStateBase

Metropolis-Hastings dynamics of the Potts model.

Parameters:
gGraph

Graph to be used for the dynamics

flist of lists or two-dimensional numpy.ndarray

Matrix of interactions between spin values, of dimension \(q\times q\), where \(q\) is the number of spins.

wEdgePropertyMap or float (optional, default: 1.)

Edge interaction strength. If a scalar is provided, it’s used for all edges.

hVertexPropertyMap or iterable or float (optional, default: 0.)

Vertex local field. If an iterable is provided, it will be used as the field for all vertices. If a scalar is provided, it will be used for all spins values and vertices.

sVertexPropertyMap (optional, default: None)

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

Notes

This implements the Metropolis-Hastings dynamics [metropolis-equations-1953] [hastings-monte-carlo-1970] of the Potts model [potts-model] on a network.

If a node \(i\) is updated at time \(t\), the transition to state \(s_i(t+1) \in \{0,\dots,q-1\}\) is done as follows:

  1. A spin value \(r\) is sampled uniformly at random from the set \(\{0,\dots,q-1\}\).

  2. The transition \(s_i(t+1)=r\) is made with probability

    \[\min\left[1, \exp\left(\sum_jA_{ij}w_{ij}(f_{r, s_j(t)}-f_{s_i(t), s_j(t)}) + h^{(i)}_{r} - h^{(i)}_{s_i(t)}\right)\right]\]

    otherwise we have \(s_i(t+1)=s_i(t)\).

References

[metropolis-equations-1953]

Metropolis, N., A.W. Rosenbluth, M.N. Rosenbluth, A.H. Teller, and E. Teller, “Equations of State Calculations by Fast Computing Machines,” Journal of Chemical Physics, 21, 1087–1092 (1953). DOI: 10.1063/1.1699114 [sci-hub, @tor]

[hastings-monte-carlo-1970]

Hastings, W.K., “Monte Carlo Sampling Methods Using Markov Chains and Their Applications,” Biometrika, 57, 97–109, (1970) DOI: 10.1093/biomet/57.1.97 [sci-hub, @tor]

Examples

>>> g = gt.GraphView(gt.collection.data["polblogs"].copy(), directed=False)
>>> gt.remove_parallel_edges(g)
>>> g = gt.extract_largest_component(g, prune=True)
>>> f = np.eye(4) * 0.1
>>> state = gt.PottsGlauberState(g, f)
>>> ret = state.iterate_async(niter=1000 * g.num_vertices())
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=state.s,
...               output="metropolis-potts.pdf")
<...>
../_images/metropolis-potts.png

State of a Metropolis-Hastings Potts dynamics with \(q=4\) on a political blog network.#

Methods

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])

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.

reset_active()

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.