pmrf.sampling.BaseSampler

class pmrf.sampling.BaseSampler(model)[source]

Bases: ABC, Generic[ModelT]

Abstract base class for parameter sampling engines.

This class provides the infrastructure to generate random variations of a pmrf.Model based on the prior distributions of its parameters. It supports generating batches of models, batches of features (e.g., S-parameters), or iterating over generated models.

Subclasses must implement _generate_hypercube_samples to define the sampling strategy (e.g., Monte Carlo, Latin Hypercube).

Parameters:

model (ModelT)

model

The base model defining the parameter structure and priors.

Type:

Model

N

The number of samples for the current iteration context.

Type:

int or None

logger

Logger instance.

Type:

logging.Logger

__init__(model)[source]

Initialize the sampler.

Parameters:

model (Model) – The model to sample from.

Methods

__class_getitem__(params)

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__gt__(value, /)

Return self>value.

__hash__()

Return hash(self).

__init__(model)

Initialize the sampler.

__init_subclass__(*args, **kwargs)

This method is called when a class is subclassed.

__iter__()

Iterate over generated models.

__le__(value, /)

Return self<=value.

__len__()

Return the number of samples in the current iteration context.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(**kwargs)

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

_generate_hypercube_samples(N, D)

Generate samples in the unit hypercube [0, 1]^D.

_generate_params(N)

Internal method to generate parameter values in physical space.

generate_features(N, features, frequency[, ...])

Generate feature vectors for N random samples.

generate_models(N)

Generate N random model instances using the sampler's engine.

range(N)

Configure the sampler for iteration over N samples.

Attributes

__abstractmethods__

__annotations__

__dict__

__doc__

__module__

__orig_bases__

__parameters__

__slots__

__weakref__

list of weak references to the object (if defined)

_abc_impl

_is_protocol

__init__(model)[source]

Initialize the sampler.

Parameters:

model (Model) – The model to sample from.

range(N)[source]

Configure the sampler for iteration over N samples.

Allows the Sampler to be used as an iterable.

Examples

>>> for i, system in enumerate(sampler.range(10)):
...     print(system)
Parameters:

N (int) – The number of samples to generate.

Returns:

Returns self to allow chaining into an iterator.

Return type:

BaseSampler

generate_models(N)[source]

Generate N random model instances using the sampler’s engine.

Parameters:

N (int) – The number of samples to generate.

Returns:

A list of model instances with parameters sampled from the prior.

Return type:

list[Model]

generate_features(N, features, frequency, dont_jit=False, **kwargs)[source]

Generate feature vectors for N random samples.

This method vectorizes the feature extraction process using JAX for efficiency.

Parameters:
  • N (int) – The number of samples to generate.

  • features (FeatureInputT) – The list or dictionary of features to extract (e.g., [‘s11_db’]).

  • frequency (Frequency or skrf.Frequency) – The frequency grid to evaluate the features on.

  • dont_jit (bool, optional, default=False) – If True, disables JIT compilation for the vectorized function.

  • **kwargs – Additional arguments passed to the feature extractor.

Returns:

The array of generated features with shape (N, n_features).

Return type:

jnp.array