Providing inversion information
CrossInverts.AbstractCrossInversionCase
— TypeAbstractCrossInversionCase
Interface for providing all relevant information for a cross-individual mixed effects bayesian inversion.
Concrete types should implement
get_case_inverted_system(::AbstractCrossInversionCase; scenario)
get_case_mixed_keys(::AbstractCrossInversionCase; scenario)
get_case_indiv_ids(::AbstractCrossInversionCase; scenario)
get_case_priors_dict(::AbstractCrossInversionCase, indiv_id; scenario)
Priors for optimized model effects, which may differ by individual.get_case_priors_random_dict(::AbstractCrossInversionCase; scenario)
Priors for meta-parameters for ranadd and ranmul effects.get_case_obs_uncertainty_dist_type(::AbstractCrossInversionCase; scenario)
Type of distribution of observation-uncertainty per stream.get_case_indivdata(::AbstractCrossInversionCase, indiv_id; scenario)
The times, observations, and uncertainty parameters per indiv_id and stream.
optionally:
get_case_u0p(::AbstractCrossInversionCase; scenario)
get_case_problemupdater(::AbstractCrossInversionCase; system, scenario)
A ProblemUpdater for ensuring consistent parameters after setting optimized parameters.
CrossInverts.get_case_inverted_system
— Functionget_case_inverted_system(::AbstractCrossInversionCase; scenario)
Provide a NamedTuple
(;system::AbstractSystem, u0_default::ComponentVector, p_default::ComponentVector)
of the inverted system and default initial values and parameters for given inversion scenario.
CrossInverts.get_case_mixed_keys
— Functionget_case_mixed_keys(::AbstractCrossInversionCase; scenario)
Provide NamedTuple (;fixed, ranadd, ranmul, indiv)
of tuples of parameter names (Symbol) that are optimized in the inversion scenario.
CrossInverts.get_case_indiv_ids
— Functionget_case_indiv_ids(::AbstractCrossInversionCase; scenario)
Provide Tuple of Symbols identifying the individuals.
CrossInverts.get_case_priors_dict
— Functionget_case_priors_dict(::AbstractCrossInversionCase, indiv_id; scenario)
Provide a dictionary (par -> Distribution) for prior parameters and unknowns.
CrossInverts.get_case_priors_random_dict
— Functionget_case_priors_random_dict(::AbstractCrossInversionCase; scenario)
Provide a dictionary (par -> Distribution) for hyperpriors of the spread of the ranmul and ranadd effects.
CrossInverts.get_case_obs_uncertainty_dist_type
— Functionget_case_obs_uncertainty_dist_type(::AbstractCrossInversionCase; scenario)
Provide the type of distribution of observation uncertainty for given stream, to be used with fit_mean_Σ
.
CrossInverts.get_case_indivdata
— Functionget_case_indivdata(::AbstractCrossInversionCase, indiv_id; scenario)
Provide Tuple (indiv_id -> (stream_info)
for each individ. Where StreamInfo is a Tuple `(streamsymbol -> (;t, obs, obstrue)). Such that solution can be indexed by sol[streamsymbol](t) to provide observations. Value
obs_true` is optional. They are synthetic data without noise generated from the system, which are not used in inversion, but used for comparison.
The ValueType dispatches to different implementations. There is am implementation for Val(:CrossInverts_samplesystem1)
independent of scenario.
CrossInverts.get_case_problemupdater
— Functionget_case_problemupdater(::AbstractCrossInversionCase; scenario)
Return a specific ProblemUpdater
for given Inversioncase and scennario. It is applied after parameters to optimized have been set. The typical case is optimizing a parameter, but adjusting other non-optimized parameters to be consistent with the optimized one, e.g. always use the same value for another parameter.
The default is a NullProblemUpdater
, which does not modify parameters.
Setup tools
CrossInverts.setup_inversion
— Functionsetup_inversion(inv_case::AbstractCrossInversionCase; scenario = NTuple{0, Symbol}())
Calls all the functions for specific AbstractCrossInversionCase
to setup the inversion.
Returns a NamedTuple
with entries: (; system, pop_info, indiv_info)
pop_info
is a NamedTuple with entriees
mixed_keys
: The optimized parameters and their distribution across individual as returned by [get_case_mixed_keys]
(@ref)indiv_ids
: A tuple of ids (Symbols) of the individuals taking part in the inversion, as returned by [get_case_indiv_ids]
(@ref)mixed
: mixed effectsNamedTuple(fixed, ranadd, ranmul, indiv, indiv_ranadd, indiv_ranmul)
from individual's states and parameters in the format expected by forward sim.psets
:NTuple{ODEProblemParSetter}
for each mixed componentpriors_pop
:ComponentVector
of priors on population level(fixed, ranadd, ranmul, ranadd_σ, ranmul_σ)
problemupdaterproblemupdater
: used to update problems after setting parameters to be optimized.sample0
: ComponentVector of an initial sample This can be used to name (attach_axis) a sample from MCMCChains objecteffect_pos
: ComponentVector to map keys to positions (1:n_par) in sample
indiv_info
: is a DataFrame with rows for each individual with columns
indiv_id
: Symbols identifying individualsu0
andp
: ComponentVectors of initial states and parametersparopt
: optimized parameters extracted from indiviudals state and parameterstools
: tools initialized for each sitepriors_indiv
: priors, which may differ between individualsproblem
: the ODEProblem set up with initial state and parametersindivdata
: as returned by getcaseindivdata
CrossInverts.df_from_paramsModeUpperRows
— Functiondf_from_paramsModeUpperRows(paramsModeUpperRows)
Convert Tuple-Rows of (:par, :dType, :mode, :upper)
to DataFrame
. And fit distribution and report it in column :dist
.
Simulating
CrossInverts.gen_sim_sols_probs
— Functiongen_sim_sols_probs(; tools, psets, problemupdater,
solver = AutoTsit5(Rodas5()), kwargs_gen...)
Generates a function sim_sols_probs(fixed, ranadd, ranmul, indiv, indiv_ranmul, indiv_ranadd)
that updates and simulate the system (given with tools to gen_sim_sols_probs
) by
- for each individual i
- update fixed parameters: fixed
- update ranadd parameters: ranadd .+ indiv_ranadd[:,i]
- update ranmul parameters: ranmul .* indiv_ranmul[:,i]
- update indiv_id parameters: indiv[:,i]
- simulate the problem
- return a vector(nindiv) of (;sol, problemopt)
If non-optimized p
or u0
differ between individuals, they must already be set in tools[i_indiv].problem
.
CrossInverts.gen_model_cross
— Functionfunction gen_model_cross(;
inv_case::AbstractCrossInversionCase, tools, priors_pop, sim_sols_probs,
scenario, psets, solver)
Generate a Turing model using objects generated by setup_inversion
components: indiv_info.tools
, pop_info.priors_pop
, and pop_info.psets
) and forward simulation function generated by gen_sim_sols_probs
.