pypesto.hierarchical.ordinal
Ordinal and censored data integration
Contains the implementation of the optimal scaling approach, applied for integration of ordinal and censored data in ODE modeling. Each ordinal datapoint is defined as being part of a category, where the mutual ordering of the categories of the same observable is known. The category interval bounds are numerically optimized and quantitative surrogate measurements are calculated to represent the ordinal measurements. This constitutes the inner subproblem of the hierarchical optimization problem. For censored data, as the category interval bounds are known, the surrogate measurements are directly calculated.
An example of parameter estimation with ordinal data can be found in pypesto/doc/examples/ordinal_data.ipynb. An example of parameter estimation with censored data can be found in pypesto/doc/examples/censored_data.ipynb.
Details on the optimal scaling approach can be found in Shepard, 1962 (https://doi.org/10.1007/BF02289621). Details on the application of the gradient-based optimal scaling approach to mechanistic modeling with ordinal data can be found in Schmiester et al. 2020 (https://doi.org/10.1007/s00285-020-01522-w) and Schmiester et al. 2021 (https://doi.org/10.1093/bioinformatics/btab512).
- class pypesto.hierarchical.ordinal.OrdinalCalculator[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.
- __init__(inner_problem, inner_solver=None)[source]
Initialize the calculator from the given problem.
- Parameters:
inner_problem (
OrdinalProblem
) – The optimal scaling inner problem.inner_solver (
OrdinalInnerSolver
) – A solver to solveinner_problem
. Defaults toOptimalScalingInnerSolver
.
- class pypesto.hierarchical.ordinal.OrdinalInnerSolver[source]
Bases:
InnerSolver
Solve the inner subproblem of the optimal scaling approach for ordinal data.
Options
- method:
The method to use for the inner optimization problem. Can be ‘standard’ or ‘reduced’. The latter is more efficient.
- reparameterized:
Whether to use reparameterized optimization.
- intervalConstraints:
The type of interval constraints to use. Can be ‘max’ or ‘maxmin’.
- minGap:
The minimum gap between two consecutive categories.
- calculate_gradients(problem, x_inner_opt, sim, sy, sigma, 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 (
OrdinalProblem
) – Optimal scaling inner problem.x_inner_opt (
list
[dict
]) – List of optimization results of the inner subproblem.ssigma (
list
[ndarray
]) – Model sensitivity of 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.par_edata_indices – Indices of parameters from amici_model.getParameterIds() that are needed for sensitivity calculation. Comes from edata.plist for each condition.
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 OptimalScalingInnerSolver.solve.
- Parameters:
x_inner_opt (
list
) – List of optimization results of the inner subproblem.- Returns:
Inner objective function value.
- static get_default_options()[source]
Return default options for solving the inner problem.
- Return type:
- class pypesto.hierarchical.ordinal.OrdinalParameter[source]
Bases:
InnerParameter
Inner parameter of the optimal scaling inner optimization problem for ordinal data.
- dummy_value
Value to be used when the optimal parameter is not yet known (in particular to simulate unscaled observables).
- inner_parameter_id
The inner parameter ID.
- inner_parameter_type
The inner parameter type.
- ixs
A mask (boolean matrix) that indicates the measurements that this parameter is used in.
- lb
The lower bound, for optimization.
- scale
Scale on which to estimate this parameter.
- ub
The upper bound, for optimization.
- observable_id
The id of the observable whose measurements are in the category with this inner parameter.
- category
Category index.
- group
Group index.
- value
Current value of the inner parameter.
- estimate
Whether to estimate inner parameter in inner subproblem.
- censoring_type
The censoring type of the measurements in the category with this inner parameter. In case of ordinal measurements, this is None.
- class pypesto.hierarchical.ordinal.OrdinalProblem[source]
Bases:
AmiciInnerProblem
Inner optimization problem for ordinal or censored data.
The ordinal inner problem contains the following parameters: surrogate data, lower bounds, and upper bounds. All parameters are optimized to minimize the distance between the surrogate data and the simulated data while satisfying the ordering constraints of the problem. Depending on the method, the problem is re-formulated to reduce the number of parameters to estimate.
- xs
Mapping of (inner) parameter ID to
InnerParameters
.
- data
Measurement data. One matrix (
num_timepoints
xnum_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.
- method
A string representing the method of the Optimal Scaling approach, either
reduced
orstandard
.
- static from_petab_amici(petab_problem, amici_model, edatas, method=None)[source]
Construct the inner problem from the petab_problem.
- Return type:
- Parameters:
- get_cat_lb_parameters_for_group(group)[source]
Get
OptimalScalingParameter
s that are category lower boundaries and belong to the given group.- Return type:
- Parameters:
group (int) –
- get_cat_ub_parameters_for_group(group)[source]
Get
OptimalScalingParameter
s that are category upper boundaries and belong to the given group.- Return type:
- Parameters:
group (int) –
- get_censored_group_quantitative_ixs(xs)[source]
Return a list of boolean masks indicating which data points are quantitative.
For a given group with censored data, return a list of boolean masks indicating which data points are not censored, and therefore quantitative.
- Parameters:
xs (
list
[OrdinalParameter
]) – List ofOptimalScalingParameter
s of a group with censored data.- Return type:
- Returns:
quantitative_ixs – List of boolean masks indicating which data points are quantitative.
- get_d(group, xs, y_sim_all, eps)[source]
Return vector of minimal gaps and ranges.
- Return type:
- Parameters:
xs (list[OrdinalParameter]) –
y_sim_all (ndarray) –
eps (float) –
- get_dd_dtheta(group, xs, y_sim_all, sy_all)[source]
Return the derivative of vector of minimal gaps and ranges with respect to an outer parameter.
- get_fixed_xs_for_group(group)[source]
Get
OptimalScalingParameter
s that are fixed and belong to the given group.- Return type:
- Parameters:
group (int) –
- get_free_xs_for_group(group)[source]
Get
OptimalScalingParameter
s that are free and belong to the given group.- Return type:
- Parameters:
group (int) –
- get_groups_for_xs(inner_parameter_type)[source]
Get unique list of
OptimalScalingParameter.group
values.
- get_inner_parameter_dictionary()[source]
Return a dictionary with inner parameter ids and their values.
- Return type:
- get_interpretable_x_ids()[source]
Get IDs of interpretable inner parameters.
There are no interpretable inner parameters for the ordinal problem.
- get_wdot(group, y_sim_all, sy_all)[source]
Return the derivative of the weight matrix of a group with respect to an outer parameter.
- get_xs_for_group(group)[source]
Get
OptimalScalingParameter
s that belong to the given group.- Return type:
- Parameters:
group (int) –
- initialize_c(group)[source]
Initialize the constraints matrix for the group.
The structure of the constraints matrix is the following: Each row C_i of the matrix C represents one optimization constraint as C_i * xi + d(theta, sim) <= 0, where xi is the vector of inner paramters (surrogate data, lower bounds, upper bounds)^T, and d is the vector of minimal category interval ranges and gaps.
First self.groups[group][NUM_DATAPOINTS] rows constrain the surrogate data to stay larger than lower category bounds. Then another self.groups[group][NUM_DATAPOINTS] rows constrain the surrogate data to stay smaller than upper category bounds. Then self.groups[group][NUM_CATEGORIES] rows constrain the ordering of the categories. And lastly, the remaining self.groups[group][NUM_CATEGORIES] constrain the lower bound to be smaller than the upper bound for each category.