PottsGlauberState#
- class graph_tool.dynamics.PottsGlauberState(g, f, w=1, h=0, s=None, shift=0)[git][source]#
Bases:
DiscreteStateBaseGlauber dynamics of the generalized Potts model.
- Parameters:
- g
Graph 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.
- w
EdgePropertyMaporfloat(optional, default:1.) Edge interaction strength. If a scalar is provided, it’s used for all edges.
- h
VertexPropertyMapor iterable orfloat(optional, default:0.) Vertex local field. It should be a property map of type
vector<double>. If an iterable is provided, it will be used as the field for all vertices. Each vertex needs \(q\) field values. If a scalar is provided, it will be used for all spin values and vertices.- s
VertexPropertyMap(optional, default:None) Initial global state. If not provided, a random state will be chosen.
- shift
int(optional, default:0) The node states will be assumed to lie in the range
[shift, shift+q-1], which will then be translated to the range[0, q-1]before the transition probabilities are computed. AValueErroris raised by the update functions if a state lies outside this range.
- g
Notes
This implements the Glauber dynamics of the generalized 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 with probability
\[P(s_i(t+1)|\boldsymbol s(t)) \propto \exp\left(\sum_jA_{ij}w_{ij}f_{s_i(t+1), s_j(t)} + h^{(i)}_{s_i(t+1)}\right)\]References
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="glauber-potts.svg") <...>
State of a Glauber Potts dynamics with \(q=4\) on a political blog network.#
Methods
copy()Return a copy of the state.
Returns list of "active" nodes, for states where this concept is used.
Returns the internal
VertexPropertyMapwith 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.
- get_state()[git]#
Returns the internal
VertexPropertyMapwith the current state.
- iterate_async(niter=1)[git]#
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)[git]#
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.