Existing accumulators in DynamicPPL

DynamicPPL provides a number of built-in accumulators which can be used as-is; they cover many of the typical use-cases for accumulators.

Log-probability accumulators

DynamicPPL.LogPriorAccumulatorType
LogPriorAccumulator{T<:Real} <: LogProbAccumulator{T}

An accumulator that tracks the cumulative log prior during model execution.

Note that the log prior stored in here is always calculated based on unlinked parameters, i.e., the value of logp is independent of whether tha VarInfo is linked or not.

Fields

  • logp::Real: the scalar log prior value
source
DynamicPPL.LogLikelihoodAccumulatorType
LogLikelihoodAccumulator{T<:Real} <: LogProbAccumulator{T}

An accumulator that tracks the cumulative log likelihood during model execution.

Fields

  • logp::Real: the scalar log likelihood value
source
DynamicPPL.LogJacobianAccumulatorType
LogJacobianAccumulator{T<:Real} <: LogProbAccumulator{T}

An accumulator that tracks the cumulative log Jacobian (technically, log(abs(det(J)))) during model execution. Specifically, J refers to the Jacobian of the link transform, i.e., from the space of the original distribution to unconstrained space.

Note

This accumulator is only incremented if the variable is transformed by a link function, i.e., if the VarInfo is linked (for the particular variable that is currently being accumulated). If the variable is not linked, the log Jacobian term will be 0.

In general, for the forward Jacobian $\mathbf{J}$ corresponding to the function $\mathbf{y} = f(\mathbf{x})$,

\[\log(q(\mathbf{y})) = \log(p(\mathbf{x})) - \log (|\mathbf{J}|)\]

and correspondingly:

getlogjoint_internal(vi) = getlogjoint(vi) - getlogjac(vi)

Fields

  • logjac::Real: the logabsdet of the link transform Jacobian
source

There are various convenience functions in DynamicPPL to combine the outputs from these accumulators:

DynamicPPL.getlogjoint_internalFunction
getlogjoint_internal(vi::AbstractVarInfo)

Return the log of the joint probability of the observed data and parameters as they are stored internally in vi, including the log-Jacobian for any linked parameters.

In general, we have that:

getlogjoint_internal(vi) == getlogjoint(vi) - getlogjac(vi)
source
DynamicPPL.getlogprior_internalFunction
getlogprior_internal(vi::AbstractVarInfo)

Return the log of the prior probability of the parameters as stored internally in vi. This includes the log-Jacobian for any linked parameters.

In general, we have that:

getlogprior_internal(vi) == getlogprior(vi) - getlogjac(vi)
source
DynamicPPL.getlogjacFunction
getlogjac(vi::AbstractVarInfo)

Return the accumulated log-Jacobian term for any linked parameters in vi. The Jacobian here is taken with respect to the forward (link) transform.

See also: setlogjac!!.

source

Storing values

DynamicPPL.RawValueAccumulatorFunction
RawValueAccumulator(include_colon_eq)::Bool <: AbstractAccumulator

An accumulator that keeps tracks of the model parameters exactly as they are seen in the model.

The parameter include_colon_eq controls whether variables on the LHS of := are also included in the accumulator. If true, then these variables will be included; if false, they will not be included.

source
DynamicPPL.VectorValueAccumulatorFunction
VectorValueAccumulator()

An accumulator that collects VectorValues and LinkedVectorValues seen during model execution.

Whether a VectorValue or LinkedVectorValue is collected depends on the transform strategy used when evaluating the model. For variables that are specified as being linked (i.e., DynamicLink()), a LinkedVectorValue will be collected. Conversely, for variables that are not specified as being linked, a VectorValue will be collected.

source
DynamicPPL.VectorParamAccumulatorType
VectorParamAccumulator(ldf::DynamicPPL.LogDensityFunction)

An accumulator for collecting vectorised parameters from a model evaluation. The resulting vector will be consistent with the LogDensityFunction used to construct the accumulator, both in terms of whether parameters are transformed or not, as well as the order of the parameters in the vector.

This accumulator allows you to re-evaluate a LogDensityFunction with a different initialisation strategy and collect the vectorised parameters corresponding to that strategy.

source

and their associated convenience functions:

DynamicPPL.get_raw_valuesFunction
get_raw_values(vi::AbstractVarInfo)

Extract a VarNamedTuple of values from the RawValueAccumulator in vi. This is the 'raw' values as they are seen in the model, without any transformations applied to them.

If vi does not contain a RawValueAccumulator, this function will throw an error.

source
DynamicPPL.get_vector_valuesFunction
get_vector_values(accs::OnlyAccsVarInfo)

Get a VarNamedTuple containing vectorised values from accs. This will error if accs does not contain a VectorValueAccumulator.

Note that this function is implemented for OnlyAccsVarInfo, but not VarInfo since that could be ambiguous (VarInfo stores its own vectorised values!). If you want to extract the vectorised values from varinfo.values where varinfo isa VarInfo, you should use DynamicPPL.internal_values_as_vector(varinfo).

source
DynamicPPL.get_vector_paramsFunction
get_vector_params(vi::DynamicPPL.AbstractVarInfo)

Extract the vectorised parameters from the VectorParamAccumulator stored in the AbstractVarInfo. If there is no VectorParamAccumulator in the AbstractVarInfo, or if some indices in the output vector were not set, an error will be thrown.

source

Miscellaneous

(No convenience function for this one yet.)