Result

The pypesto.Result object contains all results generated by the pypesto components. It contains sub-results for optimization, profiling, sampling.

class pypesto.result.McmcPtResult(trace_x: numpy.ndarray, trace_neglogpost: numpy.ndarray, trace_neglogprior: numpy.ndarray, betas: Iterable[float], burn_in: Optional[int] = None, time: float = 0.0, auto_correlation: Optional[float] = None, effective_sample_size: Optional[float] = None, message: Optional[str] = None)[source]

Bases: dict

The result of a sampler run using Markov-chain Monte Carlo.

Currently result object of all supported samplers. Can be used like a dict.

Parameters
  • trace_x ([n_chain, n_iter, n_par]) – Parameters.

  • trace_neglogpost ([n_chain, n_iter]) – Negative log posterior values.

  • trace_neglogprior ([n_chain, n_iter]) – Negative log prior values.

  • betas ([n_chain]) – The associated inverse temperatures.

  • burn_in ([n_chain]) – The burn in index.

  • time ([n_chain]) – The computation time.

  • auto_correlation ([n_chain]) – The estimated chain autcorrelation.

  • effective_sample_size ([n_chain]) – The estimated effective sample size.

  • message (str) – Textual comment on the profile result.

  • Here

  • denotes the number of chains (n_chain) –

  • the number of (n_iter) –

  • (i.e. (iterations) –

  • chain length) (the) –

  • n_par the number of parameters. (and) –

__init__(trace_x: numpy.ndarray, trace_neglogpost: numpy.ndarray, trace_neglogprior: numpy.ndarray, betas: Iterable[float], burn_in: Optional[int] = None, time: float = 0.0, auto_correlation: Optional[float] = None, effective_sample_size: Optional[float] = None, message: Optional[str] = None)[source]

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

class pypesto.result.OptimizeResult[source]

Bases: object

Result of the pypesto.optimize.minimize() function.

__init__()[source]

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

append(optimizer_result: pypesto.result.optimize.OptimizerResult)[source]

Append an optimizer result to the result object.

Parameters

optimizer_result – The result of one (local) optimizer run.

as_dataframe(keys=None)pandas.core.frame.DataFrame[source]

Get as pandas DataFrame.

If keys is a list, return only the specified values, otherwise all.

as_list(keys=None)Sequence[source]

Get as list.

If keys is a list, return only the specified values.

Parameters

keys (list(str), optional) – Labels of the field to extract.

get_for_key(key)list[source]

Extract the list of values for the specified key as a list.

sort()[source]

Sort the optimizer results by function value fval (ascending).

class pypesto.result.OptimizerResult(id: Optional[str] = None, x: Optional[numpy.ndarray] = None, fval: Optional[float] = None, grad: Optional[numpy.ndarray] = None, hess: Optional[numpy.ndarray] = None, res: Optional[numpy.ndarray] = None, sres: Optional[numpy.ndarray] = None, n_fval: Optional[int] = None, n_grad: Optional[int] = None, n_hess: Optional[int] = None, n_res: Optional[int] = None, n_sres: Optional[int] = None, x0: Optional[numpy.ndarray] = None, fval0: Optional[float] = None, history: Optional[pypesto.objective.history.History] = None, exitflag: Optional[int] = None, time: Optional[float] = None, message: Optional[str] = None)[source]

Bases: dict

The result of an optimizer run.

Used as a standardized return value to map from the individual result objects returned by the employed optimizers to the format understood by pypesto.

Can be used like a dict.

id

Id of the optimizer run. Usually the start index.

x

The best found parameters.

fval

The best found function value, fun(x).

grad

The gradient at x.

hess

The Hessian at x.

res

The residuals at x.

sres

The residual sensitivities at x.

n_fval

Number of function evaluations.

n_grad

Number of gradient evaluations.

n_hess

Number of Hessian evaluations.

n_res

Number of residuals evaluations.

n_sres

Number of residual sensitivity evaluations.

x0

The starting parameters.

fval0

The starting function value, fun(x0).

history

Objective history.

exitflag

The exitflag of the optimizer.

time

Execution time.

message

Textual comment on the optimization result.

Type

str

Notes

Any field not supported by the optimizer is filled with None.

__init__(id: Optional[str] = None, x: Optional[numpy.ndarray] = None, fval: Optional[float] = None, grad: Optional[numpy.ndarray] = None, hess: Optional[numpy.ndarray] = None, res: Optional[numpy.ndarray] = None, sres: Optional[numpy.ndarray] = None, n_fval: Optional[int] = None, n_grad: Optional[int] = None, n_hess: Optional[int] = None, n_res: Optional[int] = None, n_sres: Optional[int] = None, x0: Optional[numpy.ndarray] = None, fval0: Optional[float] = None, history: Optional[pypesto.objective.history.History] = None, exitflag: Optional[int] = None, time: Optional[float] = None, message: Optional[str] = None)[source]

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

update_to_full(problem: pypesto.problem.Problem)None[source]

Update values to full vectors/matrices.

Parameters

problem – problem which contains info about how to convert to full vectors or matrices

class pypesto.result.PredictionConditionResult(timepoints: numpy.ndarray, output_ids: Sequence[str], output: Optional[numpy.ndarray] = None, output_sensi: Optional[numpy.ndarray] = None, output_weight: Optional[float] = None, output_sigmay: Optional[numpy.ndarray] = None, x_names: Optional[Sequence[str]] = None)[source]

Bases: object

Light-weight wrapper for the prediction of one simulation condition.

It should provide a common api how amici predictions should look like in pyPESTO.

__init__(timepoints: numpy.ndarray, output_ids: Sequence[str], output: Optional[numpy.ndarray] = None, output_sensi: Optional[numpy.ndarray] = None, output_weight: Optional[float] = None, output_sigmay: Optional[numpy.ndarray] = None, x_names: Optional[Sequence[str]] = None)[source]

Initialize PredictionConditionResult.

Parameters
  • timepoints – Output timepoints for this simulation condition

  • output_ids – IDs of outputs for this simulation condition

  • output – Postprocessed outputs (ndarray)

  • output_sensi – Sensitivities of postprocessed outputs (ndarray)

  • output_weight – LLH of the simulation

  • output_sigmay – Standard deviations of postprocessed observables

  • x_names – IDs of model parameter w.r.t to which sensitivities were computed

class pypesto.result.PredictionResult(conditions: Sequence[Union[pypesto.result.predict.PredictionConditionResult, Dict]], condition_ids: Optional[Sequence[str]] = None, comment: Optional[str] = None)[source]

Bases: object

Light-weight wrapper around prediction from pyPESTO made by an AMICI model.

Its only purpose is to have fixed format/api, how prediction results should be stored, read, and handled: as predictions are a very flexible format anyway, they should at least have a common definition, which allows to work with them in a reasonable way.

__init__(conditions: Sequence[Union[pypesto.result.predict.PredictionConditionResult, Dict]], condition_ids: Optional[Sequence[str]] = None, comment: Optional[str] = None)[source]

Initialize PredictionResult.

Parameters
  • conditions – A list of PredictionConditionResult objects or dicts

  • condition_ids – IDs or names of the simulation conditions, which belong to this prediction (e.g., PEtab uses tuples of preequilibration condition and simulation conditions)

  • comment – An additional note, which can be attached to this prediction

write_to_csv(output_file: str)[source]

Save predictions to a csv file.

Parameters

output_file – path to file/folder to which results will be written

write_to_h5(output_file: str, base_path: Optional[str] = None)[source]

Save predictions to an h5 file.

It appends to the file if the file already exists.

Parameters
  • output_file – path to file/folder to which results will be written

  • base_path – base path in the h5 file

class pypesto.result.ProfileResult[source]

Bases: object

Result of the profile() function.

It holds a list of profile lists. Each profile list consists of a list of ProfilerResult objects, one for each parameter.

__init__()[source]

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

append_empty_profile_list()int[source]

Append an empty profile list to the list of profile lists.

Returns

The index of the created profile list.

Return type

index

append_profiler_result(profiler_result: Optional[pypesto.result.profile.ProfilerResult] = None, profile_list: Optional[int] = None)None[source]

Append the profiler result to the profile list.

Parameters
  • profiler_result – The result of one profiler run for a parameter, or None if to be left empty.

  • profile_list – Index specifying the profile list to which we want to append. Defaults to the last list.

get_profiler_result(i_par: int, profile_list: Optional[int] = None)[source]

Get the profiler result at parameter index i_par of profile_list.

Parameters
  • i_par – Integer specifying the profile index.

  • profile_list – Index specifying the profile list. Defaults to the last list.

set_profiler_result(profiler_result: pypesto.result.profile.ProfilerResult, i_par: int, profile_list: Optional[int] = None)None[source]

Write a profiler result to the result object.

Parameters
  • profiler_result – The result of one (local) profiler run.

  • i_par – Integer specifying the parameter index where to put profiler_result.

  • profile_list – Index specifying the profile list. Defaults to the last list.

class pypesto.result.ProfilerResult(x_path: numpy.ndarray, fval_path: numpy.ndarray, ratio_path: numpy.ndarray, gradnorm_path: numpy.ndarray = nan, exitflag_path: numpy.ndarray = nan, time_path: numpy.ndarray = nan, 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 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: numpy.ndarray = nan, exitflag_path: numpy.ndarray = nan, time_path: numpy.ndarray = nan, 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]

Append 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]

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

class pypesto.result.Result(problem=None)[source]

Bases: object

Universal result object for pypesto.

The algorithms like optimize, profile, sample fill different parts of it.

problem

The problem underlying the results.

Type

pypesto.Problem

optimize_result

The results of the optimizer runs.

profile_result

The results of the profiler run.

sample_result

The results of the sampler run.

__init__(problem=None)[source]

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

class pypesto.result.SampleResult[source]

Bases: object

Result of the sample() function.

__init__()[source]

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