Parameter (pmrf.Parameter)
- class pmrf.parameters.Parameter(value, distribution=None, fixed=False, scale=1.0, name=None)[source]
Bases:
ModuleOverview
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 distribution, 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 # 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
- distribution: 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
valuereplaced.- Return type:
- with_distribution(dist)[source]
Return a copy with a new distribution.
- Parameters:
dist (numpyro.distributions.Distribution) – The distribution to associate with this parameter.
- Returns:
A copy of this object with
distributionreplaced.- Return type:
- flatten(separator='_')[source]
Flattens self, either returning a single Parameter if the internal parameter is scalar, or a list. If the internal distribution 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)
distribution (Distribution | None)
fixed (bool)
scale (float)
name (str | None)
- class pmrf.parameters.ParameterGroup(param_names, dist=None)[source]
Bases:
objectA 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).
dist (numpyro.distributions.Distribution, optional) – An optional joint distribution over the flattened parameters.
- parameter_names: list[str]
- distribution: 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