BPBaseState#
- class graph_tool.dynamics.BPBaseState[source]#
Bases:
ABC
Base class for belief propagation (BP) states.
Methods
converge
([epsilon, max_niter, update_marginals])Calls
iterate()
until delta falls belowepsilon
or the number of iterations exceedsmax_niter
.copy
()Return a copy of the state.
energy
(s)Obtains the energy (Hamiltonean) of state
s
(aVertexPropertyMap
).iterate
([niter, parallel, update_marginals])Updates meassages synchronously (or asyncrhonously if
parallel=False
), niter number of times.log_Z
()Obtains the log-partition function from the current messages.
log_prob
(s)Obtains the log-probability of state
s
(aVertexPropertyMap
).Obtains the marginal log-probability of state
s
(aVertexPropertyMap
).sample
([update_marginals, val_type])Samples a state from the marignal distribution.
Update the node marginals from the current messages.
- converge(epsilon=1e-08, max_niter=1000, update_marginals=True, **kwargs)[source]#
Calls
iterate()
until delta falls belowepsilon
or the number of iterations exceedsmax_niter
.If
update_marignals=True
, this function callsupdate_marginals()
at the end.The remaining keyword arguments are passed to
iterate()
.
- energy(s)[source]#
Obtains the energy (Hamiltonean) of state
s
(aVertexPropertyMap
).If
s
is vector valued, it’s assumed to correspond to multiple states, and the total energy sum is returned.
- iterate(niter=1, parallel=True, update_marginals=True)[source]#
Updates meassages synchronously (or asyncrhonously if
parallel=False
), niter number of times. This function returns the interation delta of the last iteration.If
update_marignals=True
, this function callsupdate_marginals()
at the end.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.
- log_prob(s)[source]#
Obtains the log-probability of state
s
(aVertexPropertyMap
).If
s
is vector valued, it’s assumed to correspond to multiple states, and the total log-probability sum is returned.
- marginal_log_prob(s)[source]#
Obtains the marginal log-probability of state
s
(aVertexPropertyMap
).If
s
is vector valued, it’s assumed to correspond to multiple states, and the total marginal log-probability sum is returned.
- sample(update_marginals=True, val_type='int')[source]#
Samples a state from the marignal distribution. This functio returns a
VertexPropertyMap
of type given byval_type
.If
update_marignals=True
, this function callsupdate_marginals()
before sampling.