API reference
Docstrings
Belief Propagation
BeliefPropagation.BP — TypeBP{F<:BPFactor, FV<:BPFactor, M, MB, G<:FactorGraph}A type representing the state of the Belief Propagation algorithm.
Fields
g: aFactorGraph(see IndexedFactorGraphs.jl)ψ: a vector ofBPFactorrepresenting the factors {ψₐ(xₐ)}ₐϕ: a vector ofBPFactorrepresenting the single-variable factors {ϕᵢ(xᵢ)}ᵢu: messages from factor to variableh: messages from variable to factorb: beliefs
BeliefPropagation.BP — MethodBP(g::FactorGraph, ψ::AbstractVector{<:BPFactor}, states; ϕ)Constructor for the BP type.
Arguments
BeliefPropagation.BPFactor — TypeBPFactorAn abstract type representing a factor.
BeliefPropagation.BeliefConvergence — TypeBeliefConvergenceCalled after an iteration in a callback, it computes the maximum absolute change in beliefs with (::BeliefConvergence)(::BP, errv, errf, errb, it)
BeliefPropagation.Callback — Typeabstract type CallbackSubtypes can be used as callbacks during the iterations.
BeliefPropagation.ConvergenceChecker — Typeabstract type ConvergenceCheckerSubtypes such as MessageConvergence compute convergence errors
BeliefPropagation.Decimation — TypeDecimation(n, maxiter, tol)Return an instance of the Decimation callback.
Arguments
n: total number of variablesmaxiter: maximum number of iterationstol: tolerance for convergence check
Optional arguments
conv_checker: aConvergenceCheckersoftinf: the real value used to fix variables
BeliefPropagation.Decimation — TypeDecimation <: CallbackA callback that implements the decimation procedure: whenever the desired convergence tolerance has been reached, the variable with the most biased belief is fixed to that value by modifying the corresponding ϕ factor. The procedure is repeated until all variables are fixed. The recommended constructor is Decimation(n::Integer, tol::Real).
BeliefPropagation.MessageConvergence — TypeMessageConvergenceCalled after an iteration in a callback, it computes the maximum absolute change in messages with (::MessageConvergence)(::BP, errv, errf, errb, it)
BeliefPropagation.ProgressAndConvergence — TypeProgressAndConvergence(maxiter, tol)Return an instance of the ProgressAndConvergence callback.
Arguments
maxiter: maximum number of iterationstol: tolerance for convergence check
Optional arguments
conv_checker: aConvergenceChecker
BeliefPropagation.ProgressAndConvergence — TypeProgressAndConvergence <: CallbackA basic callback that prints a progress bar and checks convergence.ù The recommended constructor is ProgressAndConvergence(maxiter::Integer, tol::Real).
Fields
prog: aProgressfrom ProgressMeter.jltol: the tolerance below which BP is considered at a fixed pointconv_checker: aConvergenceChecker
BeliefPropagation.TabulatedBPFactor — TypeTabulatedBPFactorA type of BPFactor constructed by specifying the output to any input in a tabular fashion via an array values.
BeliefPropagation.UniformFactor — TypeUniformFactorA type of BPFactor which returns the same value for any input: it behaves as if it wasn't even there. It is used as the default for single-variable factors
BeliefPropagation.avg_energy — Methodavg_energy([f], bp::BP)Return the average energy
\[\langle E \rangle =\sum_a\sum_{\underline{x}_a}b_a(\underline{x}_a) \left[-\log\psi_a(\underline{x}_a)\right] + \sum_i\sum_{x_i}b_i(x_i) \left[-\log\phi_i(x_i)\right]\]
BeliefPropagation.beliefs — Methodbeliefs([f], bp::BP)Return single-variable beliefs $\{b_i(x_i)\}_i$.
BeliefPropagation.bethe_free_energy — Methodbethe_free_energy([f], bp::BP)Return the bethe free energy
\[F=\sum_a\sum_{\underline{x}_a}b_a(\underline{x}_a) \left[-\log\frac{b_a(\underline{x}_a)}{\psi_a(\underline{x}_a)}\right] + \sum_i\sum_{x_i}b_i(x_i) \left[-\log\frac{b_i(x_i)^{1-\lvert\partial i\rvert}}{\phi_i(x_i)}\right]\]
BeliefPropagation.energy — Methodenergy(bp::BP, x)Return the energy
\[E(\underline{x})=\sum_a \left[-\log\psi_a(\underline{x}_a)\right] + \sum_i \left[-\log\phi_i(x_i)\right]\]
of configuration x.
BeliefPropagation.evaluate — Methodevaluate(bp::BP, x)Return the unnormalized probability $\prod_a\psi_a(\underline{x}_a)\prod_i\phi_i(x_i)$ of configuration x.
BeliefPropagation.factor_beliefs — Methodfactor_beliefs([f], bp::BP)Return factor beliefs $\{b_a(\underline{x}_a)\}_a$.
BeliefPropagation.iterate! — Methoditerate!(bp::BP; kwargs...)Run BP.
Optional arguments
update_variable!: the function that computes and updates variable-to-factor messagesupdate_factor!: the function that computes and updates factor-to-variable messagesmaxiter: maximum number of iterationstol: convergence check parameterdamp: damping parameterrein: reinforcement parametercallbacks: a vector of callbacks. By default aProgressAndConvergence- extra arguments to be passed to custom
update_variable!andupdate_factor!
BeliefPropagation.iterate_ms! — Methoditerate_ms!(bp::BP; kwargs...)Runs the max-sum algorithm (BP at zero temperature).
BeliefPropagation.nstates — Methodnstates(bp::BP, i::Integer)Return the number of values taken by variable i.
BeliefPropagation.randomize! — Methodrandomize!([rng], bp::BP)Fill messages and belief with random values
BeliefPropagation.reset! — Methodreset!(bp::BP)Reset all messages and beliefs to zero
Models
BeliefPropagation.Models.ColoringCoupling — TypeColoringCouplingA type of BPFactor representing a factor in the coloring problem. It always involves two (discrete) incident variables $x_i$, $x_j$. The factor evaluates to $\psi(x_i,x_j)=1-\delta(x_i,x_j)$
BeliefPropagation.Models.IsingCoupling — TypeIsingCouplingA type of BPFactor representing a factor in an Ising distribution. It involves $\pm 1$ variables $\boldsymbol{\sigma}_a=\{\sigma_1, \sigma_2, \ldots\}$. The factor evaluates to $\psi(\boldsymbol{\sigma}_a)=e^{\beta J \prod_{i\in a}\sigma_i}$. A particular case is the pairwise interaction where $a=\{i,j\}$ is a pair of vertices involved in an edge $(ij)$.
Fields
βJ: coupling strength.
BeliefPropagation.Models.IsingField — TypeIsingFieldA type of BPFactor representing a single-variable external field in an Ising distribution. The factor evaluates to $\psi(\sigma_i)=e^{\beta h \sigma_i}$.
Fields
βh: field strength.
BeliefPropagation.Models.KSATClause — TypeKSATClauseA type of BPFactor representing a clause in a k-SAT formula. It involves $\{0,1\}$ variables $\boldsymbol{x}_a=\{x_1, x_2, \ldots, x_k\}$. The factor evaluates to $\psi_a(\boldsymbol{x}_a)=1 - \prod_{i\in a}\delta(x_i, J^a_{i})$.
Fields
J: a vector of booleans.
BeliefPropagation.Models.SoftColoringCoupling — TypeSoftColoringCouplingA soft version of ColoringCoupling. It always involves two (discrete) incident variables $x_i$, $x_j$. The factor evaluates to $\psi(x_i,x_j)=e^{-\beta\delta(x_i,x_j)}$
Fields
β: the real parameter controlling the softness. AColoringCouplingis recovered in the large β limit.
BeliefPropagation.Models.fast_ising_bp — Functionfast_ising_bp(g::AbstractFactorGraph, ψ::Vector{<:IsingCoupling}, [ϕ])Return a BP instance with Ising factors and messages and beliefs in log-ratio format:
\[\begin{align*} &m_{a\to i}(\sigma_i) \propto e^{u_{a\to i}\sigma_i}\\ &u_{a\to i} = \frac12\log\frac{m_{a\to i}(+1)}{m_{a\to i}(+1)} \end{align*}\]
BeliefPropagation.Models.fast_ksat_bp — Functionfast_ksat_bp(g::AbstractFactorGraph, ψ::Vector{<:KSATClause}, [ϕ])Return a specialized BP instance with KSATClause and messages encoded as reals instead of vectors: only the probability of x=1 is stored. ```
Test utilities
BeliefPropagation.TabulatedBPFactor — MethodTabulatedBPFactor(f::BPFactor, states)Construct a TabulatedBPFactor out of any BPFactor. Used mostly for tests.
BeliefPropagation.Test.exact_avg_energy — Methodexact_avg_energy(bp::BP; p_exact = exact_prob(bp))Exhaustively compute the average energy (minus the log of the unnormalized probability weight).
BeliefPropagation.Test.exact_factor_marginals — Methodexact_factor_marginals(bp::BP; p_exact = exact_prob(bp))Exhaustively compute marginal distributions for each f_vertex.
BeliefPropagation.Test.exact_marginals — Methodexact_marginals(bp::BP; p_exact = exact_prob(bp))Exhaustively compute marginal distributions for each variable.
BeliefPropagation.Test.exact_minimum_energy — Methodexact_minimum_energy(bp::BP)Exhaustively compute the minimum energy (minus the log of the unnormalized probability weight).
BeliefPropagation.Test.exact_normalization — Methodexact_normalization(bp::BP)Exhaustively compute the normalization constant.
BeliefPropagation.Test.exact_prob — Methodexact_prob(bp::BP; Z = exact_normalization(bp))Exhaustively compute the probability of each possible configuration of the variables.
BeliefPropagation.Test.make_generic — Methodmake_generic(bp::BP)Return the corresponding BP with plain TabulatedBPFactor as factors. Used to test specific implementations.
BeliefPropagation.Test.rand_bp — Methodrand_bp([rng], g::FactorGraph, states)Return a BP with random factors.
states is an iterable containing the number of values that can be taken by each variable.
BeliefPropagation.Test.rand_factor — Methodrand_factor([rng,], states)Return a random BPFactor whose domain is specified by the iterable states.
BeliefPropagation.Test.test_observables_bp — Methodtest_observables_bp(bp::BP; kwargs...)Test beliefs_bp, factor_beliefs_bp and bethe_free_energy_bp against the same quantities computed exactly by exhaustive enumeration.
BeliefPropagation.Test.test_observables_bp_generic — Methodtest_observables_bp_generic(bp::BP, bp_generic::BP; kwargs...)Test beliefs_bp, factor_beliefs_bp and bethe_free_energy_bp against the same quantities on a generic version. See also make_generic
BeliefPropagation.Test.test_za — Methodtest_za(bp::BP)Test a specific implementation of compute_za against the naive one.
Index
BeliefPropagation.BPBeliefPropagation.BPBeliefPropagation.BPFactorBeliefPropagation.BeliefConvergenceBeliefPropagation.CallbackBeliefPropagation.ConvergenceCheckerBeliefPropagation.DecimationBeliefPropagation.DecimationBeliefPropagation.MessageConvergenceBeliefPropagation.Models.ColoringCouplingBeliefPropagation.Models.IsingCouplingBeliefPropagation.Models.IsingFieldBeliefPropagation.Models.KSATClauseBeliefPropagation.Models.SoftColoringCouplingBeliefPropagation.ProgressAndConvergenceBeliefPropagation.ProgressAndConvergenceBeliefPropagation.TabulatedBPFactorBeliefPropagation.TabulatedBPFactorBeliefPropagation.UniformFactorBeliefPropagation.Models.fast_ising_bpBeliefPropagation.Models.fast_ksat_bpBeliefPropagation.Test.exact_avg_energyBeliefPropagation.Test.exact_factor_marginalsBeliefPropagation.Test.exact_marginalsBeliefPropagation.Test.exact_minimum_energyBeliefPropagation.Test.exact_normalizationBeliefPropagation.Test.exact_probBeliefPropagation.Test.make_genericBeliefPropagation.Test.rand_bpBeliefPropagation.Test.rand_factorBeliefPropagation.Test.test_observables_bpBeliefPropagation.Test.test_observables_bp_genericBeliefPropagation.Test.test_zaBeliefPropagation.avg_energyBeliefPropagation.beliefsBeliefPropagation.bethe_free_energyBeliefPropagation.energyBeliefPropagation.evaluateBeliefPropagation.factor_beliefsBeliefPropagation.iterate!BeliefPropagation.iterate_ms!BeliefPropagation.nstatesBeliefPropagation.randomize!BeliefPropagation.reset!