pybop.plotting.plot_cost2d#
Module Contents#
Functions#
|
Create a Plotly figure with a 2D contour plot of the cost landscape. |
|
Retrieve parameter bounds from a cost function's associated problem parameters. |
|
Plot a 2D visualization of a cost landscape using Plotly. |
- pybop.plotting.plot_cost2d.create_figure(x, y, z, bounds, params, optim)[source]#
Create a Plotly figure with a 2D contour plot of the cost landscape.
- Parameters:
x (numpy.ndarray) – 1D array of x-coordinates for the meshgrid.
y (numpy.ndarray) – 1D array of y-coordinates for the meshgrid.
z (numpy.ndarray) – 2D array of cost function values corresponding to the meshgrid.
bounds (numpy.ndarray) – A 2x2 array specifying the [min, max] bounds for each parameter.
params (iterable) – An iterable of parameter objects with ‘name’ attributes for axis labeling.
optim (object) – An optimiser instance with ‘log’ and ‘x0’ attributes for plotting traces.
- Returns:
The Plotly figure object with the contour plot and optimization traces.
- Return type:
plotly.graph_objs.Figure
- pybop.plotting.plot_cost2d.get_param_bounds(cost)[source]#
Retrieve parameter bounds from a cost function’s associated problem parameters.
- Parameters:
cost (callable) – The cost function with an associated ‘problem’ attribute containing ‘parameters’.
- Returns:
An array of shape (n_parameters, 2) containing the bounds for each parameter.
- Return type:
numpy.ndarray
- pybop.plotting.plot_cost2d.plot_cost2d(cost, bounds=None, optim=None, steps=10)[source]#
Plot a 2D visualization of a cost landscape using Plotly.
This function generates a contour plot representing the cost landscape for a provided callable cost function over a grid of parameter values within the specified bounds.
- Parameters:
cost (callable) – The cost function to be evaluated. Must accept a list of parameters and return a cost value.
bounds (numpy.ndarray, optional) – A 2x2 array specifying the [min, max] bounds for each parameter. If None, uses get_param_bounds.
optim (object, optional) – An optimiser instance which, if provided, overlays its specific trace on the plot.
steps (int, optional) – The number of intervals to divide the parameter space into along each dimension (default is 10).
- Returns:
The Plotly figure object containing the cost landscape plot.
- Return type:
plotly.graph_objs.Figure
- Raises:
ValueError – If the cost function does not return a valid cost when called with a parameter list.