Helper nodes and message types
This page covers two nodes that are not a distribution family with parameters, a message type for the shape of a Gamma, and a constructor that models use. The two nodes send a fixed message towards out, which is exact under any factorisation.
StandaloneDistribution
StandaloneDistribution makes a fixed distribution a factor. Its interface distribution holds the distribution as a constant, and the message towards out is that distribution.
\[f(\mathrm{out}, d) = d(\mathrm{out})\]
MessagePassingRulesBase.rule_coverage(StandaloneDistribution)| DefaultAlgorithm | |
|---|---|
| → out | ✓ |
| → distribution | |
| average energy | ✓ |
The rule reads the constant as a point-mass marginal that holds the distribution. The card calls the rule variational because it takes a marginal, but the message is the distribution itself:
@call_message_update_rule(node = StandaloneDistribution, target = :out, q = (distribution = PointMass(Beta(2.0, 3.0)),))Result
| value | Distributions.Beta{Float64}(α=2.0, β=3.0) |
|---|---|
| type | Distributions.Beta{Float64} |
| log scale | 0 (declared) |
Inputs
| edge | value | |
|---|---|---|
| distribution | q | PointMass{Beta{Float64}}(Distributions.Beta{Float64}(α=2.0, β=3.0)) |
Rule
| declared inputs | q[:distribution]::BayesBase.PointMass{<:Distributions.Distribution} |
|---|---|
| algorithm | DefaultAlgorithm() |
| log scale | 0 |
| defined | standalone_distribution/out.jl:1 |
| body | args->BayesBase.getpointmass(args.q[:distribution]) |
Limitations. No rule towards distribution, which must be a constant.
StandardMessagePassingRules.StandaloneDistribution — Type
StandaloneDistributionThe node out ~ d for a distribution value d of any family, given on its interface distribution as a constant: what a model writes as x ~ prior, with prior a distribution rather than a family and its parameters. Its interfaces are out and distribution, and it runs under DefaultAlgorithm.
Rules. The message towards out is d itself, from the marginal of distribution, a PointMass holding d; its log scale is zero. There is no rule towards distribution, which must be a constant. The average energy is the cross entropy E_q[-log d(out)] = KL(q ‖ d) + H(q), defined for every pair (q, d) for which Distributions has a kldivergence.
Examples
julia> prior = Beta(2.0, 3.0);
julia> getresult(@call_message_update_rule(node = StandaloneDistribution, target = :out, q = (distribution = PointMass(prior),))) === prior
trueSee also Uninformative.
Uninformative
Uninformative is the factor of one. Its message is Uninformative(), which leaves every product unchanged.
\[f(\mathrm{out}) = 1\]
MessagePassingRulesBase.rule_coverage(Uninformative)| DefaultAlgorithm | |
|---|---|
| → out | ✓ |
| average energy | ✓ |
Limitations. Uninformative() is not a distribution, and its message declares no log scale.
StandardMessagePassingRules.Uninformative — Type
Uninformative()The uninformative node, a factor of one over its single interface out, and the value of its message. The rule towards out takes no inputs and returns Uninformative() itself; it declares no log scale, so the message's log scale is undefined. Uninformative() is the identity of prod under the default product rule, so it changes nothing it is multiplied with. The average energy is zero.
A model uses it to leave a variable without a prior, x ~ Uninformative(), where every other factor on x then decides its marginal. Uninformative() is not a distribution and has no mean or density, so a variable needs some other factor for its marginal to be one.
Examples
julia> prior = NormalMeanVariance(0.0, 1.0);
julia> prod(GenericProd(), Uninformative(), prior) === prior
true
julia> prod(GenericProd(), Uninformative(), Uninformative())
Uninformative()See also StandaloneDistribution.
GammaShapeLikelihood
GammaShapeLikelihood is the message towards the shape of a Gamma, from GammaShapeRate and from GammaMixture. ExponentialFamily has no closed-form conjugate prior for a Gamma's shape, so the message is a type of its own.
StandardMessagePassingRules.GammaShapeLikelihood — Type
GammaShapeLikelihood(p::Real, γ::Real)The likelihood of a Gamma distribution's shape α, the unnormalised density
\[f(α) = \exp(γ α - p \log Γ(α)), \quad α > 0,\]
which is the message towards the shape of a GammaShapeRate node, with p = 1 and γ = E[log β] + E[log out], and towards a shape (:a, k) of a GammaMixture, with p the component's responsibility. p and γ are promoted to one type.
It has logpdf, support (the positive half line) and params, (p, γ), but no mean or normaliser. The product of two of them is a GammaShapeLikelihood again, with the parameters added; with any other distribution the default product is a lazy ProductOf.
Examples
julia> left, right = GammaShapeLikelihood(1.0, 2.0), GammaShapeLikelihood(0.5, -1.0);
julia> product = prod(GenericProd(), left, right);
julia> product isa GammaShapeLikelihood && all(params(product) .≈ (1.5, 1.0))
true
julia> logpdf(left, 1.0) ≈ 2.0
truediageye
diageye(n) returns the n×n identity as a dense matrix. It is MessagePassingRulesBase's diageye, and this package exports it so that models can write covariances and precisions with it.