pybop._result#

Classes#

OptimisationResult

Stores the result of the optimisation.

SamplingResult

Stores the result of the sampling.

Module Contents#

class pybop._result.OptimisationResult(optim: pybop.BaseOptimiser, logger: pybop.Logger, time: float, optim_name: str | None = None, message: str | None = None, scipy_result=None)[source]#

Stores the result of the optimisation.

optim[source]#

The optimisation object used to generate the results.

Type:

pybop.BaseOptimiser

logger#

The log of the optimisation process.

Type:

pybop.Logger

time[source]#

The time taken.

Type:

float

optim_name[source]#

The name of the optimiser.

Type:

str

message[source]#

The reason for stopping given by the optimiser.

Type:

str

scipy_result[source]#

The result obtained from a SciPy optimiser.

Type:

scipy.optimize.OptimizeResult, optional

__str__() str[source]#

A string representation of the OptimisationResult object.

Returns:

A formatted string containing optimisation result information.

Return type:

str

_check_for_finite_cost() None[source]#

Validate the optimised parameters and ensure they produce a finite cost value.

Raises:

ValueError – If the optimised parameters do not produce a finite cost value.

_get_single_or_all(attr)[source]#
_validate()[source]#

Check that there is a finite cost and update best run.

static combine(results: list[OptimisationResult]) OptimisationResult[source]#

Combine multiple OptimisationResult objects into a single one.

Parameters:

results (list[OptimisationResult]) – List of OptimisationResult objects to combine.

Returns:

Combined OptimisationResult object.

Return type:

OptimisationResult

plot_contour(**kwargs)[source]#

Generate and plot a 2D visualisation of the cost landscape with the optimisation trace.

Parameters:
  • gradient (bool, optional) – If True, gradient plots are also generated (default: False).

  • bounds (numpy.ndarray | list[list[float]], optional) – A 2x2 array specifying the [min, max] bounds for each parameter.

  • transformed (bool, optional) – Uses the transformed parameter values, as seen by the optimiser (default: False).

  • steps (int, optional) – The number of grid points to divide the parameter space into along each dimension (default: 10).

  • show (bool, optional) – If True, the figure is shown upon creation (default: True).

  • **layout_kwargs (optional) – Valid Plotly layout keys and their values.

plot_convergence(**kwargs)[source]#

Plot the evolution of the best cost during the optimisation.

Parameters:
  • show (bool, optional) – If True, the figure is shown upon creation (default: True).

  • **layout_kwargs (optional) – Valid Plotly layout keys and their values.

plot_parameters(**kwargs)[source]#

Plot the evolution of parameter values during the optimisation.

Parameters:
  • show (bool, optional) – If True, the figure is shown upon creation (default: True).

  • **layout_kwargs (optional) – Valid Plotly layout keys and their values.

plot_surface(**kwargs)[source]#

Plot a 2D representation of the Voronoi diagram with color-coded regions.

Parameters:
  • bounds (numpy.ndarray, optional) – A 2x2 array specifying the [min, max] bounds for each parameter.

  • normalise (bool, optional) – If True, the voronoi regions are computed using the Euclidean distance between points normalised with respect to the bounds (default: True).

  • resolution (int, optional) – Resolution of the plot (default: 500).

  • show (bool, optional) – If True, the figure is shown upon creation (default: True).

  • **layout_kwargs (optional) – Valid Plotly layout keys and their values.

total_evaluations() numpy.floating | None[source]#

Calculates the total number of evaluations across all runs.

total_iterations() numpy.floating | None[source]#

Calculates the total number of iterations across all runs.

total_runtime() numpy.floating | None[source]#

Calculates the total runtime across all runs.

_best_cost[source]#
_best_run = None[source]#
_cost[source]#
_initial_cost[source]#
_iteration_number[source]#
_message[source]#
_minimising[source]#
_n_evaluations[source]#
_n_iterations[source]#
_optim[source]#
_scipy_result[source]#
_time[source]#
_x[source]#
_x0[source]#
_x_model[source]#
property best_cost: float[source]#

The best cost value(s).

property best_inputs: dict[str, numpy.ndarray][source]#

The best parameters as a dictionary.

property cost: numpy.ndarray[source]#

The log of the cost values.

property initial_cost: float[source]#

The initial cost value(s).

property iteration_number: numpy.ndarray | None[source]#

The number of iterations.

property message: str | None[source]#

The optimisation termination message(s).

property minimising: bool[source]#

Whether the cost was minimised (or maximised).

property n_evaluations: int[source]#

The number of evaluations.

property n_iterations: int[source]#

The number of iterations.

n_runs = 0[source]#
property optim: pybop.BaseOptimiser[source]#

The optimisation problem.

optim_name = None[source]#
property scipy_result[source]#

The SciPy result.

property time: float | None[source]#

The optimisation time(s).

property x: numpy.ndarray[source]#

The best parameter values (in model space).

property x0: numpy.ndarray[source]#

The initial parameter values.

property x_model: numpy.ndarray[source]#

The log of the evaluated parameters (in model space).

class pybop._result.SamplingResult(sampler: pybop.BaseSampler, logger: pybop.Logger, time: float, chains: numpy.ndarray, sampler_name: str | None = None, message: str | None = None)[source]#

Bases: OptimisationResult

Stores the result of the sampling.

sampler#

The sampler used to generate the results.

Type:

pybop.BaseSampler

logger#

The log of the optimisation process.

Type:

pybop.Logger

time[source]#

The time taken.

Type:

float

chains[source]#

An array containing the samples from the posterior distribution, or None.

Type:

np.ndarray, optional

sampler_name#

The name of the sampler.

Type:

str

message[source]#

The reason for stopping given by the sampler.

Type:

str

chains[source]#