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[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 (Optional[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 and X_INNER_OPT.

__init__(inner_problem, inner_solver=None)[source]

Initialize the calculator from the given problem.

Parameters:
get_inner_parameter_ids()[source]

Get the ids of the inner parameters.

Return type:

List[str]

initialize()[source]

Initialize.

class pypesto.hierarchical.spline_approximation.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 | None) –

  • group (int | None) –

  • index (int | None) –

  • estimate (bool) –

initialize()[source]

Initialize.

class pypesto.hierarchical.spline_approximation.SplineInnerProblem[source]

Bases: InnerProblem

Inner optimization problem for spline approximation.

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:
static from_petab_amici(petab_problem, amici_model, edatas, spline_ratio=None)[source]

Construct the inner problem from the petab_problem.

Return type:

SplineInnerProblem

Parameters:
  • petab_problem (Problem) –

  • amici_model (Model) –

  • edatas (List[ExpData]) –

  • spline_ratio (float | None) –

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_parameter_dictionary()[source]

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

Return type:

Dict

get_inner_parameter_dictionary()[source]

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

Return type:

Dict

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 nonlinear-monotone 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_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.spline_approximation.SplineInnerSolver[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 | None) –

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.

  • 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 (Dict) – Empty dictionary with optimization parameters as keys.

  • amici_sigma (List[ndarray]) –

  • amici_ssigma (List[ndarray]) –

Returns:

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

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.