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)[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
- rvs(n_samples, random_state=None)[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.
- 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.
- 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
- 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
- join(parameters=None)[source]#
Join two Parameters objects into the first by copying across each Parameter.
- Parameters:
parameters (pybop.Parameters)
- rvs(n_samples: int) List[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.
- Returns:
An array of samples drawn from the prior distribution within each parameter’s bounds.
- Return type:
array-like