pypesto.hierarchical.spline_approximation
Spline approximation
Contains the implementation of a spline approximation approach, applied for integration of nonlinear-monotone data in ODE modeling, where the data is assumed to have an unknown monotone relationship with the model output. This relationship is approximated by a piecewise linear (spline) function, which is numerically optimized to fit the data. This constitutes the inner subproblem of the hierarchical optimization problem.
- class pypesto.hierarchical.spline_approximation.SplineAmiciCalculator(inner_problem, inner_solver=None)[source]
Bases:
AmiciCalculator
A calculator is passed as calculator to the pypesto.AmiciObjective.
The object is called by
pypesto.AmiciObjective.call_unprocessed()
to calculate the current objective function values and gradient.- Parameters:
inner_problem (SplineInnerProblem) –
inner_solver (SplineInnerSolver) –
- __call__(x_dct, sensi_orders, mode, amici_model, amici_solver, edatas, n_threads, x_ids, parameter_mapping, fim_for_hess, rdatas=None)[source]
Perform the actual AMICI call.
- Parameters:
x_dct (
Dict
) – Parameters for which to compute function value and derivatives.sensi_orders (
Tuple
[int
,...
]) – Tuple of requested sensitivity orders.mode (
str
) – Call mode (function value or residual based).edatas (
List
[ExpData
]) – The experimental data.n_threads (
int
) – Number of threads for AMICI call.parameter_mapping (
ParameterMapping
) – Mapping of optimization to simulation parameters.fim_for_hess (
bool
) – Whether to use the FIM (if available) instead of the Hessian (if requested).rdatas (
Optional
[List
[ReturnData
]]) – AMICI simulation return data. In case the calculator is part of thepypesto.objective.amici.InnerCalculatorCollector
, it will already simulate the model and pass the results here.
- Returns:
A dict containing the calculation results: FVAL, GRAD, RDATAS and X_INNER_OPT.
- Return type:
inner_result
- __init__(inner_problem, inner_solver=None)[source]
Initialize the calculator from the given problem.
- Parameters:
inner_problem (
SplineInnerProblem
) – The optimal scaling inner problem.inner_solver (
Optional
[SplineInnerSolver
]) – A solver to solveinner_problem
. Defaults toSplineInnerSolver
.
- class pypesto.hierarchical.spline_approximation.SplineInnerParameter(*args, observable_id=None, group=None, index=None, estimate=False, **kwargs)[source]
Bases:
InnerParameter
A spline (inner) parameter of the spline hierarchical optimization problem.
- observable_id
The id of the observable the spline is modeling.
- group
Group index. Corresponds to observable index + 1.
- index
Parameter index inside the group. Ranges from 1 to n_spline_parameters of its group.
- value
Current value of the inner parameter.
- estimate
Whether to estimate inner parameter in inner subproblem.
- class pypesto.hierarchical.spline_approximation.SplineInnerProblem(xs, data, spline_ratio=0.5)[source]
Bases:
InnerProblem
Inner optimization problem for spline approximation.
- Parameters:
xs (List[SplineInnerParameter]) –
spline_ratio (float) –
- xs
Mapping of (inner) parameter ID to
InnerParameters
.
- data
Measurement data. One matrix (num_timepoints x num_observables) per simulation condition. Missing observations as NaN.
- groups
A dictionary of the groups of the subproblem.
- spline_ratio
The ratio of the number of spline inner parameters and number of measurements for each group.
- __init__(xs, data, spline_ratio=0.5)[source]
Construct.
- Parameters:
xs (List[SplineInnerParameter]) –
spline_ratio (float) –
- static from_petab_amici(petab_problem, amici_model, edatas, spline_ratio=None)[source]
Construct the inner problem from the petab_problem.
- Return type:
- Parameters:
- get_fixed_xs_for_group(group)[source]
Get
SplineParameter
s that are fixed and belong to the given group.- Return type:
- Parameters:
group (int) –
- get_free_xs_for_group(group)[source]
Get
SplineParameter
s that are free and belong to the given group.- Return type:
- Parameters:
group (int) –
- get_inner_noise_parameter_dictionary()[source]
Get a dictionary with all noise inner parameter ids and their values.
- Return type:
- get_inner_parameter_dictionary()[source]
Get a dictionary with all inner parameter ids and their values.
- Return type:
- get_noise_dummy_values(scaled)[source]
Get dummy values for noise parameters of the nonlinear-monotone observable.
- get_noise_parameters_for_group(group)[source]
Get the
SplineParameter
that is a noise parameters and belongs to the given group.- Return type:
- Parameters:
group (int) –
- class pypesto.hierarchical.spline_approximation.SplineInnerSolver(options=None)[source]
Bases:
InnerSolver
Solver of the inner subproblem of spline approximation for nonlinear-monotone data.
Options
- min_diff_factor:
Determines the minimum difference between two consecutive spline as
min_diff_factor * (measurement_range) / n_spline_pars
. Default is 1/2.
- calculate_gradients(problem, x_inner_opt, sim, amici_sigma, sy, amici_ssigma, parameter_mapping, par_opt_ids, par_sim_ids, snllh)[source]
Calculate gradients of the inner objective function.
Calculates gradients of the objective function with respect to outer (dynamical) parameters.
- Parameters:
problem (
SplineInnerProblem
) – Optimal scaling inner problem.x_inner_opt (
List
[Dict
]) – List of optimization results of the inner subproblem.sigma – Model noise parameters.
parameter_mapping (
ParameterMapping
) – Mapping of optimization to simulation parameters.par_opt_ids (
List
) – Ids of outer otimization parameters.par_sim_ids (
List
) – Ids of outer simulation parameters, includes fixed parameters.snllh (
Dict
) – Empty dictionary with optimization parameters as keys.
- Return type:
Filled in snllh dictionary with objective function gradients.
- static calculate_obj_function(x_inner_opt)[source]
Calculate the inner objective function value.
Calculates the inner objective function value from a list of inner optimization results returned from _optimize_spline.
- Parameters:
x_inner_opt (
list
) – List of optimization results- Return type:
Inner objective function value.
- static get_default_options()[source]
Return default options for solving the inner problem.
- Return type:
- solve(problem, sim, amici_sigma)[source]
Get results for every group (inner optimization problem).
- Parameters:
problem (
SplineInnerProblem
) – InnerProblem from pyPESTO hierarchical.
- Return type:
List of optimization results of the inner subproblem.
- Parameters:
options (Dict) –