Param (pmrf.Param)
- class pmrf.Param(*, value: ArrayLike | None = None, distribution: AbstractDistribution | None = None, constraint: AbstractConstraint | None = None, name: str | None = None, scale: Any = None, fixed: bool = False, metadata: Any = None, variable: Any = None, validity: Any = None)
Bases:
AbstractVariable,AbstractAnnotated[Any]The canonical parameter container for ParamRF.
Parameters can be created by instantiating this class, or using factories in
pmrf.parameters, most of which are re-exported at root (e.g.pmrf.Unconstrained(),pmrf.Fixed(),pmrf.Bounded()).Wraps a Parax variable, applying an optional scale, name and metadata.
A parameter’s number lives in one of three spaces:
declared: the number as written, in the units the scale declares (
value). Construction, bounds and distributions are in declared space.physical: the declared value times the scale (
physical_value). Unwrapping and arithmetic use the physical value.raw: the latent array an optimiser or sampler moves through (
raw_value).
Examples
p = prf.Unconstrained(2.0, scale=1e-12) p.value # 2.0 p.physical_value # 2e-12
Creates a generic parameter.
The incoming value can be any ArrayLike object.
- Parameters:
value (ArrayLike, optional) – The declared value of the parameter.
distribution (Optional[AbstractDistribution], optional) – The probability distribution, in declared space. See
pmrf.stats.distributions.constraint (Optional[AbstractConstraint], optional) – The range, in declared space. See
pmrf.parameters.constraints. It is intersected with validity, and distribution is truncated to the result and renormalised.name (str, optional) – A name for the parameter, by default None.
scale (float, optional) – The units the value is written in. None, the default, acts as 1.0 and lets a field declared with
pmrf.param()apply its own scale.fixed (bool, optional) – Initializes the parameter as fixed. Defaults to False.
metadata (Any, optional) – Arbitrary metadata for the parameter, by default None.
variable (Optional[prx.AbstractVariable], optional) – The Parax variable to wrap. If value is also passed, the variable’s declared value is replaced, keeping its distribution, constraint, fixed state, and the dtype, shape and weak_type of its array, so the jit cache key is unchanged. This is what makes
pmrf.replace(param, value=...)work, sopmrf.replace(param, value=param.value)is the identity (up to the floating-point round trip through the constraint bijector).validity (Optional[AbstractConstraint], optional) – The constraint the parameter must always satisfy, in declared space. See
validity. With variable, it is recorded as given: the variable’s constraint must already lie inside it.
- Raises:
ValueError – If distribution reaches outside the constraint and cannot be truncated to it. Normal and Uniform distributions can be.
- __add__(*args)
- __floordiv__(*args)
- __getitem__(*args)
- __len__(*args)
- __mod__(*args)
- __mul__(*args)
- __rmul__(*args)
- __sub__(*args)
- __truediv__(*args)
- unwrap() Array
Unwraps the parameter to its value in physical space.
- Returns:
The physical value, as
physical_value.- Return type:
jax.Array
- property as_fixed
- property bijector: AbstractBijector | None
The full bijector mapping the raw value to the physical value.
Composes
raw_to_declared_bijectorwithdeclared_to_physical_bijector.- Returns:
The bijector if a constraint exists, otherwise None.
- Return type:
AbstractBijector | None
- property bounds: tuple[Array | ndarray | bool | number | bool | int | float | complex, Array | ndarray | bool | number | bool | int | float | complex] | None
The lower and upper bounds of the parameter, in declared space.
- Returns:
A tuple of (lower_bound, upper_bound) if bounds exist, otherwise None.
- Return type:
tuple[ArrayLike, ArrayLike] | None
- property constraint: AbstractConstraint | None
The constraint of the parameter, in declared space.
- Returns:
The constraint if one exists, otherwise None.
- Return type:
AbstractConstraint | None
- property declared_to_physical_bijector: AbstractBijector | None
The bijector mapping the declared value to the physical value.
This is multiplication by the scale. Distributions and bounds are in declared space, so this is the step needed to compare them against an unwrapped, physical value.
- Returns:
The bijector if the parameter is scaled, otherwise None.
- Return type:
AbstractBijector | None
- property distribution: AbstractDistribution | None
The probability distribution of the parameter, in declared space.
- Returns:
The distribution if one exists, otherwise None.
- Return type:
AbstractDistribution | None
- property fixed: bool
Indicates whether the parameter is fixed (constant).
- Returns:
True if the parameter is fixed, False otherwise.
- Return type:
bool
- metadata: Any = None
Arbitrary metadata to store alongside the parameter.
- name: str | None = None
A name for the parameter.
- property physical_value: Array
the declared value times the scale.
This is what
pmrf.unwrap()and arithmetic on the parameter use.- Returns:
The physical value.
- Return type:
jax.Array
- Type:
The value in physical space
- property raw_leaf: Array | None
Returns this parameter’s single remaining raw/whitened array leaf, without relying on the internal structure of the wrapped Parax variable (e.g. Random, Fixed). Intended for use after masking or partitioning has already reduced this parameter’s own metadata (its distribution, constraint, etc.) to None, leaving only its own raw value behind.
- Returns:
The one remaining leaf, or None if none remain (e.g. this parameter was masked out entirely).
- Return type:
jax.Array | None
- Raises:
ValueError – If more than one leaf remains, e.g. called before masking.
- property raw_to_declared_bijector: AbstractBijector | None
The bijector mapping the raw value to the declared value.
Raw space is what Parax calls unconstrained space. ParamRF calls it raw to avoid confusion with
pmrf.Unconstrained(), which creates a parameter without bounds.- Returns:
The bijector if a constraint exists, otherwise None.
- Return type:
AbstractBijector | None
- property raw_value: Array
the latent array an optimiser or sampler moves through.
- Returns:
The raw array.
- Return type:
jax.Array
- Type:
The value in raw space
- scale: float | None = None
physical = declared × scale. None means not set, which acts as 1.0 and lets a field’s scale apply.
- Type:
The units the declared value is written in
- validity: AbstractConstraint | None = None
that of the model field it was passed to (see
pmrf.param()), or None. Its bounds combine it with the range the user gave, which a prior in declared or physical space replaces (seepmrf.prior()). It is stored frozen, as a Parax variable stores its constraint, so it stays out of gradients and partitioning: read it throughparax.unwrap.- Type:
The constraint the parameter must always satisfy, in declared space
- property value: Array
the number as written, in the parameter’s units.
- Returns:
The declared value.
- Return type:
jax.Array
- Type:
The value in declared space
- variable: AbstractVariable
The Parax variable holding the declared value, constraint and distribution.