leaspy.models.noise_models.DistributionFamily

class DistributionFamily(parameters: Dict[str, Tensor] | None = None)

Bases: object

Base class for a distribution family being able to sample “around” user-provided values.

Parameters:
parametersdict [ str, torch.Tensor ] or None

Values for all the free parameters of the distribution family. All of them must have values before using the sampling methods.

Attributes:
free_parametersfrozenset of str

Name of all the free parameters (but loc) needed to characterize the distribution. Nota: for each parameter, if a method named “validate_xxx” exists (torch.Tensor -> torch.Tensor), then it will be used for user-input validation of parameter “xxx”.

factoryNone or function(free parameters values) -> torch.distributions.distribution.Distribution

The factory for the distribution family.

parametersdict [ str, torch.Tensor ] or None

Values for all the free parameters of the distribution family. All of them must have values before using the sampling methods.

Methods

move_to_device(device)

Move all torch tensors stored in this instance to the provided device (parameters & hyperparameters).

raise_if_partially_defined()

Raise an error if some of the free parameters are not defined.

raise_if_unknown_parameters(params)

Raise an error if the provided parameters are not part of the free parameters.

rv_around(loc)

Return the torch distribution centred around values (only if noise is not None).

sample_around(loc)

Realization around loc with respect to partially defined distribution.

sampler_around(loc)

Return the sampling function around input values.

to_dict()

Serialize instance as dictionary.

update_parameters(*[, validate])

(Partial) update of the free parameters of the distribution family.

validate(**params)

Validation function for parameters (based on 'validate_xxx' methods).

move_to_device(device: device) None

Move all torch tensors stored in this instance to the provided device (parameters & hyperparameters).

Parameters:
devicetorch.device

Torch device on which to move the tensors.

raise_if_partially_defined() None

Raise an error if some of the free parameters are not defined.

classmethod raise_if_unknown_parameters(params: Iterable | None) None

Raise an error if the provided parameters are not part of the free parameters.

Parameters:
paramsIterable, optional

The list of parameters to analyze.

rv_around(loc: Tensor) Distribution

Return the torch distribution centred around values (only if noise is not None).

Parameters:
loctorch.Tensor

The loc around which to sample.

Returns:
torch.distributions.distribution.Distribution

The torch distribution centered around the loc.

sample_around(loc: Tensor) Tensor

Realization around loc with respect to partially defined distribution.

Parameters:
loctorch.Tensor

The loc around which to sample.

Returns:
torch.Tensor

The requested sample.

sampler_around(loc: Tensor) Callable[[], Tensor]

Return the sampling function around input values.

Parameters:
loctorch.Tensor

The loc around which to sample.

Returns:
Callable

The sampler.

to_dict() Dict[str, Any]

Serialize instance as dictionary.

Returns:
KwargsType

The instance serialized as a dictionary.

update_parameters(*, validate: bool = False, **parameters: Tensor) None

(Partial) update of the free parameters of the distribution family.

Parameters:
validatebool, optional

If True, the provided parameters are validated before being updated. Default=False.

**parameterstorch.Tensor

The new parameters.

validate(**params: Any) Dict[str, Tensor]

Validation function for parameters (based on ‘validate_xxx’ methods).

Parameters:
**paramsAny

The parameters to validate.

Returns:
DictParamsTorch

The validated parameters.