pybop.parameters.parameter#
Attributes#
Exceptions#
Base exception for parameter-related errors. |
|
Raised when a parameter is not found. |
|
Raised when parameter validation fails. |
Classes#
Immutable bounds representation with validation. |
|
Represents a parameter within the PyBOP framework. |
|
Container for managing multiple Parameter objects with additional functionality. |
Module Contents#
- exception pybop.parameters.parameter.ParameterError[source]#
Bases:
ExceptionBase exception for parameter-related errors.
- exception pybop.parameters.parameter.ParameterNotFoundError[source]#
Bases:
ParameterErrorRaised when a parameter is not found.
- exception pybop.parameters.parameter.ParameterValidationError[source]#
Bases:
ParameterErrorRaised when parameter validation fails.
- class pybop.parameters.parameter.Bounds[source]#
Immutable bounds representation with validation.
- class pybop.parameters.parameter.Parameter(*, initial_value: float = None, current_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
current_value (NumericValue, optional) – Current parameter value (defaults to initial_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.
- _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.
- 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
- 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.
- _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.
- 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_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).
- get_values(*, transformed: bool = False) numpy.typing.NDArray[numpy.floating][source]#
Get current values as array.
- Parameters:
transformed (bool, default=False) – Whether to apply transformations
- Returns:
Array of current values
- Return type:
NDArray[np.floating]
- 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)
- reset_to_initial(names: collections.abc.Sequence[str] | None = None) None[source]#
Reset parameters to initial values.
- 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 (‘current’, ‘initial’) or custom array. Default is “current”.
- 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(*, values: ArrayLike | Inputs | None = None, 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:
values (array-like or dict, optional) – New current values (by position or name)
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