PottsState#
- class graph_tool.inference.PottsState(g, f, b=None, eweight=None, theta=None, clabel=None, entropy_args={}, **kwargs)[git][source]#
Bases:
CLabelState,MCMCState,GibbsMCMCState,DrawBlockStateSample from a generalized Potts model.
- Parameters:
- g
Graph Graph to be modelled.
- f
ndarray \(q\times q\) symmetric matrix of spin interaction strengths.
- eweight
EdgePropertyMap(optional, default:None) Edge property map with the edge weights. If not supplied, it will be assumed to be unity.
- theta
VertexPropertyMap(optional, default:None) Vertex property map of type
vector<double>with the node fields, with at most \(q\) values per node (missing values are taken to be zero). If not supplied, it will be assumed to be zero.- b
VertexPropertyMap(optional, default:None) Initial spin labels. If not supplied, all spins will be initialized with label
0.- clabel
VertexPropertyMap(optional, default:None) Constraint labels on the vertices. If supplied, vertices with different label values will not be clustered in the same group.
- entropy_args
dict(optional, default:{}) Override default arguments for
entropy()method and related operations.
- g
See also
graph_tool.dynamics.PottsGlauberStatePotts Glauber dynamics
graph_tool.dynamics.PottsMetropolisStatePotts Metropolis dynamics
graph_tool.dynamics.GenPottsBPStateBelief propagation for the Potts model
Methods
copy(**kwargs)Copies the state.
draw(**kwargs)Convenience wrapper to
graph_draw()that draws the state of the graph as colors on the vertices and edges.entropy(**kwargs)Returns the energy of generalized Potts model.
get_N()Return the number of nodes of the state.
get_bclabel([clabel])Returns a
VertexPropertyMapcorresponding to constraint labels for the block graph.Returns a
VertexPropertyMapcorresponding to partition constraint labels for the block graph.Return the current default values for the parameters of the function
entropy(), together with other operations that depend on them.gibbs_sweep([beta, niter, entropy_args, ...])Perform
nitersweeps of a rejection-free Gibbs MCMC to sample network partitions.mcmc_sweep([beta, c, d, niter, ...])Perform
nitersweeps of a Metropolis-Hastings acceptance-rejection MCMC to sample network partitions.Reset the current default values for the parameters of the function
entropy(), together with other operations that depend on them.update_entropy_args(**kwargs)Update the default values for the parameters of the function
entropy()from the keyword arguments, in a stateful way, together with other operations that depend on them.- copy(**kwargs)[git]#
Copies the state. The parameters override the state properties, and have the same meaning as in the constructor.
- draw(**kwargs)[git]#
Convenience wrapper to
graph_draw()that draws the state of the graph as colors on the vertices and edges.
- entropy(**kwargs)[git]#
Returns the energy of generalized Potts model.
Warning
The default arguments of this function are overridden by those obtained from
get_entropy_args(). To update the defaults in a stateful way,update_entropy_args()should be called.Notes
The energy of the generalized Potts model is given by
\[H = -\sum_{i<j}w_{ij}A_{ij}f_{b_i,b_j} - \sum_i\theta^{(i)}_{b_i}.\]
- get_bclabel(clabel=None)[git]#
Returns a
VertexPropertyMapcorresponding to constraint labels for the block graph.
- get_bpclabel()[git]#
Returns a
VertexPropertyMapcorresponding to partition constraint labels for the block graph.
- get_entropy_args()[git]#
Return the current default values for the parameters of the function
entropy(), together with other operations that depend on them.
- gibbs_sweep(beta=1.0, niter=1, entropy_args={}, allow_new_group=True, sequential=True, deterministic=False, vertices=None, verbose=False, **kwargs)[git]#
Perform
nitersweeps of a rejection-free Gibbs MCMC to sample network partitions.- Parameters:
- beta
float(optional, default:1.) Inverse temperature.
- niter
int(optional, default:1) Number of sweeps to perform. During each sweep, a move attempt is made for each node.
- entropy_args
dict(optional, default:{}) Entropy arguments, with the same meaning and defaults as in
graph_tool.inference.BlockState.entropy().- allow_new_group
bool(optional, default:True) Allow the number of groups to increase and decrease.
- sequential
bool(optional, default:True) If
sequential == Trueeach vertex move attempt is made sequentially, where vertices are visited in random order. Otherwise the moves are attempted by sampling vertices randomly, so that the same vertex can be moved more than once, before other vertices had the chance to move.- deterministic
bool(optional, default:False) If
sequential == Trueanddeterministic == Truethe vertices will be visited in deterministic order.- vertices
listof ints (optional, default:None) If provided, this should be a list of vertices which will be moved. Otherwise, all vertices will.
- verbose
bool(optional, default:False) If
verbose == True, detailed information will be displayed.
- beta
- Returns:
- dS
float Entropy difference after the sweeps.
- nattempts
int Number of vertex moves attempted.
- nmoves
int Number of vertices moved.
- dS
Notes
This algorithm has an \(O(E\times B)\) complexity, where \(B\) is the number of groups, and \(E\) is the number of edges.
- mcmc_sweep(beta=1.0, c=0.5, d=0.01, niter=1, entropy_args={}, allow_vacate=True, sequential=True, deterministic=False, vertices=None, verbose=False, **kwargs)[git]#
Perform
nitersweeps of a Metropolis-Hastings acceptance-rejection MCMC to sample network partitions.- Parameters:
- beta
float(optional, default:1.) Inverse temperature.
- c
float(optional, default:.5) Sampling parameter
cfor move proposals: For \(c\to 0\) the blocks are sampled according to the local neighborhood of a given node and their block connections; for \(c\to\infty\) the blocks are sampled randomly. Note that only for \(c > 0\) the MCMC is guaranteed to be ergodic.- d
float(optional, default:.01) Probability of selecting a new (i.e. empty) group for a given move.
- niter
int(optional, default:1) Number of sweeps to perform. During each sweep, a move attempt is made for each node.
- entropy_args
dict(optional, default:{}) Entropy arguments, with the same meaning and defaults as in
graph_tool.inference.BlockState.entropy().- allow_vacate
bool(optional, default:True) Allow groups to be vacated.
- sequential
bool(optional, default:True) If
sequential == Trueeach vertex move attempt is made sequentially, where vertices are visited in random order. Otherwise the moves are attempted by sampling vertices randomly, so that the same vertex can be moved more than once, before other vertices had the chance to move.- deterministic
bool(optional, default:False) If
sequential == Trueanddeterministic == Truethe vertices will be visited in deterministic order.- vertices
listof ints (optional, default:None) If provided, this should be a list of vertices which will be moved. Otherwise, all vertices will.
- verbose
bool(optional, default:False) If
verbose == True, detailed information will be displayed.
- beta
- Returns:
- dS
float Entropy difference after the sweeps.
- nattempts
int Number of vertex moves attempted.
- nmoves
int Number of vertices moved.
- dS
Notes
This algorithm has an \(O(E)\) complexity, where \(E\) is the number of edges (independent of the number of groups).
References
[peixoto-efficient-2014]Tiago P. Peixoto, “Efficient Monte Carlo and greedy heuristic for the inference of stochastic block models”, Phys. Rev. E 89, 012804 (2014), DOI: 10.1103/PhysRevE.89.012804 [sci-hub, @tor], arXiv: 1310.4378