pybop.parameters.parameter#

Attributes#

Exceptions#

ParameterError

Base exception for parameter-related errors.

ParameterNotFoundError

Raised when a parameter is not found.

ParameterValidationError

Raised when parameter validation fails.

Classes#

Bounds

Immutable bounds representation with validation.

Parameter

Represents a parameter within the PyBOP framework.

Parameters

Container for managing multiple Parameter objects with additional functionality.

Module Contents#

exception pybop.parameters.parameter.ParameterError[source]#

Bases: Exception

Base exception for parameter-related errors.

exception pybop.parameters.parameter.ParameterNotFoundError[source]#

Bases: ParameterError

Raised when a parameter is not found.

exception pybop.parameters.parameter.ParameterValidationError[source]#

Bases: ParameterError

Raised when parameter validation fails.

class pybop.parameters.parameter.Bounds[source]#

Immutable bounds representation with validation.

lower[source]#

Lower bound (inclusive)

Type:

float

upper[source]#

Upper bound (inclusive)

Type:

float

__post_init__() None[source]#
clip(value: NumericValue) float[source]#

Clip value to bounds.

clip_array(values: ArrayLike) numpy.typing.NDArray[numpy.floating][source]#

Clip array values to bounds.

contains(value: NumericValue) bool[source]#

Check if value is within bounds.

contains_array(values: ArrayLike) bool[source]#

Check if all values in array are within bounds.

width() float[source]#

Return the width of the bounds.

lower: float[source]#
upper: float[source]#
class pybop.parameters.parameter.Parameter(*, initial_value: float = None, bounds: BoundsPair | None = None, prior: pybop.parameters.priors.BasePrior | None = None, transformation: pybop.transformation.base_transformation.Transformation | None = None, margin: float = 0.0001)[source]#

Represents a parameter within the PyBOP framework.

This class encapsulates the definition of a parameter, including its name, prior distribution, initial value, bounds, and a margin to ensure the parameter stays within feasible limits during optimisation or sampling.

Parameters:
  • initial_value (NumericValue, optional) – Initial parameter value

  • bounds (tuple[float, float], optional) – Parameter bounds as (lower, upper)

  • prior (pybop.BasePrior, optional) – Prior distribution object

  • transformation (Transformation, optional) – Parameter transformation

  • margin (float, default=1e-4) – Safety margin for bounds sampling

__call__(*unused_args, **unused_kwargs) float[source]#

Return the current value. The unused arguments are to pass pybamm.ParameterValues checks.

__hash__() int[source]#

Hash based on name.

__repr__() str[source]#

String representation of the parameter.

_set_margin(margin: float) None[source]#

Set the margin to a specified positive value less than 1.

The margin is used to ensure parameter samples are not drawn exactly at the bounds, which may be problematic in some optimization or sampling algorithms.

_validate_values_within_bounds() None[source]#

Validate that initial values are within bounds.

get_initial_value_transformed() numpy.typing.NDArray | None[source]#

Get initial value in transformed space.

sample_from_prior(n_samples: int = 1, *, random_state: int | None = None, transformed: bool = False) numpy.typing.NDArray[numpy.floating] | None[source]#

Sample from parameter’s prior distribution.

Parameters:
  • n_samples (int) – Number of samples to draw (default: 1).

  • random_state (int, optional) – Random seed for reproducibility.

  • transformed (bool) – Whether to apply transformation to samples (default: False).

Returns:

Array of samples, or None if no prior exists

Return type:

NDArray[np.floating] or None

set_bounds(bounds: BoundsPair) None[source]#

Set new parameter bounds.

Parameters:

bounds (tuple[float, float]) – New bounds as (lower, upper)

update_initial_value(value: NumericValue) None[source]#

Update the initial parameter value.

Parameters:

value (NumericValue) – New initial value

_bounds: Bounds | None = None[source]#
_initial_value[source]#
_prior = None[source]#
_transformation[source]#
property bounds: BoundsPair | None[source]#

Parameter bounds as (lower, upper) tuple.

property initial_value: float[source]#
property prior: Any | None[source]#
property transformation: pybop.transformation.base_transformation.Transformation[source]#
class pybop.parameters.parameter.Parameters(parameters: dict | Parameters = None)[source]#

Container for managing multiple Parameter objects with additional functionality.

This class provides a comprehensive interface for parameter management including validation, transformation, serialisation, and bulk operations.

__contains__(name: str) bool[source]#
__getitem__(name: str) Parameter[source]#
__iter__() collections.abc.Iterator[Parameter][source]#
__len__() int[source]#
__repr__() str[source]#
_add(name: str, parameter: Parameter, update_transform: bool = True) None[source]#

Internal method to add a parameter to the collection.

Parameters:
  • parameter (Parameter) – Parameter to add

  • update_transform (bool, optional) – Whether to update the transformation after adding (default: True)

_bulk_update_bounds(bounds: collections.abc.Sequence[BoundsPair] | dict[str, BoundsPair]) None[source]#

Update bounds in bulk.

_bulk_update_initial_values(values: ArrayLike | Inputs) None[source]#

Update initial values in bulk.

add(name: str, parameter: Parameter) None[source]#

Add a parameter to the collection.

construct_transformation() pybop.transformation.base_transformation.Transformation[source]#

Create a ComposedTransformation object from the individual parameter transformations.

copy() Parameters[source]#

Create a deep copy of the Parameters object.

get(name: str) Parameter[source]#

Get a parameter by name.

get_bounds(transformed: bool = False) dict[source]#

Get bounds, for either all or no parameters.

Parameters:

transformed (bool) – If True, the transformation is applied to the output (default: False).

get_bounds_array(transformed: bool = False) numpy.ndarray[source]#

Retrieve parameter bounds in numpy format.

Returns:

bounds – An array of shape (n_parameters, 2) containing the bounds for each parameter.

Return type:

numpy.ndarray

get_bounds_for_plotly(transformed: bool = False) numpy.ndarray[source]#

Retrieve parameter bounds in the format expected by Plotly.

Returns:

bounds – An array of shape (n_parameters, 2) containing the bounds for each parameter.

Return type:

numpy.ndarray

get_initial_values(*, transformed: bool = False) numpy.typing.NDArray[numpy.floating][source]#

Get initial values as array.

Parameters:

transformed (bool, default=False) – Whether to apply transformations to bounds

Returns:

Array of initial values

Return type:

NDArray[np.floating]

get_sigma0(transformed: bool = False) list[source]#

Get the standard deviation, for either all or no parameters.

Parameters:

transformed (bool) – If True, the transformation is applied to the output (default: False).

items() collections.abc.Iterator[tuple[str, Parameter]][source]#

Iterate over (name, parameter) pairs.

join(parameters=None)[source]#

Join two Parameters objects into the first by copying across each Parameter.

Parameters:

parameters (pybop.Parameters)

keys() collections.abc.Iterator[str][source]#

Iterate over parameter names.

priors() list[source]#

Return the prior distribution of each parameter.

remove(name: str) Parameter[source]#

Remove parameter and return it.

remove_bounds() None[source]#
sample_from_priors(n_samples: int = 1, *, random_state: int | None = None, transformed: bool = False) numpy.typing.NDArray[numpy.floating] | None[source]#

Sample from all parameter priors.

Returns:

Array of shape (n_samples, n_parameters) or None if any prior is missing

Return type:

NDArray[np.floating] or None

to_dict(values: str | ArrayLike | None = None) Inputs[source]#

Convert to parameter dictionary.

Parameters:

values (str or array-like, optional) – Which values to use (‘initial’) or custom array. Default is “initial”.

Returns:

Dictionary mapping parameter names to values

Return type:

Inputs

to_inputs(values: numpy.ndarray | list[numpy.ndarray]) list[Inputs][source]#

Return parameter values as a list of dictionaries, as required for multiprocessing.

update(*, initial_values: ArrayLike | Inputs | None = None, bounds: collections.abc.Sequence[BoundsPair] | dict[str, BoundsPair] | None = None, **individual_updates: dict[str, Any]) None[source]#

Update multiple parameters efficiently.

Parameters:
  • initial_values (array-like or dict, optional) – New initial values (by position or name)

  • bounds (sequence or dict, optional) – New bounds (by position or name)

  • **individual_updates (dict) – Individual parameter updates with parameter names as keys

values() collections.abc.Iterator[Parameter][source]#

Iterate over parameters.

verify_inputs(inputs: Inputs) bool[source]#

Check if the inputs are valid parameters.

_parameters[source]#
_transform = None[source]#
property names: list[str][source]#
property transformation: pybop.transformation.base_transformation.Transformation[source]#

Get the transformation for the parameters.

pybop.parameters.parameter.ArrayLike[source]#
pybop.parameters.parameter.BoundsPair[source]#
pybop.parameters.parameter.Inputs[source]#
pybop.parameters.parameter.NumericValue[source]#