pypesto.result

Result

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

class pypesto.result.LazyOptimizerResult[source]

Bases: OptimizerResult

A class to handle lazy loading of optimizer results from an HDF5 file.

This class extends the OptimizerResult class and overrides methods to load data only when it is accessed, improving memory usage and performance for large datasets.

filename

The path to the HDF5 file containing the optimizer results.

Type:

str

group_name

The name of the group in the HDF5 file where the results are stored.

Type:

str

_data

A dictionary to store loaded data.

Type:

dict

_metadata_loaded

A flag indicating whether metadata has been loaded.

Type:

bool

__init__(filename, group_name)[source]

Initialize a LazyOptimizerResult instance.

Parameters:
  • filename (str) – The path to the HDF5 file containing the optimizer results.

  • group_name (str) – The name of the group in the HDF5 file where the results are stored.

property exitflag

See OptimizerResult.

property free_indices

See OptimizerResult.

property fval

See OptimizerResult.

property fval0

See OptimizerResult.

property grad

See OptimizerResult.

property hess

See OptimizerResult.

property history

See OptimizerResult.

property id

See OptimizerResult.

property inner_parameters

See OptimizerResult.

property message

See OptimizerResult.

property n_fval

See OptimizerResult.

property n_grad

See OptimizerResult.

property n_hess

See OptimizerResult.

property n_res

See OptimizerResult.

property n_sres

See OptimizerResult.

property optimizer

See OptimizerResult.

property res

See OptimizerResult.

property spline_knots

See OptimizerResult.

property sres

See OptimizerResult.

property time

See OptimizerResult.

property x

See OptimizerResult.

property x0

See OptimizerResult.

class pypesto.result.McmcPtResult[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

  • chains (n_chain denotes the number of)

  • of (n_iter the number)

  • (i.e. (iterations)

  • length) (the chain)

  • parameters. (and n_par the number of)

__init__(trace_x, trace_neglogpost, trace_neglogprior, betas, burn_in=None, time=0.0, auto_correlation=None, effective_sample_size=None, message=None)[source]
Parameters:
class pypesto.result.OptimizeResult[source]

Bases: object

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

__init__()[source]
append(optimize_result, sort=True, prefix='')[source]

Append an OptimizerResult or an OptimizeResult to the result object.

Parameters:
  • optimize_result (Union[OptimizerResult, OptimizeResult]) – The result of one or more (local) optimizer run.

  • sort (bool) – Boolean used so we only sort once when appending an optimize_result.

  • prefix (str) – The IDs for all appended results will be prefixed with this.

as_dataframe(keys=None)[source]

Get as pandas DataFrame.

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

Return type:

DataFrame

as_list(keys=None)[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.

Return type:

Sequence

get_by_id(ores_id)[source]

Get OptimizationResult with the specified id.

Parameters:

ores_id (str)

get_for_key(key)[source]

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

Return type:

list

sort()[source]

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

summary(disp_best=True, disp_worst=False, full=False, show_hess=True)[source]

Get summary of the object.

Parameters:
  • disp_best (bool) – Whether to display a detailed summary of the best run.

  • disp_worst (bool) – Whether to display a detailed summary of the worst run.

  • full (bool) – If True, print full vectors including fixed parameters.

  • show_hess (bool) – If True, display the Hessian of the OptimizerResult.

Return type:

str

class pypesto.result.OptimizerResult[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

optimizer

The optimizer used for optimization.

Type:

str

Notes

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

__init__(id=None, x=None, fval=None, grad=None, hess=None, res=None, sres=None, n_fval=None, n_grad=None, n_hess=None, n_res=None, n_sres=None, x0=None, fval0=None, history=None, exitflag=None, time=None, message=None, optimizer=None)[source]
Parameters:
summary(full=False, show_hess=True)[source]

Get summary of the object.

Parameters:
  • full (bool) – If True, print full vectors including fixed parameters.

  • show_hess (bool) – If True, display the Hessian of the result.

Return type:

str

Returns:

summary (str)

update_to_full(problem)[source]

Update values to full vectors/matrices.

Parameters:

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

Return type:

None

class pypesto.result.PredictionConditionResult[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, output_ids, output=None, output_sensi=None, output_weight=None, output_sigmay=None, x_names=None)[source]

Initialize PredictionConditionResult.

Parameters:
  • timepoints (ndarray) – Output timepoints for this simulation condition

  • output_ids (Sequence[str]) – IDs of outputs for this simulation condition

  • output (ndarray) – Postprocessed outputs (ndarray)

  • output_sensi (ndarray) – Sensitivities of postprocessed outputs (ndarray)

  • output_weight (float) – LLH of the simulation

  • output_sigmay (ndarray) – Standard deviations of postprocessed observables

  • x_names (Sequence[str]) – IDs of model parameter w.r.t to which sensitivities were computed

class pypesto.result.PredictionResult[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, condition_ids=None, comment=None)[source]

Initialize PredictionResult.

Parameters:
  • conditions (Sequence[Union[PredictionConditionResult, dict]]) – A list of PredictionConditionResult objects or dicts

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

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

write_to_csv(output_file)[source]

Save predictions to a csv file.

Parameters:

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

write_to_h5(output_file, base_path=None)[source]

Save predictions to an h5 file.

It appends to the file if the file already exists.

Parameters:
  • output_file (str) – path to file/folder to which results will be written

  • base_path (str) – 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]
append_empty_profile_list()[source]

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

Return type:

int

Returns:

index – The index of the created profile list.

append_profiler_result(profiler_result=None, profile_list=None)[source]

Append the profiler result to the profile list.

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

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

Return type:

None

get_profiler_result(i_par, profile_list=None)[source]

Get the profiler result at parameter index i_par of profile_list.

Parameters:
  • i_par (int) – Integer specifying the profile index.

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

set_profiler_result(profiler_result, i_par, profile_list=None)[source]

Write a profiler result to the result object.

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

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

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

Return type:

None

class pypesto.result.ProfilerResult[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.

color_path

The color of the profile path. Signifies types of steps made. Red indicates a step for which min_step_size was reduced, blue indicates a step for which max_step_size was increased, and green indicates a step for which the profiler had to resample the parameter vector due to optimization failure of the previous two. Black indicates a step for which none of the above was necessary.

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, fval_path, ratio_path, gradnorm_path=None, exitflag_path=None, time_path=None, color_path=None, time_total=0.0, n_fval=0, n_grad=0, n_hess=0, message=None)[source]
Parameters:
append_profile_point(x, fval, ratio, gradnorm=nan, time=nan, color=nan, exitflag=nan, n_fval=0, n_grad=0, n_hess=0)[source]

Append a new point to the profile path.

Parameters:
  • x (ndarray) – The parameter values.

  • fval (float) – The function value at x.

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

  • gradnorm (float) – The gradient norm at x.

  • time (float) – The computation time to find x.

  • color (ndarray) – The color of the profile path. Signifies types of steps made.

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

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

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

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

Return type:

None

flip_profile()[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.

Return type:

None

class pypesto.result.Result[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, optimize_result=None, profile_result=None, sample_result=None)[source]
Parameters:
summary(full=False, show_hess=True)[source]

Get summary of the object.

Parameters:
  • full (bool) – If True, print full vectors including fixed parameters.

  • show_hess (bool) – If True, display the Hessian of the OptimizeResult.

Return type:

str

class pypesto.result.SampleResult[source]

Bases: object

Result of the sample() function.

__init__()[source]