Parameter (pmrf.Parameter)

class pmrf.parameters.Parameter(value, distribution=None, fixed=False, scale=1.0, name=None)[source]

Bases: Module

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, compatible with JAX transformations (jit, grad).

  • Mark as fixed (honoured by fitting and sampling routines).

  • Associate distributions, specified as numpyro distributions (uniform, normal, etc.).

value

The underlying unscaled value. Automatically converted to a float64 array.

Type:

jnp.ndarray

distribution

The prior distribution associated with this parameter.

Type:

numpyro.distributions.Distribution or None

fixed

If True, the parameter is treated as a constant during optimization/sampling.

Type:

bool

scale

A scaling factor. The effective value used in calculations is value * scale.

Type:

float

name

An optional name for the parameter (marked as static).

Type:

str or None

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.

Returns 0 if the parameter is fixed.

property min: array

The unscaled minimum value of the parameter’s distribution.

This is determined by the MIN_PERCENTILE quantile of the distribution.

Returns:

The minimum value, or -inf if no distribution is set.

Return type:

jnp.array

property max: array

The unscaled maximum value of the parameter’s distribution.

This is determined by the MAX_PERCENTILE quantile of the distribution.

Returns:

The maximum value, or inf if no distribution is set.

Return type:

jnp.array

with_value(value)[source]

Return a copy of the parameter 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:

Parameter

with_distribution(dist)[source]

Return a copy of the parameter with a new distribution.

Parameters:

dist (numpyro.distributions.Distribution) – The distribution to associate with this parameter.

Returns:

A copy of this object with distribution replaced.

Return type:

Parameter

Raises:

Exception – If dist is not a numpyro Distribution.

flattened(separator='_')[source]

Flatten self into a list of scalar Parameters.

If the internal parameter is scalar, the list will contain self. Otherwise, the parameter is split (de-vectorized) if possible.

Parameters:

separator (str, optional, default='_') – Separator used for naming split parameters (e.g., name_0, name_1).

Returns:

The list of individual parameters.

Return type:

list[Parameter]

Raises:

ValueError – If any internal distributions cannot be de-vectorized.

interpolated(x_old, x_new)[source]

Return a new parameter interpolated to a new domain.

Interpolates both the value and the distribution parameters.

Parameters:
  • x_old (array_like) – The original domain coordinates.

  • x_new (array_like) – The new domain coordinates.

Returns:

The interpolated parameter.

Return type:

Parameter

as_fixed()[source]

Return a copy of self with fixed=True.

Returns:

The new, fixed parameter.

Return type:

Parameter

as_free()[source]

Return a copy of self with fixed=False.

Returns:

The new, free parameter.

Return type:

Parameter

copy()[source]

Return a shallow copy.

Returns:

A copy created via dataclasses.replace.

Return type:

Parameter

to_json()[source]

Serialize the parameter to a JSON string.

Returns:

A JSON-formatted string containing value, distribution, fixed, scale, and name.

Return type:

str

classmethod from_json(s)[source]

Deserialize a parameter from a JSON string.

Parameters:

s (str) – The JSON string produced by to_json().

Returns:

A reconstructed Parameter instance.

Return type:

Parameter

__init__(value, distribution=None, fixed=False, scale=1.0, name=None)
Parameters:
  • value (Any)

  • distribution (Distribution | None)

  • fixed (bool)

  • scale (float)

  • name (str | None)

Return type:

None

Parameters:
  • value (Array)

  • distribution (Distribution | None)

  • fixed (bool)

  • scale (float)

  • name (str | None)

class pmrf.parameters.ParameterGroup(param_names, dist=None)[source]

Bases: object

A metadata class that groups a set of named flat parameters and defines any relationships between them.

Parameters:
  • param_names (list[str] | dict[str, Parameter])

  • dist (Distribution | None)

parameter_names

The names of the parameters included in this group.

Type:

list[str]

distribution

An optional joint distribution over the flattened parameters.

Type:

dist.Distribution or None

__init__(param_names, dist=None)[source]

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 in the group.

Returns:

The count of names in parameter_names.

Return type:

int

property min: array

The unscaled minimum value of the parameter group’s distribution.

Determined by the MIN_PERCENTILE quantile.

Returns:

The minimum value, or -inf if no distribution is set.

Return type:

jnp.array

property max: array

The unscaled maximum value of the parameter group’s distribution.

Determined by the MAX_PERCENTILE quantile.

Returns:

The maximum value, or inf if no distribution is set.

Return type:

jnp.array