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.LogPriorAccumulator — Type
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
DynamicPPL.LogLikelihoodAccumulator — Type
LogLikelihoodAccumulator{T<:Real} <: LogProbAccumulator{T}An accumulator that tracks the cumulative log likelihood during model execution.
Fields
logp::Real: the scalar log likelihood value
DynamicPPL.LogJacobianAccumulator — Type
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.
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
There are various convenience functions in DynamicPPL to combine the outputs from these accumulators:
DynamicPPL.getlogjoint — Function
getlogjoint(vi::AbstractVarInfo)Return the log of the joint probability of the observed data and parameters in vi.
See also: getlogprior, getloglikelihood.
DynamicPPL.getlogjoint_internal — Function
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)DynamicPPL.getlogprior — Function
getlogprior(vi::AbstractVarInfo)Return the log of the prior probability of the parameters in vi.
See also: getlogjoint, getloglikelihood, setlogprior!!.
DynamicPPL.getlogprior_internal — Function
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)DynamicPPL.getloglikelihood — Function
getloglikelihood(vi::AbstractVarInfo)Return the log of the likelihood probability of the observed data in vi.
See also: getlogjoint, getlogprior, setloglikelihood!!.
DynamicPPL.getlogjac — Function
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!!.
Storing values
DynamicPPL.RawValueAccumulator — Function
RawValueAccumulator(include_colon_eq)::Bool <: AbstractAccumulatorAn 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.
DynamicPPL.VectorValueAccumulator — Function
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.
DynamicPPL.VectorParamAccumulator — Type
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.
and their associated convenience functions:
DynamicPPL.get_raw_values — Function
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.
DynamicPPL.get_vector_values — Function
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).
DynamicPPL.get_vector_params — Function
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.
Miscellaneous
DynamicPPL.PriorDistributionAccumulator — Function
PriorDistributionAccumulator()An accumulator that stores the prior distributions of every variable seen in a model.
(No convenience function for this one yet.)