pypesto.hierarchical.semiquantitative
Semi-quantitative data integration
Contains the implementation of a spline approximation approach, applied for integration of semi-quantitative 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.
An example of parameter estimation with semi-quantitative data can be found in pypesto/doc/examples/semiquantitative_data.ipynb.
- class pypesto.hierarchical.semiquantitative.SemiquantCalculator[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.- __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 (
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:
inner_result – A dict containing the calculation results: FVAL, GRAD, RDATAS, INNER_PARAMETERS, and SPLINE_KNOTS.
- __init__(inner_problem, inner_solver=None)[source]
Initialize the calculator from the given problem.
- Parameters:
inner_problem (
SemiquantProblem
) – The optimal scaling inner problem.inner_solver (
SemiquantInnerSolver
) – A solver to solveinner_problem
. Defaults toSplineInnerSolver
.
- class pypesto.hierarchical.semiquantitative.SemiquantInnerSolver[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, par_edatas_indices, snllh)[source]
Calculate gradients of the inner objective function.
Calculates gradients of the objective function with respect to outer (dynamical) parameters.
- Parameters:
problem (
SemiquantProblem
) – 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 (
ndarray
) – A zero-initialized vector of the same length aspar_opt_ids
to store the gradients in. Will be modified in-place.par_edatas_indices (list) –
- Returns:
The gradients with respect to the outer parameters.
- 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- Returns:
Inner objective function value.
- static get_default_options()[source]
Return default options for solving the inner problem.
- Return type:
- class pypesto.hierarchical.semiquantitative.SemiquantProblem[source]
Bases:
AmiciInnerProblem
Inner optimization problem for semi-quantitative data.
The inner problem for semi-quantitative data consists of spline parameters and noise parameters for semi-quantitative observables. The unknown nonlinear measurement mapping is estimated using a piece-wise linear spline.
- 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.
- edatas
AMICI
ExpData
s for each simulation condition.
- 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.
- 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_parameter_dictionary()[source]
Get a dictionary with all inner parameter ids and their values.
- Return type:
- get_interpretable_x_ids()[source]
Get IDs of interpretable inner parameters.
The interpretable inner parameters of the semiquantitative problem are the noise parameters.
- get_noise_dummy_values(scaled)[source]
Get dummy values for noise parameters of the semiquantitative 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) –
- get_spline_knots()[source]
Get spline knots of all semiquantitative observables.
- Return type:
- Returns:
list[list[np.ndarray[float], np.ndarray[float]]] – A list of lists with two arrays. Each list in the first level corresponds to a semiquantitative observable. Each of these lists contains two arrays: the first array contains the spline bases, the second array contains the spline knot values. The ordering of the observable lists is the same as in pypesto.problem.hierarchical.semiquant_observable_ids.
- class pypesto.hierarchical.semiquantitative.SplineInnerParameter[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.