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()

Return a copy of the state.

energy(s)

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

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

marginal_log_prob(s)

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

sample([update_marginals, val_type])

Samples a state from the marignal distribution.

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()[source]#

Return a copy of the state.

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.

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.

If enabled during compilation, this algorithm runs in parallel (i.e. using more than one thread.)

log_Z()[source]#

Obtains the log-partition function from the current messages.

log_prob(s)[source]#

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

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.

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.

update_marginals()[source]#

Update the node marginals from the current messages.