param (pmrf.param)
- pmrf.param(*, default: Any = <dataclasses._MISSING_TYPE object>, as_free: bool = False, as_fixed: bool = False, constraint: AbstractConstraint | None = None, scale: float = 1.0, **kwargs) Any
A field specifier for registering parameters within a model.
This specifier can be used when declaring custom models inheriting from pmrf.Model.
It is used to register the parameter when a model is constructed, so it is listed under
pmrf.Model.named_params(). It can also be used to enforce constraints, scaling, bounds and variability within the model itself.This simply creates a pmrf.field with a pmrf.as_param converter.
Example
Declaring a parameter with a positive constraint and built-in scale:
import pmrf as prf from pmrf.models import Resistor, Capacitor from pmrf.constraints import Positive class RC(prf.Model): R: prf.Param = prf.param(constraint=Positive()) C: prf.Param = prf.param(constraint=Positive(), scale=1e-12) def build(self) -> prf.Model: return Resistor(self.R) ** Capacitor(self.C) RC(1.0, 2.0) # RC(R=1., C=2.e-12) RC(-1.0, 2.0) # ValueError: out of bounds
- Parameters:
default (Any, optional) – The default value of the parameter.
constraint (Optional[AbstractConstraint], optional) – The constraint to apply to the parameter. See
pmrf.constraints.scale (float, optional) – The scaling factor to apply, by default 1.0.
as_free (bool, optional) – Whether to enforce that the value is a variable parameter. If False, incoming values will keep the variability (e.g. constants will remain constants). If True, all values will be co-erced into variable parameters.
as_fixed (bool, optional) – Whether to enforce that the value is a fixed parameter. If False, incoming values will keep the variability (e.g. constants will remain constants). If True, all values will be wrapped in
pmrf.Fixed().**kwargs – Additional key-word arguments to pass to the general
pmrf.field()specifier.
- Returns:
An equinox field with a built-in converter for parameter rules.
- Return type:
Any