Profile

class pypesto.profile.ProfileOptions(default_step_size: float = 0.01, min_step_size: float = 0.001, max_step_size: float = 1.0, step_size_factor: float = 1.25, delta_ratio_max: float = 0.1, ratio_min: float = 0.145, reg_points: int = 10, reg_order: int = 4, magic_factor_obj_value: float = 0.5)[source]

Bases: dict

Options for optimization based profiling.

Parameters
  • default_step_size – Default step size of the profiling routine along the profile path (adaptive step lengths algorithms will only use this as a first guess and then refine the update).

  • min_step_size – Lower bound for the step size in adaptive methods.

  • max_step_size – Upper bound for the step size in adaptive methods.

  • step_size_factor – Adaptive methods recompute the likelihood at the predicted point and try to find a good step length by a sort of line search algorithm. This factor controls step handling in this line search.

  • delta_ratio_max – Maximum allowed drop of the posterior ratio between two profile steps.

  • ratio_min – Lower bound for likelihood ratio of the profile, based on inverse chi2-distribution. The default 0.145 is slightly lower than the 95% quantile 0.1465 of a chi2 distribution with one degree of freedom.

  • reg_points – Number of profile points used for regression in regression based adaptive profile points proposal.

  • reg_order – Maximum degree of regression polynomial used in regression based adaptive profile points proposal.

  • magic_factor_obj_value – There is this magic factor in the old profiling code which slows down profiling at small ratios (must be >= 0 and < 1).

__init__(default_step_size: float = 0.01, min_step_size: float = 0.001, max_step_size: float = 1.0, step_size_factor: float = 1.25, delta_ratio_max: float = 0.1, ratio_min: float = 0.145, reg_points: int = 10, reg_order: int = 4, magic_factor_obj_value: float = 0.5)[source]

Initialize self. See help(type(self)) for accurate signature.

static create_instance(maybe_options: Union[pypesto.profile.options.ProfileOptions, Dict])pypesto.profile.options.ProfileOptions[source]

Returns a valid options object.

Parameters

maybe_options (ProfileOptions or dict) –

class pypesto.profile.ProfilerResult(x_path: numpy.ndarray, fval_path: numpy.ndarray, ratio_path: numpy.ndarray, gradnorm_path: Optional[numpy.ndarray] = None, exitflag_path: Optional[numpy.ndarray] = None, time_path: Optional[numpy.ndarray] = None, time_total: float = 0.0, n_fval: int = 0, n_grad: int = 0, n_hess: int = 0, message: Optional[str] = None)[source]

Bases: dict

The result of a profiler run. The standardized return return value from pypesto.profile, which can either be initialized from an OptimizerResult or from an existing ProfilerResult (in order to extend the computation).

Can be used like a dict.

x_path

The path of the best found parameters along the profile (Dimension: n_par x n_profile_points)

fval_path

The function values, fun(x), along the profile.

ratio_path

The ratio of the posterior function along the profile.

gradnorm_path

The gradient norm along the profile.

exitflag_path

The exitflags of the optimizer along the profile.

time_path

The computation time of the optimizer runs along the profile.

time_total

The total computation time for the profile.

n_fval

Number of function evaluations.

n_grad

Number of gradient evaluations.

n_hess

Number of Hessian evaluations.

message

Textual comment on the profile result.

Notes

Any field not supported by the profiler or the profiling optimizer is filled with None. Some fields are filled by pypesto itself.

__init__(x_path: numpy.ndarray, fval_path: numpy.ndarray, ratio_path: numpy.ndarray, gradnorm_path: Optional[numpy.ndarray] = None, exitflag_path: Optional[numpy.ndarray] = None, time_path: Optional[numpy.ndarray] = None, time_total: float = 0.0, n_fval: int = 0, n_grad: int = 0, n_hess: int = 0, message: Optional[str] = None)[source]

Initialize self. See help(type(self)) for accurate signature.

append_profile_point(x: numpy.ndarray, fval: float, ratio: float, gradnorm: float = nan, time: float = nan, exitflag: float = nan, n_fval: int = 0, n_grad: int = 0, n_hess: int = 0)None[source]

This function appends a new point to the profile path.

Parameters
  • x – The parameter values.

  • fval – The function value at x.

  • ratio – The ratio of the function value at x by the optimal function value.

  • gradnorm – The gradient norm at x.

  • time – The computation time to find x.

  • exitflag – The exitflag of the optimizer (useful if an optimization was performed to find x).

  • n_fval – Number of function evaluations performed to find x.

  • n_grad – Number of gradient evaluations performed to find x.

  • n_hess – Number of Hessian evaluations performed to find x.

flip_profile()None[source]

This function flips the profiling direction (left-right) Profiling direction needs to be changed once (if the profile is new), or twice if we append to an existing profile.

All profiling paths are flipped in-place.

pypesto.profile.approximate_parameter_profile(problem: pypesto.problem.Problem, result: pypesto.result.Result, profile_index: Optional[Iterable[int]] = None, profile_list: Optional[int] = None, result_index: int = 0, n_steps: int = 100)pypesto.result.Result[source]

Calculate profiles based on an approximation via a normal likelihood centered at the chosen optimal parameter value, with the covariance matrix being the Hessian or FIM.

Parameters
  • problem – The problem to be solved.

  • result – A result object to initialize profiling and to append the profiling results to. For example, one might append more profiling runs to a previous profile, in order to merge these. The existence of an optimization result is obligatory.

  • profile_index – List with the profile indices to be computed (by default all of the free parameters).

  • profile_list – Integer which specifies whether a call to the profiler should create a new list of profiles (default) or should be added to a specific profile list.

  • result_index – Index from which optimization result profiling should be started (default: global optimum, i.e., index = 0).

  • n_steps – Number of profile steps in each dimension.

Returns

The profile results are filled into result.profile_result.

Return type

result

pypesto.profile.calculate_approximate_ci(xs: numpy.ndarray, ratios: numpy.ndarray, confidence_ratio: float)Tuple[float, float][source]

Calculate approximate confidence interval based on profile. Interval bounds are linerly interpolated.

Parameters
  • xs – The ordered parameter values along the profile for the coordinate of interest.

  • ratios – The likelihood ratios corresponding to the parameter values.

  • confidence_ratio – Minimum confidence ratio to base the confidence interval upon, as obtained via pypesto.profile.chi2_quantile_to_ratio.

Returns

Bounds of the approximate confidence interval.

Return type

lb, ub

pypesto.profile.chi2_quantile_to_ratio(alpha: float = 0.95, df: int = 1)[source]

Transform lower tail probability alpha for a chi2 distribution with df degrees of freedom to a profile likelihood ratio threshold.

Parameters
  • alpha – Lower tail probability, defaults to 95% interval.

  • df – Degrees of freedom.

Returns

Corresponds to a likelihood ratio.

Return type

ratio

pypesto.profile.parameter_profile(problem: pypesto.problem.Problem, result: pypesto.result.Result, optimizer: pypesto.optimize.optimizer.Optimizer, engine: Optional[pypesto.engine.base.Engine] = None, profile_index: Optional[Iterable[int]] = None, profile_list: Optional[int] = None, result_index: int = 0, next_guess_method: Union[Callable, str] = 'adaptive_step_regression', profile_options: Optional[pypesto.profile.options.ProfileOptions] = None, progress_bar: bool = True)pypesto.result.Result[source]

This is the main function to call to do parameter profiling.

Parameters
  • problem – The problem to be solved.

  • result – A result object to initialize profiling and to append the profiling results to. For example, one might append more profiling runs to a previous profile, in order to merge these. The existence of an optimization result is obligatory.

  • optimizer – The optimizer to be used along each profile.

  • engine – The engine to be used.

  • profile_index – List with the parameter indices to be profiled (by default all free indices).

  • profile_list – Integer which specifies whether a call to the profiler should create a new list of profiles (default) or should be added to a specific profile list.

  • result_index – Index from which optimization result profiling should be started (default: global optimum, i.e., index = 0).

  • next_guess_method – Function handle to a method that creates the next starting point for optimization in profiling.

  • profile_options – Various options applied to the profile optimization.

  • progress_bar – Whether to display a progress bar.

Returns

The profile results are filled into result.profile_result.

Return type

result

pypesto.profile.validation_profile_significance(problem_full_data: pypesto.problem.Problem, result_training_data: pypesto.result.Result, result_full_data: Optional[pypesto.result.Result] = None, n_starts: Optional[int] = 1, optimizer: Optional[pypesto.optimize.optimizer.Optimizer] = None, engine: Optional[pypesto.engine.base.Engine] = None, lsq_objective: bool = False, return_significance: bool = True)float[source]

A Validation Interval for significance alpha is a confidence region/ interval for a new validation experiment. 1 et al. (This method per default returns the significance = 1-alpha!)

The reasoning behind their approach is, that a validation data set is outside the validation interval, if fitting the full data set would lead to a fit $ heta_{new}$, that does not contain the old fit $ heta_{train}$ in their (Profile-Likelihood) based parameter-confidence intervals. (I.e. the old fit would be rejected by the fit of the full data.)

This method returns the significance of the validation data set (where result_full_data is the objective function for fitting both data sets). I.e. the largest alpha, such that there is a validation region/interval such that the validation data set lies outside this Validation Interval with probability alpha. (If one is interested in the opposite, set return_significance=False.)

Parameters
  • problem_full_data – pypesto.problem, such that the objective is the negative-log-likelihood of the training and validation data set.

  • result_training_data – result object from the fitting of the training data set only.

  • result_full_data – pypesto.result object that contains the result of fitting training and validation data combined.

  • n_starts – number of starts for fitting the full data set (if result_full_data is not provided).

  • optimizer – optimizer used for refitting the data (if result_full_data is not provided).

  • engine – engine for refitting (if result_full_data is not provided).

  • lsq_objective – indicates if the objective of problem_full_data corresponds to a nllh (False), or a chi^2 value (True).

  • return_significance

    indicates, if the function should return the significance (True) (i.e.

    the probability, that the new data set lies outside the Confidence Interval for the validation experiment, as given by the method), or the largest alpha, such that the validation experiment still lies within the Confidence Interval (False). I.e. alpha = 1-significance.

    1

    Kreutz, Clemens, Raue, Andreas and Timmer, Jens. “Likelihood based observability analysis and confidence intervals for predictions of dynamic models”. BMC Systems Biology 2012/12. doi:10.1186/1752-0509-6-120