Priors¶
Gaussian¶
-
class
tramp.priors.
GaussianPrior
(size, mean=0, var=1, isotropic=True)[source]¶ Gaussian prior \(p(x)=\mathcal{N}(x|r, v)\)
- Parameters
size (int or tuple of int) – Shape of x
mean (float) – Mean parameter \(r\) of the Gaussian prior
var (float) – Variance parameter \(v\) of the Gaussian prior
isotropic (bool) – Using isotropic or diagonal beliefs
Definition The Gaussian prior belongs to the Normal exponential family distibution
with associated natural parameter \(a_0 = \frac{1}{v}, b_0 = \frac{r}{v}\)
Expectation propagation The scalar log-partition, posterior mean and variance are given by:
where \(A(a,b), r(a,b), v(a,b)\) are the log-partition, mean and variance of the Normal belief and \(a = a_x^- + a_0, b = b_x^- + b_0\).
A special property of the Gaussian prior is that
the output messages, sent from the prior \(p\) to the variable \(x\), are constant
\(a_{p \rightarrow x} = a_0, b_{p \rightarrow x} = b_0\).
The corresponding compute_forward_message()
method,
implemented in the base Prior
class, is overwritten
to directly send these constant messages.
State evolution The measures over \(b_x^-\) are the Gaussian measures:
where:
A special property of the Gaussian prior is that the output messages, sent from the prior \(p\) to the variable \(x\), are constant \(a_{p \rightarrow x} = a_0\). The corresponding methods:
compute_forward_state_evolution()
in a Bayes-optimal setting + Bayesian network context,compute_forward_state_evolution_BO()
in a Bayes-optimal setting + factor graph context,
implemented in the base Prior
class, are overwritten to directly send
these constant messages.
Todo
RS mismatched case GaussianPrior
Binary¶
-
class
tramp.priors.
BinaryPrior
(size, p_pos=0.5, isotropic=True)[source]¶ Binary prior \(p(x) = p_+ \delta_+(x) + p_- \delta_-(x)\)
- Parameters
size (int or tuple of int) – Shape of x
p_pos (float in (0,1)) – Parameter \(p_+\) of the binary prior
isotropic (bool) – Using isotropic or diagonal beliefs
Definition The binary prior belongs to the Binary exponential family distibution
with associated natural parameter \(b_0 = \tfrac{1}{2}\ln\tfrac{p_+}{p_-}\)
Expectation propagation The scalar log-partition, posterior mean and variance are given by:
where \(A(b), r(b), v(b)\) are the log-partition, mean and variance of the Binary belief and \(b = b_x^- + b_0\).
State evolution The measures over \(b_x^-\) are given by linear combinations of Gaussian measures:
Gauss-Bernoulli¶
-
class
tramp.priors.
GaussBernoulliPrior
(size, rho=0.5, mean=0, var=1, isotropic=True)[source]¶ Gauss-Bernoulli prior \(p(x)=[1-\rho]\delta(x)+\rho\mathcal{N}(x|r,v)\)
- Parameters
size (int or tuple of int) – Shape of x
rho (float in (0,1)) – Sparsity parameter \(\rho\) of the Gauss-Bernoulli prior
mean (float) – Mean parameter \(r\) of the Gauss-Bernoulli prior
var (float) – Variance parameter \(v\) of the Gauss-Bernoulli prior
isotropic (bool) – Using isotropic or diagonal beliefs
Definition The Gauss-Bernouilli prior belongs to the Sparse exponential family distibution
with associated natural parameters
Expectation propagation The scalar log-partition, posterior mean and variance are given by:
where \(A(a,b,\eta), r(a,b,\eta), v(a,b,\eta)\) are the log-partition, mean and variance of the Sparse belief and \(a = a_x^- + a_0, b = b_x^- + b_0\).
State evolution The measures over \(b_x^-\) are given by linear combinations of Gaussian measures:
where:
Gaussian Mixture¶
-
class
tramp.priors.
GaussianMixturePrior
(size, probs=[0.5, 0.5], means=[- 1, 1], vars=[1, 1], isotropic=True)[source]¶ Gaussian mixture prior \(p(x)=\sum_{k=1}^K p_k \mathcal{N}(x|r_k,v_k)\)
- Parameters
size (int or tuple of int) – Shape of x
probs (list of length K) – Probability parameters \(p_k\) of the Gaussian mixture prior
means (list of length K) – Mean parameters \(r_k\) of the Gaussian mixture prior
vars (list of length K) – Variance parameters \(r_k\) of the Gaussian mixture prior
isotropic (bool) – Using isotropic or diagonal beliefs
Definition The Gaussian Mixture prior belongs to the Mixture exponential family distibution
with associated natural parameters \(a_0 = \{a_k\}_{k=1}^K\), \(b_0 = \{b_k\}_{k=1}^K\), \(\eta_0 = \{\eta_k\}_{k=1}^K\) given by:
Expectation propagation The scalar log-partition, posterior mean and variance are given by:
where \(A(a,b,\eta), r(a,b,\eta), v(a,b,\eta)\) are the log-partition, mean and variance of the Mixture belief and \(a = a_x^- + a_0, b = b_x^- + b_0\).
State evolution The measures over \(b_x^-\) are given by linear combinations of Gaussian measures:
where:
Positive¶
-
class
tramp.priors.
PositivePrior
(size, isotropic=True)[source]¶ Positive prior \(p(x) = 2 * 1_+(x) \mathcal{N}(x|0,1)\)
- Parameters
size (int or tuple of int) – Shape of x
isotropic (bool) – Using isotropic or diagonal beliefs
Definition The Positive prior belongs to the Positive exponential family distibution
with associated natural parameters \(a_0 = 1, b_0 = 0\).
Expectation propagation The scalar log-partition, posterior mean and variance are given by:
where \(A_+(a,b), r_+(a,b), v_+(a,b)\) are the log-partition, mean and variance of the Positive belief and \(a = a_x^- + a_0, b = b_x^- + b_0\).
State evolution The measures over \(b_x^-\) are given by the Gaussian measures:
where:
and \(p_+(a,b)\) denotes the probability that a normal belief with natural
parameters \(ab\) falls within the \(\mathbb{R}_+\) interval, which is implemented
by the function p()
of the Positive belief.
Exponential¶
-
class
tramp.priors.
ExponentialPrior
(size, mean=1, isotropic=True)[source]¶ Exponential prior \(p(x) = 1_+(x) \frac{1}{r} e^{-\frac{x}{r}}\)
- Parameters
size (int or tuple of int) – Shape of x
mean (float in (0,1)) – Mean parameter \(r\) of the exponential prior
isotropic (bool) – Using isotropic or diagonal beliefs
Definition The Exponential prior belongs to the Exponential belief family distibution
with associated natural parameter \(b_0 = -\frac{1}{r}\).
Expectation propagation The scalar log-partition, posterior mean and variance are given by:
where \(A_+(a,b), r_+(a,b), v_+(a,b)\) are the log-partition, mean and variance of the Positive belief with \(a = a_x^- + a_0, b = b_x^- + b_0\) and \(A(b_0) = -\ln(-b_0)\) is the log-partition of the Exponential belief.
State evolution
Todo
b and bx measures ExponentialPrior
MAP L1 norm¶
-
class
tramp.priors.
MAP_L1NormPrior
(size, gamma=1, isotropic=True)[source]¶ MAP prior associated to the \(\Vert . \Vert_1\) penalty.
The corresponding factor is given by \(f(x) = e^{-\gamma \Vert x \Vert_1}\) where \(\gamma\) is the regularization parameter.
- Parameters
size (int or tuple of int) – Shape of x
gamma (float) – Regularization parameter \(\gamma\)
isotropic (bool) – Using isotropic or diagonal beliefs
Definition It corresponds to the prior obtained by the MAP approximation applied to the factor \(f(x) = e^{-E(x)}\) with a L1 penalty
where \(\gamma\) is the regularization parameter. The penalty is separable \(E(x) = \sum_{i=1}^{N_x} E(x^{[i]})\).
Expectation propagation The scalar log-partition, posterior mean and variance are given by the usual formula for MAP priors using the scalar proximal operator. For the \(\Vert . \Vert_1\) penalty, the scalar proximal operator is known as the soft thresholding operator:
MAP L21 norm¶
-
class
tramp.priors.
MAP_L21NormPrior
(size, gamma=1, axis=0, isotropic=True)[source]¶ MAP prior associated to the \(\Vert . \Vert_{2,1}\) penalty.
The corresponding factor is given by \(f(x)=e^{-\gamma \Vert x \Vert_{2,1}}\) where \(\gamma\) is the regularization parameter.
- Parameters
size (tuple of int) – Shape of x
gamma (float) – Regularization parameter \(\gamma\)
axis (int) – Axis over which the \(\Vert . \Vert_2\) norm is taken
isotropic (bool) – Using isotropic or diagonal beliefs
Definition It corresponds to the prior obtained by the MAP approximation applied to the factor \(f(x) = e^{-E(x)}\) with a L21 penalty
where \(\gamma\) is the regularization parameter. You must specify over which
axis the L2 norm is taken. For example, say the variable
\(x \in \mathbb{R}^{d \times P}\) is an array of shape \((d, P)\) and we take the
L2 norm over the axis=0
, then the L21 norm is precisely
The penalty is not separable due to the L2 norm.
Expectation propagation The vectorized log-partition, posterior mean and variance are given by the usual formula for MAP priors using the proximal operator. For the \(\Vert . \Vert_{2,1}\) penalty, the proximal operator is known as the group soft thresholding operator:
Committee Binary¶
-
class
tramp.priors.
CommitteeBinaryPrior
(N, K, p_pos=0.5)[source]¶ Committee Binary prior \(p(x) = p_+ \delta_+(x) + p_- \delta_-(x)\)
- Parameters
N (int) – Shape of x is (N, K)
K (int) – Number of experts in the committee
p_pos (float in (0,1)) – Parameter \(p_+\) of the binary prior
Definition The binary prior belongs to the Binary exponential family distibution
with associated natural parameter \(b_0 = \tfrac{1}{2}\ln\tfrac{p_+}{p_-}\).
Expectation propagation The K-committee log-partition, posterior mean and covariance are given by:
where \(A(b)\) is the log-partition of the Binary belief, \(\sigma = \mathrm{softmax}(\{A_x\})\) and for a spin configuration \(x \in (\pm)^K\) we set \(A_x = - \frac{1}{2} x \cdot a_x^- x + (b_0 + b_x^-) \cdot x\).
Warning
The committee binary prior is here implemented as an explicit summation over the \(2^K\) spin configurations, thus \(K\) cannot be too large.