BPBaseState#
- class graph_tool.dynamics.BPBaseState[source]#
Bases:
ABCBase class for belief propagation (BP) states.
Methods
converge([epsilon, max_niter, update_marginals])Calls
iterate()until delta falls belowepsilonor the number of iterations exceedsmax_niter.copy(**kwargs)Return a copy of the state.
iterate([niter, parallel, update_marginals])Updates meassages synchronously (or asyncrhonously if
parallel=False), niter number of times.log_Z()Obtains the log-partition function (a.k.a.
log_prob(s)Obtains the log-probability of state
s(aVertexPropertyMap), computed as the negative energy ofs`minus the logarithm of the partition function.Obtains the marginal log-probability of state
s(aVertexPropertyMap).marginal_sample([update_marginals, val_type])Samples a state from the marignal distribution.
Obtains the energy (Hamiltonean) of state
s(aVertexPropertyMap).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 belowepsilonor 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().
- copy(**kwargs)[source]#
Return a copy of the state. The keyword arguments override the constructor parameters.
- 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_Z()[source]#
Obtains the log-partition function (a.k.a. free entropy) from the current messages.
- log_prob(s)[source]#
Obtains the log-probability of state
s(aVertexPropertyMap), computed as the negative energy ofs`minus the logarithm of the partition function.If
sis 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
sis vector valued, it’s assumed to correspond to multiple states, and the total marginal log-probability sum is returned.
- marginal_sample(update_marginals=True, val_type='int')[source]#
Samples a state from the marignal distribution. This functio returns a
VertexPropertyMapof type given byval_type.If
update_marignals=True, this function callsupdate_marginals()before sampling.
- sample_energy(s)[source]#
Obtains the energy (Hamiltonean) of state
s(aVertexPropertyMap).If
sis vector valued, it’s assumed to correspond to multiple states, and the total energy sum is returned.