quimb.experimental.belief_propagation.bp_common

Classes

RollingDiffMean

Tracker for the absolute rolling mean of diffs between values, to

BeliefPropagationCommon

Common interfaces for belief propagation algorithms.

Functions

prod(xs)

Product of all elements in xs.

initialize_hyper_messages(tn[, fill_fn, smudge_factor])

Initialize messages for belief propagation, this is equivalent to doing

combine_local_contractions(tvals, mvals, backend[, ...])

contract_hyper_messages(tn, messages[, ...])

Estimate the contraction of tn given messages, via the

compute_index_marginal(tn, ind, messages)

Compute the marginal for a single index given messages.

compute_tensor_marginal(tn, tid, messages)

Compute the marginal for the region surrounding a single tensor/factor

compute_all_index_marginals_from_messages(tn, messages)

Compute all index marginals from belief propagation messages.

maybe_get_thread_pool(thread_pool)

Get a thread pool if requested.

create_lazy_community_edge_map(tn[, site_tags, ...])

For lazy BP algorithms, create the data structures describing the

Module Contents

quimb.experimental.belief_propagation.bp_common.prod(xs)

Product of all elements in xs.

class quimb.experimental.belief_propagation.bp_common.RollingDiffMean(size=16)

Tracker for the absolute rolling mean of diffs between values, to assess effective convergence of BP above actual message tolerance.

size = 16
diffs = []
last_x = None
dxsum = 0.0
update(x)
absmeandiff()
class quimb.experimental.belief_propagation.bp_common.BeliefPropagationCommon

Common interfaces for belief propagation algorithms.

Parameters:
  • max_iterations (int, optional) – The maximum number of iterations to perform.

  • tol (float, optional) – The convergence tolerance for messages.

  • progbar (bool, optional) – Whether to show a progress bar.

run(max_iterations=1000, tol=5e-06, info=None, progbar=False)
quimb.experimental.belief_propagation.bp_common.initialize_hyper_messages(tn, fill_fn=None, smudge_factor=1e-12)

Initialize messages for belief propagation, this is equivalent to doing a single round of belief propagation with uniform messages.

Parameters:
  • tn (TensorNetwork) – The tensor network to initialize messages for.

  • fill_fn (callable, optional) – A function to fill the messages with, of signature fill_fn(shape).

  • smudge_factor (float, optional) – A small number to add to the messages to avoid numerical issues.

Returns:

messages – The initial messages. For every index and tensor id pair, there will be a message to and from with keys (ix, tid) and (tid, ix).

Return type:

dict

quimb.experimental.belief_propagation.bp_common.combine_local_contractions(tvals, mvals, backend, strip_exponent=False, check_for_zero=True)
quimb.experimental.belief_propagation.bp_common.contract_hyper_messages(tn, messages, strip_exponent=False, backend=None)

Estimate the contraction of tn given messages, via the exponential of the Bethe free entropy.

quimb.experimental.belief_propagation.bp_common.compute_index_marginal(tn, ind, messages)

Compute the marginal for a single index given messages.

Parameters:
  • tn (TensorNetwork) – The tensor network to compute the marginal for.

  • ind (int) – The index to compute the marginal for.

  • messages (dict) – The messages to use, which should match tn.

Returns:

marginal – The marginal probability distribution for the index ind.

Return type:

array_like

quimb.experimental.belief_propagation.bp_common.compute_tensor_marginal(tn, tid, messages)

Compute the marginal for the region surrounding a single tensor/factor given messages.

Parameters:
  • tn (TensorNetwork) – The tensor network to compute the marginal for.

  • tid (int) – The tensor id to compute the marginal for.

  • messages (dict) – The messages to use, which should match tn.

Returns:

marginal – The marginal probability distribution for the tensor/factor tid.

Return type:

array_like

quimb.experimental.belief_propagation.bp_common.compute_all_index_marginals_from_messages(tn, messages)

Compute all index marginals from belief propagation messages.

Parameters:
  • tn (TensorNetwork) – The tensor network to compute marginals for.

  • messages (dict) – The belief propagation messages.

Returns:

marginals – The marginals for each index.

Return type:

dict

quimb.experimental.belief_propagation.bp_common.maybe_get_thread_pool(thread_pool)

Get a thread pool if requested.

quimb.experimental.belief_propagation.bp_common.create_lazy_community_edge_map(tn, site_tags=None, rank_simplify=True)

For lazy BP algorithms, create the data structures describing the effective graph of the lazily grouped ‘sites’ given by site_tags.