API: Turing.Optimisation

SciMLBase.OptimizationProblemMethod
OptimizationProblem(log_density::OptimLogDensity, adtype, constraints)

Create an OptimizationProblem for the objective function defined by log_density.

source
Turing.Optimisation.MAPType
MAP <: ModeEstimator

Concrete type for maximum a posteriori estimation. Only used for the Optim.jl interface.

source
Turing.Optimisation.ModeEstimationConstraintsType
ModeEstimationConstraints

A struct that holds constraints for mode estimation problems.

The fields are the same as possible constraints supported by the Optimization.jl: ub and lb specify lower and upper bounds of box constraints. cons is a function that takes the parameters of the model and returns a list of derived quantities, which are then constrained by the lower and upper bounds set by lcons and ucons. We refer to these as generic constraints. Please see the documentation of Optimization.jl for more details.

Any of the fields can be nothing, disabling the corresponding constraints.

source
Turing.Optimisation.ModeEstimatorType
ModeEstimator

An abstract type to mark whether mode estimation is to be done with maximum a posteriori (MAP) or maximum likelihood estimation (MLE). This is only needed for the Optim.jl interface.

source
Turing.Optimisation.ModeResultType
ModeResult{
    V<:NamedArrays.NamedArray,
    M<:NamedArrays.NamedArray,
    O<:Optim.MultivariateOptimizationResults,
    S<:NamedArrays.NamedArray
}

A wrapper struct to store various results from a MAP or MLE estimation.

source
Turing.Optimisation.ModeResultMethod
ModeResult(log_density::OptimLogDensity, solution::SciMLBase.OptimizationSolution)

Create a ModeResult for a given log_density objective and a solution given by solve.

Optimization.solve returns its own result type. This function converts that into the richer format of ModeResult. It also takes care of transforming them back to the original parameter space in case the optimization was done in a transformed space.

source
Turing.Optimisation.OptimLogDensityMethod
(f::OptimLogDensity)(z)
(f::OptimLogDensity)(z, _)

Evaluate the negative log joint or log likelihood at the array z. Which one is evaluated depends on the context of f.

Any second argument is ignored. The two-argument method only exists to match interface the required by Optimization.jl.

source
Turing.Optimisation.OptimLogDensityMethod
OptimLogDensity(model::DynamicPPL.Model, context::OptimizationContext)

Create a callable OptimLogDensity struct that evaluates a model using the given context.

source
Turing.Optimisation.OptimizationContextType
OptimizationContext{C<:AbstractContext} <: AbstractContext

The OptimizationContext transforms variables to their constrained space, but does not use the density with respect to the transformation. This context is intended to allow an optimizer to sample in R^n freely.

source
Base.getMethod
Base.get(m::ModeResult, var_symbol::Symbol)
Base.get(m::ModeResult, var_symbols::AbstractVector{Symbol})

Return the values of all the variables with the symbol(s) var_symbol in the mode result m. The return value is a NamedTuple with var_symbols as the key(s). The second argument should be either a Symbol or a vector of Symbols.

source
Turing.Optimisation.estimate_modeFunction
estimate_mode(
    model::DynamicPPL.Model,
    estimator::ModeEstimator,
    [solver];
    kwargs...
)

Find the mode of the probability distribution of a model.

Under the hood this function calls Optimization.solve.

Arguments

  • model::DynamicPPL.Model: The model for which to estimate the mode.
  • estimator::ModeEstimator: Can be either MLE() for maximum likelihood estimation or MAP() for maximum a posteriori estimation.
  • solver=nothing. The optimization algorithm to use. Optional. Can be any solver recognised by Optimization.jl. If omitted a default solver is used: LBFGS, or IPNewton if non-box constraints are present.

Keyword arguments

  • initial_params::Union{AbstractVector,Nothing}=nothing: Initial value for the optimization. Optional, unless non-box constraints are specified. If omitted it is generated by either sampling from the prior distribution or uniformly from the box constraints, if any.
  • adtype::AbstractADType=AutoForwardDiff(): The automatic differentiation type to use.
  • Keyword arguments lb, ub, cons, lcons, and ucons define constraints for the optimization problem. Please see ModeEstimationConstraints for more details.
  • Any extra keyword arguments are passed to Optimization.solve.
source
Turing.Optimisation.generate_initial_paramsMethod
generate_initial_params(model::DynamicPPL.Model, initial_params, constraints)

Generate an initial value for the optimization problem.

If initial_params is not nothing, a copy of it is returned. Otherwise initial parameter values are generated either by sampling from the prior (if no constraints are present) or uniformly from the box constraints. If generic constraints are set, an error is thrown.

source