pybop.parameters.parameter#
Attributes#
Classes#
Represents a parameter within the PyBOP framework. |
|
Represents a set of uncertain parameters within the PyBOP framework. |
Module Contents#
- class pybop.parameters.parameter.Parameter(name, initial_value=None, true_value=None, prior=None, bounds=None, transformation=None)[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 optimization or sampling.
- Parameters:
name (str) – The name of the parameter.
initial_value (float, optional) – The initial value to be assigned to the parameter. Defaults to None.
prior (scipy.stats distribution, optional) – The prior distribution from which parameter values are drawn. Defaults to None.
bounds (tuple, optional) – A tuple defining the lower and upper bounds for the parameter. Defaults to None.
- Raises:
ValueError – If the lower bound is not strictly less than the upper bound, or if the margin is set outside the interval (0, 1).
- __repr__()[source]#
Return a string representation of the Parameter instance.
- Returns:
A string including the parameter’s name, prior, bounds, and current value.
- Return type:
str
- get_initial_value(apply_transform: bool = False) float[source]#
Return the initial value of each parameter.
- Parameters:
apply_transform (bool) – If True, the transformation is applied to the output (default: False).
- rvs(n_samples: int = 1, random_state=None, apply_transform: bool = False)[source]#
Draw random samples from the parameter’s prior distribution.
The samples are constrained to be within the parameter’s bounds, excluding a predefined margin at the boundaries.
- Parameters:
n_samples (int) – The number of samples to draw (default: 1).
random_state (int, optional) – The random state seed for reproducibility (default: None).
apply_transform (bool) – If True, the transformation is applied to the output (default: False).
- Returns:
An array of samples drawn from the prior distribution within the parameter’s bounds.
- Return type:
array-like
- set_bounds(bounds=None, boundary_multiplier=6)[source]#
Set the upper and lower bounds.
- Parameters:
bounds (tuple, optional) – A tuple defining the lower and upper bounds for the parameter. Defaults to None.
boundary_multiplier (float, optional) – Used to define the bounds when no bounds are passed but the parameter has a prior distribution (default: 6).
- Raises:
ValueError – If the lower bound is not strictly less than the upper bound, or if the margin is set outside the interval (0, 1).
- set_margin(margin)[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.
- Parameters:
margin (float) – The new margin value to be used, which must be in the interval (0, 1).
- Raises:
ValueError – If the margin is not between 0 and 1.
- class pybop.parameters.parameter.Parameters(*args)[source]#
Represents a set of uncertain parameters 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:
parameter_list (pybop.Parameter or Dict)
- __getitem__(key: str) Parameter[source]#
Return the parameter dictionary corresponding to a particular key.
- Parameters:
key (str) – The name of a parameter.
- Returns:
The Parameter object.
- Return type:
- Raises:
ValueError – The key must be the name of one of the parameters.
- __repr__()[source]#
Return a string representation of the Parameters instance.
- Returns:
A string including the number of parameters and a summary of each parameter.
- Return type:
str
- add(parameter)[source]#
Construct the parameter class with a name, initial value, prior, and bounds.
- as_dict(values=None) dict[source]#
- Parameters:
values (list or str, optional) – A list of parameter values or one of the strings “initial” or “true” which can be used to obtain a dictionary of parameters.
- Returns:
A parameters dictionary.
- Return type:
Inputs
- construct_transformation()[source]#
Create a ComposedTransformation object from the individual parameter transformations.
- get_bounds(apply_transform: bool = False) dict[source]#
Get bounds, for either all or no parameters.
- Parameters:
apply_transform (bool) – If True, the transformation is applied to the output (default: False).
- get_bounds_for_plotly()[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_sigma0(apply_transform: bool = False) list[source]#
Get the standard deviation, for either all or no parameters.
- Parameters:
apply_transform (bool) – If True, the transformation is applied to the output (default: False).
- initial_value(apply_transform: bool = False) numpy.ndarray[source]#
Return the initial value of each parameter.
- Parameters:
apply_transform (bool) – If True, the transformation is applied to the output (default: False).
- join(parameters=None)[source]#
Join two Parameters objects into the first by copying across each Parameter.
- Parameters:
parameters (pybop.Parameters)
- reset_initial_value(apply_transform: bool = False) numpy.ndarray[source]#
Reset and return the initial value of each parameter.
- Parameters:
apply_transform (bool) – If True, the transformation is applied to the output (default: False).
- rvs(n_samples: int = 1, apply_transform: bool = False) numpy.ndarray[source]#
Draw random samples from each parameter’s prior distribution.
The samples are constrained to be within the parameter’s bounds, excluding a predefined margin at the boundaries.
- Parameters:
n_samples (int) – The number of samples to draw (default: 1).
apply_transform (bool) – If True, the transformation is applied to the output (default: False).
- Returns:
An array of samples drawn from the prior distribution within each parameter’s bounds.
- Return type:
array-like