Parameter (pmrf.Parameter
)
- class pmrf.parameters.Parameter(value, prior=None, fixed=False, scale=1.0, name=None)[source]
Bases:
Module
Overview
A container for a parameter, usually used within a Model.
This class serves as the fundamental building block for defining the tunable or fixed parameters within a paramrf Model and for fitting. It is designed to be a flexible container that behaves like a standard numerical type (e.g., a numpy.ndarray) while holding additional metadata for model fitting and analysis.
Usage
Use in mathematical operations just like a JAX/numpy array
Parameter objects are JAX PyTrees, making them compatible with JAX’s transformations (jit, grad, etc.).
Mark as fixed (which is honoured by fitting and sampling routines)
Associate priors, specified as numpyro distributions (uniform, normal etc.)
Examples
import pmrf as prf import jax.numpy as jnp # A simple, single-valued parameter, initialized with a float p1 = prf.Parameter(value=1.0e-12, name='C1') # This parameter can be used in calculations directly (scaling is done during casting) impedance = 1 / (2j * jnp.pi * 1e9 * p1) print(f"Impedance: {impedance}") # A parameter that is fixed and will not be optimized during a fit p2 = prf.Parameter(value=50.0, fixed=True, name='Z0') # A parameter with a uniform distribution prior # Factory functions are a convenient way to create these p3 = prf.Uniform(min=0.9e-9, max=1.1e-9, name='L1') # The parameter's value is initialized to the mean of the distribution print(f"Initial value of L1: {p3.value}")
- value: Array
- prior: Distribution | None = None
- fixed: bool = False
- scale: float = 1.0
- name: str | None = None
- property ndim: int
The number of free dimensions for this parameter.
- property min: array
The unscaled minimum value of the parameter’s distribution (MIN_PERCENTILE quantile).
- Returns:
The minimum value, or -np.inf if no distribution is set.
- Return type:
jnp.array
- property max: array
The unscaled maximum value of the parameter’s distribution (MAX_PERCENTILE quantile).
- Returns:
The maximum value, or np.inf if no distribution is set.
- Return type:
jnp.array
- with_value(value)[source]
Return a copy with a new unscaled value.
- Parameters:
value (jnp.array) – The new unscaled value to set.
- Returns:
A copy of this object with
value
replaced.- Return type:
- with_prior(prior)[source]
Return a copy with a new prior distribution.
- Parameters:
prior (numpyro.distributions.Distribution) – The prior to associate with this parameter.
- Returns:
A copy of this object with
prior
replaced.- Return type:
- flatten(separator='_')[source]
Flattens self, either returning a single Parameter if the internal parameter is scalar, or a list. If the internal prior cannot be separated, this will raise an Exception.
- Returns:
The raveled parameters.
- Return type:
‘Parameter’ | list[‘Parameter’]
- as_free()[source]
Returns a copy of self with fixed set to False.
- Returns:
The new, fixed parameter.
- Return type:
- copy()[source]
Return a shallow copy.
- Returns:
A copy created via
dataclasses.replace
.- Return type:
- Parameters:
value (Array)
prior (Distribution | None)
fixed (bool)
scale (float)
name (str | None)
- class pmrf.parameters.ParameterGroup(param_names, prior=None)[source]
Bases:
object
A metadata class that groups a set of named flat parameters and defines any relationships between them.
Construct a
ParameterGroup
.- Parameters:
param_names (list[str] | dict[str, Parameter]) – The names of the flattened parameters (or a mapping to parameters).
prior (numpyro.distributions.Distribution, optional) – An optional prior over the flattened parameters.
- param_names: list[str]
- prior: Distribution | None = None
- property num_flat_params
Number of flattened parameters.
- Returns:
The count of names in
param_names
.- Return type:
int
- property min: array
The unscaled minimum value of the parameter group’s distribution (MIN_PERCENTILE quantile).
- Returns:
The minimum value, or -np.inf if no distribution is set.
- Return type:
jnp.array
- property max: array
The unscaled maximum value of the parameter’s distribution (MAX_PERCENTILE quantile).
- Returns:
The maximum value, or np.inf if no distribution is set.
- Return type:
jnp.array