ProblemUpdater
MTKHelpers.ProblemUpdater
— TypeProblemUpdater(par_getter, par_setter)
Encapsulates updating an AbstractODEProblem based on the problem itself by Callable (pu::ProblemUpdater)(prob)
.
Must be initialized with a callable AbstractProblemParGetter
, e.g. KeysProblemParGetter
and on a AbstractODEProblemParSetter
, e.g. ODEProblemParSetter
.
There are special functions to construct ProblemUpdater based on a given Problem:
MTKHelpers.get_ode_problemupdater
— Functionget_ode_problemupdater(par_getter::AbstractProblemParGetter, u0, p)
get_ode_problemupdater(par_getter::AbstractProblemParGetter, sys::AbstractODESystem)
Construct a ProblemUpdater
based on an constructed ODEProblemParSetterConcrete
.
get_ode_problemupdater(par_getter::AbstractProblemParGetter, u0, p)
get_ode_problemupdater(par_getter::AbstractProblemParGetter, sys::AbstractODESystem)
Construct a ProblemUpdater
based on an constructed ODEProblemParSetterConcrete
.
MTKHelpers.NullProblemUpdater
— TypeAbstractProblemUpdater that returns the original AbstractODEProblem.
ProblemParGetter
In order to provide computations for parameters to set, declare a concrete subtype of AbstractProblemParGetter
, and implement a custom method (pg::MyProblemParGetter)(pu::ProblemUpdater, prob)
that returns a vector of parameter values.
MTKHelpers.AbstractProblemParGetter
— TypeSupertype for callables that implement (::AbstractProblemParGetter)(problem) -> updated_problem
Concrete subtypes should implement function keys
, so that an appropriate AbstractODEProblemParSetter
can be constructed for ProblemUpdater
.
One simple subtype of AbstractProblemParGetter
is KeysProblemParGetter
, which just extracts variables from the original problem to update other parameters. It can be used to ensure that some parameter of a problem will always equal another parameter of the problem.
MTKHelpers.KeysProblemParGetter
— TypeKeysProblemParGetter(mapping::NTuple{N,Pair{Symbol, Symbol}, keys_state)
Provices callable (pg::KeysProblemParGetter)(pu::ProblemUpdater, prob), keys_state]
. To be used to get the parameters/state vector to be set by ProblemUpdater
.
Initialize with an mapping of NTuples of symbols (source -> target) that index into either get_state_labeled(pu.pset, prob)
or get_par_labeled(pu.pset, prob))
. Argument keys_state
is a Tuple or Vector that iterates the Symbols in the state of an ODEProblem. It is required to know from which part of the problem to extract.
ProblemParSetter
MTKHelpers.AbstractProblemParSetter
— TypeDuring an optimization, one does not want to recreate the problem from a symbolic system, but only update the problem. This can be difficult, because the parameters to update may be spread across initial state and other parameters. Further, the order of parameters after simplifying a system is not fixed.
A AbstractProblemUpdater helps with
remake
: translate the set of parameters -> an updated problemget_paropt
: problem -> extract/approximate subset of parameters to optimize
The structure of optimized parameter Vector is described by an Axis object of ComponentArrays.jl. And several functions are defined to work with it. Specifically, the ComponentVector it employs a classification (classes_paropt
), ,e.g. :state
and :par
for ODEProblems, below which, ComponentVectors of actual parameters are listed (keys_paropt
](@ref)). Further functions extract information about the ComponentVector: axis_paropt
, , count_paropt
, symbols_paropt
or attach information to a plain vector for convenient access or display: label_paropt
, name_paropt
.
Translating between parameters and Problem
SciMLBase.remake
— Methodremake(prob::AbstractSciMLProblem, popt, ps::AbstractProblemParSetter)
Return an updated problem given the parameters. Subtypes need to implement method remake_pset(prob, popt, pset)
MTKHelpers.get_paropt
— Methodget_paropt(pset::AbstractProblemParSetter, prob::SciMLBase.AbstractSciMLProblem; kwargs...)
get_paropt_labeled(pset::AbstractProblemParSetter, prob::SciMLBase.AbstractSciMLProblem; kwargs...)
Extract optimized parameters from the Problem. The labeled versions additionally calls label_paropt
on the return value.
Helper functions to access optimized parameters
MTKHelpers.axis_paropt
— Methodaxis_paropt(pset::AbstractProblemParSetter)
axis_paropt_scalar(pset::AbstractProblemParSetter)
axis_paropt_flat1(pset::AbstractProblemParSetter)
Report the Axis of a CompoenentVector of parameters. The second version has a scalarized entry for state for each subvector of state. The third version provides an axis corresponding to flatten1(paropt)
.
MTKHelpers.classes_paropt
— Methodfunction classes_paropt(pset::AbstractProblemParSetter)
Get the classes (as NTuple{Symbol}) which the AbstractProblemParSetter supports and requires in paropt.
MTKHelpers.count_paropt
— Methodcount_paropt(::AbstractProblemParSetter)
Report length of the optimized parameters vector. This generally is different from the length of keys, because each key can describe a array.
MTKHelpers.keys_paropt
— Methodkeys_paropt(::AbstractProblemParSetter)
Report the keys of paropt below the classification level.
MTKHelpers.symbols_paropt
— Methodsymbols_paropt(pset::AbstractProblemParSetter)
Report the names, i.e. symbols of optimized parameters respectively, i.e. the concatenation of components. Similar to ComponentArrays.label
, but inferred from Axis object. Returns a Vector of length count_paropt
Labeling parameter vectors
MTKHelpers.label_paropt
— Methodlabel_paropt(pset::AbstractProblemParSetter, popt::AbstractVector)
label_paropt_flat1(pset::AbstractProblemParSetter, popt::AbstractVector)
Produce a labeled version, i.e. a ComponentVector of optimized parameters. The second version omits the highest level of labels, e.g. state and par in ODEProblemParSetter
.
MTKHelpers.name_paropt
— Methodname_paropt(pset, popt::AbstractVector)
name_paropt(pset, prob::AbstractSciMLProblem)
Produce a NamedVector
of given state optimized parameters vector. Similar to label_paropt
, but may print nicer. The second form calls get_paropt
on the Problem.