pybop._result#
Classes#
Stores the result produced by an optimiser or sampler. |
Module Contents#
- class pybop._result.Result(problem: pybop.problems.problem.Problem, logger: pybop._logging.Logger, time: float, method_name: str | None = None, message: str | None = None, scipy_result=None)[source]#
Stores the result produced by an optimiser or sampler.
- problem#
The optimisation problem used to generate the results.
- Type:
- logger#
The log of the optimisation or sampling process.
- Type:
- time#
The time taken.
- Type:
float
- method_name#
The name of the optimiser or sampler.
- Type:
str
- message#
The reason for stopping given by the optimiser or sampler.
- Type:
str
- __str__() str[source]#
A string representation of the Result 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.
- static combine(results: list[Result]) Result[source]#
Combine multiple Result objects into a single one.
- static load_data(filename: str, file_format: str = 'pickle') dict[source]#
Load results data as dictionary from a given file. Restores data saved with save_data.
Calls load_data_dict defined in _utils.py and provides the keys of data that is 0-d and 1-d to ensure consistent data dimensions.
- Parameters:
filename (str) – The name of the file containing the data.
file_format (str, optional) – The format the data was save to. Options are: - ‘pickle’ (default) - ‘matlab’ - ‘csv’ - ‘json’
- Returns:
python dictionary containing the data in the file.
- Return type:
data_dict
- 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.
- save_data(filename=None, to_format='pickle') str | None[source]#
Save result data
Based on pybamm.Solution.save_data
- Parameters:
filename (str, optional) – The name of the file to save data to. If None, then a str is returned for json format or an error is thrown for pickle/matlab.
to_format (str, optional) –
The format to save to. Options are:
’pickle’ (default): creates a pickle file with the data dictionary
’matlab’: creates a .mat file, for loading in matlab
’json’: creates a json file
- Returns:
data – str if ‘json’ is chosen and filename is None, otherwise None
- Return type:
str, optional
- 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.
- _best_cost#
- _best_run = None#
- _cost#
- _initial_cost#
- _iteration_number#
- _message#
- _minimising#
- _n_evaluations#
- _n_iterations#
- _problem#
- _scipy_result#
- _time#
- _x#
- _x0#
- _x_model#
- property best_cost: float#
The best cost value(s).
- property best_inputs: dict[str, numpy.ndarray]#
The best parameters as a dictionary.
- property cost: numpy.ndarray#
The log of the cost values.
- property initial_cost: float#
The initial cost value(s).
- property iteration_number: numpy.ndarray | None#
The number of iterations.
- property message: str | None#
The optimisation termination message(s).
- method_name = None#
- property minimising: bool#
Whether the cost was minimised (or maximised).
- property n_evaluations: int#
The number of evaluations.
- property n_iterations: int#
The number of iterations.
- n_runs = 1#
- property problem: pybop.problems.problem.Problem#
The optimisation problem.
- property scipy_result#
The SciPy result.
- property time: float | None#
The optimisation time(s).
- property x: numpy.ndarray#
The best parameter values (in model space).
- property x0: numpy.ndarray#
The initial parameter values.
- property x_model: numpy.ndarray#
The log of the evaluated parameters (in model space).