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 below epsilon or the number of iterations exceeds max_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 (a VertexPropertyMap), computed as the negative energy of s` minus the logarithm of the partition function.

marginal_log_prob(s)

Obtains the marginal log-probability of state s (a VertexPropertyMap).

marginal_sample([update_marginals, val_type])

Samples a state from the marignal distribution.

sample_energy(s)

Obtains the energy (Hamiltonean) of state s (a VertexPropertyMap).

update_marginals()

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 below epsilon or the number of iterations exceeds max_niter.

If update_marignals=True, this function calls update_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 calls update_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 (a VertexPropertyMap), computed as the negative energy of s` minus the logarithm of the partition function.

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 (a VertexPropertyMap).

If s is 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 VertexPropertyMap of type given by val_type.

If update_marignals=True, this function calls update_marginals() before sampling.

sample_energy(s)[source]#

Obtains the energy (Hamiltonean) of state s (a VertexPropertyMap).

If s is vector valued, it’s assumed to correspond to multiple states, and the total energy sum is returned.

update_marginals()[source]#

Update the node marginals from the current messages.