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.
- lower#
Lower bound (inclusive)
- Type:
float
- upper#
Upper bound (inclusive)
- Type:
float
- 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.
- lower: float#
- upper: float#
- class pybop.parameters.parameter.Parameter(distribution: scipy.stats.distributions.rv_frozen | pybop.parameters.distributions.Distribution | None = None, bounds: BoundsPair | None = None, initial_value: float = None, transformation: pybop.transformation.base_transformation.Transformation | None = None)[source]#
Represents a parameter within the PyBOP framework.
This class encapsulates the definition of a parameter, including its initial value, bounds.
- Parameters:
distribution (stats.distribution.rv_frozen | Distribution, optional) – Distribution of the parameter
bounds (tuple[float, float], optional) – Parameter bounds as (lower, upper)
initial_value (NumericValue, optional) – Initial parameter value
transformation (Transformation, optional) – Parameter transformation
- __call__(*unused_args, **unused_kwargs) float | None[source]#
Return the initial value. The unused arguments are to pass pybamm.ParameterValues checks.
- _check_compatible_transformation() None[source]#
Raise an error if the transformation is not compatible with the distribution.
- _validate_initial_value_within_bounds() None[source]#
Validate that the initial value is within the bounds.
- get_initial_value(transformed: bool = False) numpy.typing.NDArray | None[source]#
Get initial value in either the model space or the transformed search space.
- sample_from_distribution(n_samples: int = 1, *, random_state: int | None = None, transformed: bool = False) numpy.typing.NDArray[numpy.floating] | None[source]#
Sample from parameter’s distribution.
- Parameters:
n_samples (int) – Number of samples to draw (default: 1).
random_state (int, optional) – Random seed for reproducibility.
transformed (bool, optional) – Whether to apply transformation to samples (default: False).
- Returns:
Array of samples, or None if no distribution exists exists
- Return type:
NDArray[np.floating] or None
- update_initial_value(value: NumericValue | None) None[source]#
Update the initial parameter value.
- _bounds = None#
- _distribution = None#
- _initial_value = None#
- _transformation#
- property bounds: tuple | None#
Parameter bounds as (lower, upper) tuple.
- property distribution: Any | None#
- property initial_value: float | None#
- property transformation: pybop.transformation.base_transformation.Transformation#
- class pybop.parameters.parameter.Parameters(parameters: dict | Parameters | None = 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, update_distribution: bool = True) None[source]#
Internal method to add a parameter to the collection.
- Parameters:
name (str) – Name of the parameter.
parameter (pybop.Parameter) – The parameter to add.
update_transform (bool, optional) – Whether to update the transformation after adding (default: True).
update_distribution (bool, optional) – Whether to update the joint or multivariate distribution (default: True).
- _bulk_update_initial_values(values: ArrayLike | Inputs) None[source]#
Update initial values in bulk.
- add(name: str, parameter: Parameter, update_distribution: bool = True) 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.
- convert_grad_to_array(grad: dict[str, numpy.ndarray]) numpy.ndarray[source]#
Get an array of sensitivities with the parameters in the expected order.
- copy() Parameters[source]#
Create a deep copy of the Parameters object.
- get_bounds(transformed: bool = False) dict[source]#
Get bounds for each parameter as a dictionary.
- 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_covariance(transformed: bool = False)[source]#
Get the covariance matrix, or an estimate of it.
- Parameters:
transformed (bool, optional) – If True, the transformation is applied to the output (default: False).
- 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_mean(transformed: bool = False)[source]#
Get the mean of each parameter, or its initial value.
- Parameters:
transformed (bool, optional) – If True, the transformation is applied to the output (default: False).
- get_std(transformed: bool = False) list[source]#
Get the standard deviation, or an estimate of it, for each parameter.
- Parameters:
transformed (bool, optional) – 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)
- sample_from_distribution(n_samples: int = 1, *, random_state: int | None = None, transformed: bool = False) numpy.typing.NDArray[numpy.floating] | None[source]#
Sample from a joint or multivariate distribution.
- Parameters:
n_samples (int) – The number of samples to draw (default: 1).
random_state (int, optional) – The random state seed for reproducibility (default: None).
transformed (bool, optional) – If True, the transformation is applied to the output (default: False).
- Returns:
Array of shape (n_samples, n_parameters) or None if any distribution is missing
- Return type:
NDArray[np.floating] or None
- set(name: str, param: Parameter, update_distribution: bool = True) None[source]#
Set a parameter by name.
- to_dict(values: str | ArrayLike | None = None) Inputs[source]#
Return values as a dictionary of inputs.
- 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:
- to_inputs_list(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, **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
- update_distribution()[source]#
Method to determine whether to construct a JointDistribution or a MultivariateDistribution and to set up the distribution.
Multivariate distributions are passed to individual parameters via the corresponding marginal distribution. The pybop.MarginalDistribution class retains the underlying pybop.MultivariateDistribution in the parent_distribution property.
- _distribution = None#
- _multivariate = None#
- _parameters = None#
- _transform = None#
- property distribution: pybop.parameters.multivariate_distributions.BaseMultivariateDistribution | pybop.parameters.distributions.JointDistribution | None#
Return the joint or multivariate distribution.
- property names: list[str]#
- property transformation: pybop.transformation.base_transformation.Transformation#
Get the transformation for the parameters.
- property transformed_distribution_properties#
- pybop.parameters.parameter.ArrayLike#
- pybop.parameters.parameter.BoundsPair#
- pybop.parameters.parameter.Inputs#
- pybop.parameters.parameter.NumericValue#