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: SplineInnerProblem, inner_solver: SplineInnerSolver | None = 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.

__call__(x_dct: Dict, sensi_orders: Tuple[int, ...], mode: str, amici_model: Model | ModelPtr, amici_solver: Solver | SolverPtr, edatas: List[ExpData], n_threads: int, x_ids: Sequence[str], parameter_mapping: ParameterMapping, fim_for_hess: bool, rdatas: List[ReturnData] | None = None)[source]

Perform the actual AMICI call.

Parameters:
  • x_dct – Parameters for which to compute function value and derivatives.

  • sensi_orders – Tuple of requested sensitivity orders.

  • mode – Call mode (function value or residual based).

  • amici_model – The AMICI model.

  • amici_solver – The AMICI solver.

  • edatas – The experimental data.

  • n_threads – Number of threads for AMICI call.

  • x_ids – Ids of optimization parameters.

  • parameter_mapping – Mapping of optimization to simulation parameters.

  • fim_for_hess – Whether to use the FIM (if available) instead of the Hessian (if requested).

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

A dict containing the calculation results: FVAL, GRAD, RDATAS and X_INNER_OPT.

Return type:

inner_result

__init__(inner_problem: SplineInnerProblem, inner_solver: SplineInnerSolver | None = None)[source]

Initialize the calculator from the given problem.

Parameters:
  • inner_problem – The optimal scaling inner problem.

  • inner_solver – A solver to solve inner_problem. Defaults to SplineInnerSolver.

initialize()[source]

Initialize.

class pypesto.hierarchical.spline_approximation.SplineInnerParameter(*args, observable_id: str | None = None, group: int | None = None, index: int | None = None, estimate: bool = 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.

__init__(*args, observable_id: str | None = None, group: int | None = None, index: int | None = None, estimate: bool = False, **kwargs)[source]

Construct.

Parameters:

attributes. (See class) –

class pypesto.hierarchical.spline_approximation.SplineInnerProblem(xs: List[SplineInnerParameter], data: List[ndarray], spline_ratio: float = 0.5)[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: List[SplineInnerParameter], data: List[ndarray], spline_ratio: float = 0.5)[source]

Construct.

static from_petab_amici(petab_problem: Problem, amici_model: Model, edatas: List[ExpData], spline_ratio: float | None = None) SplineInnerProblem[source]

Construct the inner problem from the petab_problem.

get_fixed_xs_for_group(group: int) List[SplineInnerParameter][source]

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

get_free_xs_for_group(group: int) List[SplineInnerParameter][source]

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

get_groups_for_xs(inner_parameter_type: str) List[int][source]

Get unique list of SplineParameter.group values.

get_inner_parameter_dictionary() Dict[source]

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

get_measurements_for_group(gr) ndarray[source]

Get measurements for a group.

get_xs_for_group(group: int) List[SplineInnerParameter][source]

Get SplineParameters that belong to the given group.

class pypesto.hierarchical.spline_approximation.SplineInnerSolver(options: Dict | None = 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.

__init__(options: Dict | None = None)[source]
calculate_gradients(problem: SplineInnerProblem, x_inner_opt: List[Dict], sim: List[ndarray], sigma: List[ndarray], sy: List[ndarray], parameter_mapping: ParameterMapping, par_opt_ids: List, par_sim_ids: List, snllh: Dict)[source]

Calculate gradients of the inner objective function.

Calculates gradients of the objective function with respect to outer (dynamical) parameters.

Parameters:
  • problem – Optimal scaling inner problem.

  • x_inner_opt – List of optimization results of the inner subproblem.

  • sim – Model simulations.

  • sigma – Model noise parameters.

  • sy – Model sensitivities.

  • parameter_mapping – Mapping of optimization to simulation parameters.

  • par_opt_ids – Ids of outer otimization parameters.

  • par_sim_ids – Ids of outer simulation parameters, includes fixed parameters.

  • snllh – Empty dictionary with optimization parameters as keys.

Return type:

Filled in snllh dictionary with objective function gradients.

static calculate_obj_function(x_inner_opt: list)[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 of optimization results

Return type:

Inner objective function value.

static get_default_options() Dict[source]

Return default options for solving the inner problem.

solve(problem: SplineInnerProblem, sim: List[ndarray], sigma: List[ndarray]) list[source]

Get results for every group (inner optimization problem).

Parameters:
  • problem – InnerProblem from pyPESTO hierarchical.

  • sim – Simulations from AMICI.

  • sigma – List of sigmas from AMICI.

Return type:

List of optimization results of the inner subproblem.

validate_options()[source]

Validate the current options dictionary.