Providing inversion information

CrossInverts.AbstractCrossInversionCaseType
AbstractCrossInversionCase

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.
source
CrossInverts.get_case_inverted_systemFunction
get_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.

source
CrossInverts.get_case_mixed_keysFunction
get_case_mixed_keys(::AbstractCrossInversionCase; scenario)

Provide NamedTuple (;fixed, ranadd, ranmul, indiv) of tuples of parameter names (Symbol) that are optimized in the inversion scenario.

source
CrossInverts.get_case_priors_dictFunction
get_case_priors_dict(::AbstractCrossInversionCase, indiv_id; scenario)

Provide a dictionary (par -> Distribution) for prior parameters and unknowns.

source
CrossInverts.get_case_priors_random_dictFunction
get_case_priors_random_dict(::AbstractCrossInversionCase; scenario)

Provide a dictionary (par -> Distribution) for hyperpriors of the spread of the ranmul and ranadd effects.

source
CrossInverts.get_case_indivdataFunction
get_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. Valueobs_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.

source
CrossInverts.get_case_problemupdaterFunction
get_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.

source

Setup tools

CrossInverts.setup_inversionFunction
setup_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 effects NamedTuple(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 component
  • priors_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 object
  • effect_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 individuals
  • u0 and p: ComponentVectors of initial states and parameters
  • paropt: optimized parameters extracted from indiviudals state and parameters
  • tools: tools initialized for each site
    • priors_indiv: priors, which may differ between individuals
    • problem: the ODEProblem set up with initial state and parameters
    • indivdata: as returned by getcaseindivdata
source

Simulating

CrossInverts.gen_sim_sols_probsFunction
gen_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.

source
CrossInverts.gen_model_crossFunction
function 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.

source