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).

  • amici_model (Union[Model, ModelPtr]) – The AMICI model.

  • amici_solver (Union[Solver, SolverPtr]) – The AMICI solver.

  • edatas (list[ExpData]) – The experimental data.

  • n_threads (int) – Number of threads for AMICI call.

  • x_ids (Sequence[str]) – Ids of optimization parameters.

  • 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 the pypesto.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:
initialize()[source]

Initialize.

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.

__init__(options=None)[source]
Parameters:

options (dict) –

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.

  • sim (list[ndarray]) – Model simulations.

  • sigma – Model noise parameters.

  • sy (list[ndarray]) – Model sensitivities.

  • 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 as par_opt_ids to store the gradients in. Will be modified in-place.

  • amici_sigma (list[ndarray]) –

  • amici_ssigma (list[ndarray]) –

  • 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:

dict

solve(problem, sim, amici_sigma)[source]

Get results for every group (inner optimization problem).

Parameters:
Return type:

list

Returns:

List of optimization results of the inner subproblem.

validate_options()[source]

Validate the current options dictionary.

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 ExpDatas 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.

__init__(spline_ratio=0.5, **kwargs)[source]

Construct.

Parameters:

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:

SemiquantProblem

Parameters:
  • petab_problem (Problem) –

  • amici_model (Model) –

  • edatas (list[ExpData]) –

  • spline_ratio (float) –

get_fixed_xs_for_group(group)[source]

Get SplineParameters that are fixed and belong to the given group.

Return type:

list[SplineInnerParameter]

Parameters:

group (int) –

get_free_xs_for_group(group)[source]

Get SplineParameters that are free and belong to the given group.

Return type:

list[SplineInnerParameter]

Parameters:

group (int) –

get_groups_for_xs(inner_parameter_type)[source]

Get unique list of SplineParameter.group values.

Return type:

list[int]

Parameters:

inner_parameter_type (str) –

get_inner_noise_parameters()[source]

Get a list with all noise parameter values.

Return type:

list[float]

get_inner_parameter_dictionary()[source]

Get a dictionary with all inner parameter ids and their values.

Return type:

dict

get_interpretable_x_ids()[source]

Get IDs of interpretable inner parameters.

The interpretable inner parameters of the semiquantitative problem are the noise parameters.

Return type:

list[str]

get_measurements_for_group(gr)[source]

Get measurements for a group.

Return type:

ndarray

get_noise_dummy_values(scaled)[source]

Get dummy values for noise parameters of the semiquantitative observable.

Return type:

dict[str, float]

Parameters:

scaled (bool) –

get_noise_parameters_for_group(group)[source]

Get the SplineParameterthat is a noise parameters and belongs to the given group.

Return type:

SplineInnerParameter

Parameters:

group (int) –

get_spline_knots()[source]

Get spline knots of all semiquantitative observables.

Return type:

list[list[ndarray[float], ndarray[float]]]

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.

get_xs_for_group(group)[source]

Get SplineParameters that belong to the given group.

Return type:

list[SplineInnerParameter]

Parameters:

group (int) –

initialize()[source]

Initialize the subproblem.

Return type:

None

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.

__init__(*args, observable_id=None, group=None, index=None, estimate=False, **kwargs)[source]

Construct.

Parameters:
  • attributes. (See class) –

  • observable_id (str) –

  • group (int) –

  • index (int) –

  • estimate (bool) –

initialize()[source]

Initialize.