This repository contains the code relative to the paper Matrix Product Belief Propagation for reweighted stochastic dynamics over graphs (PNAS, arxiv). When possible, variable names match the notation used there. An errata file is also found here.
Usage requires Julia version >= 1.8, although 1.9 or 1.10 are recommended. You can download Julia here.
To install the package:
using Pkg; Pkg.add("MatrixProductBP")The package is based on TensorTrains.jl for the operations on tensor trains (a.k.a. matrix product states).
The directory is organized as follows:
-
The main module
MatrixProductBPimplements the BP equations. Essential ingredients are:- An
IndexedBiDiGraphon which the system is defined (for more details, see the documentation of IndexedGraphs.jl) -
BPFactors living on the factor nodes of the graph. Any concrete subtype (e.g.SISFactor) must implement a method(fᵢ::SISFactor)(xᵢᵗ⁺¹::Integer, xₙᵢᵗ::Vector{<:Integer}, xᵢᵗ::Integer)that computes the contribution of that factor to the joint probability as a function of$x_i^{t+1},\boldsymbol{x}_{\partial i}^{t}, x_i^{t}$ . - Optionally, single-node reweightings
ϕand edge reweightingsψ
Some allowed operations:
iterate!(bp::MPBP; kw...)pair_beliefs(bp::MPBP)beliefs(bp::MPBP)bethe_free_energy(bp::MPBP)
There is some montecarlo (Soft Margin) utility in
src/sampling/:-
sample(bp::MPBP, nsamples::Integer): draw samples from the prior weighted with their likelihood -
draw_node_observations!(bp::MPBP, nobs::Integer): draw samples from the prior and add them to theMPBPobject as reweighting
Code for computing probabilities exactly by exhaustive enumeration in
src/exact/(only for small system size and final time):exact_prob(bp::MPBP)
- An
-
A submodule
Modelsthat can be included with
using MatrixProductBP.Modelsthat implements two models: Glauber dynamics and the SIS model of epidemic spreading. It contains model definitions and specialized versions of the BP equations that are more efficient than the generic one.
-
A
testfolder with small examples -
A
notebooksfolder where results and plots are produced. The notebooks generating the results contained in the article output generate some data in .jld format that is then read bynotebooks/plots_for_paper.ipynbwhich produces the figures in the article.
To get a hang of how the package works, take a look at, e.g. test/glauber_small_tree.jl, notebooks/glauber_infinite_graph_large_degree_small_beta.ipynb, or notebooks/sis_compare_softmargin.ipynb.