pybop.parameters.parameter#

Attributes#

Classes#

Parameter

Represents a parameter within the PyBOP framework.

Parameters

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

get_initial_value() float[source]#

Return the initial value of each parameter.

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.

update(initial_value=None, value=None)[source]#

Update the parameter’s current value.

Parameters:

value (float) – The new value to be assigned to the parameter.

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:

pybop.Parameter

Raises:

ValueError – The key must be the name of one of the parameters.

__iter__()[source]#
__len__() int[source]#
__next__()[source]#
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

current_value() numpy.ndarray[source]#

Return the current value of each parameter.

get_bounds() Dict[source]#

Get bounds, for either all or no parameters.

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() List[source]#

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

initial_value() numpy.ndarray[source]#

Return the initial value of each parameter.

join(parameters=None)[source]#

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

Parameters:

parameters (pybop.Parameters)

keys() List[source]#

A list of parameter names

remove(parameter_name)[source]#

Remove the Parameter object from the Parameters dictionary.

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

true_value() numpy.ndarray[source]#

Return the true value of each parameter.

update(initial_values=None, values=None, bounds=None)[source]#

Set value of each parameter.

verify(inputs: Inputs | None = None)[source]#

Verify that the inputs are an Inputs dictionary or numeric values which can be used to construct an Inputs dictionary

Parameters:

inputs (Inputs or numeric)

pybop.parameters.parameter.Inputs[source]#