This package provides utilities to deal with multivariate functions factorized over a one-dimensional chain, i.e. where each variable
where
with
In other words, a probability distribution is a chain model if its factor graph is a simple path:
For a chain of length
Operation | Cost |
---|---|
Compute normalization |
|
Compute marginals |
|
Compute neighbor marginals |
|
Compute pair marginals |
|
Draw a sample from |
|
Compute the entropy |
|
Compute the log-likelihood |
|
Compute the gradient of the log-likelihood |
The efficiency of the operations mentioned above relies on some strategic pre-computations. For example, partial normalizations from the left and from the right (
can be used to compute normalization, single-variable and nearest-neighbor marginals
- The exponential parametrization is favorable because it puts no constraint on the values taken by the
$f_i$ 's, which can be positive or negative. One might as well parametrize directly as$f(x)=\prod\limits_{i=1}^{L-1} g_i(x_i,x_{i+1})$ with$g_i(x_i,x_{i+1})=e^{f_i(x_i,x_{i+1})}$ , but must always ensure$g_i \ge 0$ .
Install with
import Pkg; Pkg.add("https://github.com/stecrotti/ChainModels.jl.git")
Create a ChainModel
and compute some stuff
using ChainModels
L = 100
q = fill(20, L)
f = [randn(q[i], q[i+1]) for i in 1:L-1]
p = ChainModel(f)
Z = normalization(p)
marg = marginals(p)
neigmarg = neighbor_marginals(p)
pairmarg = pair_marginals(p)
S = entropy(p)
x = rand(p, 500)
logL = loglikelihood(p, x)