mcmc_equilibrate#
- graph_tool.inference.mcmc_equilibrate(state, wait=1000, nbreaks=2, max_niter=inf, force_niter=None, epsilon=0, gibbs=False, multiflip=True, mcmc_args={}, entropy_args={}, history=False, callback=None, verbose=False)[source]#
Equilibrate a MCMC with a given starting state.
- Parameters:
- stateAny state class (e.g.
BlockState
) Initial state. This state will be modified during the algorithm.
- wait
int
(optional, default:1000
) Number of iterations to wait for a record-breaking event.
- nbreaks
int
(optional, default:2
) Number of iteration intervals (of size
wait
) without record-breaking events necessary to stop the algorithm.- max_niter
int
(optional, default:numpy.inf
) Maximum number of iterations.
- force_niter
int
(optional, default:None
) If given, will force the algorithm to run this exact number of iterations.
- epsilon
float
(optional, default:0
) Relative changes in entropy smaller than epsilon will not be considered as record-breaking.
- gibbs
bool
(optional, default:False
) If
True
, each step will callstate.gibbs_sweep
instead ofstate.mcmc_sweep
.- multiflip
bool
(optional, default:True
) If
True
andstate
is an instance ofMultiflipMCMCState
, each step will callstate.multiflip_mcmc_sweep
instead ofstate.mcmc_sweep
.- mcmc_args
dict
(optional, default:{}
) Arguments to be passed to
state.mcmc_sweep
(orstate.gibbs_sweep
).- history
bool
(optional, default:False
) If
True
, a list of tuples of the form(nattempts, nmoves, entropy)
will be kept and returned, whereentropy
is the current entropy andnmoves
is the number of vertices moved.- callback
function
(optional, default:None
) If given, this function will be called after each iteration. The function must accept the current state as an argument, and its return value must be either None or a (possibly empty) list of values that will be append to the history, if
history == True
.- verbose
bool
ortuple
(optional, default:False
) If
True
, progress information will be shown. Optionally, this accepts arguments of the typetuple
of the form(level, prefix)
wherelevel
is a positive integer that specifies the level of detail, andprefix
is a string that is prepended to the all output messages.
- stateAny state class (e.g.
- Returns:
- historylist of tuples of the form
(nattempts, nmoves, entropy)
Summary of the MCMC run. This is returned only if
history == True
.- entropy
float
Current entropy value after run. This is returned only if
history == False
.- nattempts
int
Number of node move attempts.
- nmoves
int
Number of node moves.
- historylist of tuples of the form
Notes
The MCMC equilibration is attempted by keeping track of the maximum and minimum values, and waiting sufficiently long without a record-breaking event.
This function calls
state.mcmc_sweep
(orstate.gibbs_sweep
) at each iteration (e.g.graph_tool.inference.BlockState.mcmc_sweep()
andgraph_tool.inference.BlockState.gibbs_sweep()
), and keeps track of the value ofstate.entropy(**args)
withargs
corresponding tomcmc_args["entropy_args"]
.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