quimb.experimental.belief_propagation.bp_common¶
Classes¶
Tracker for the absolute rolling mean of diffs between values, to |
|
Common interfaces for belief propagation algorithms. |
Functions¶
|
Product of all elements in |
|
Initialize messages for belief propagation, this is equivalent to doing |
|
|
|
Estimate the contraction of |
|
Compute the marginal for a single index given |
|
Compute the marginal for the region surrounding a single tensor/factor |
|
Compute all index marginals from belief propagation messages. |
|
Get a thread pool if requested. |
|
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:
- 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:
- 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
givenmessages
, 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:
- 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
.