leaspy.models.noise_models
.GaussianDiagonalNoiseModel
- class GaussianDiagonalNoiseModel(parameters: Dict[str, Tensor] | None = None, scale_dimension: int | None = None)
Bases:
AbstractGaussianNoiseModel
Class implementing diagonal Gaussian noise models.
- Parameters:
- parameters
dict
[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.
- scale_dimension
int
, optional The scale dimension.
- parameters
- Attributes:
Methods
compute_canonical_loss
(data, predictions)Compute a human-friendly overall loss (RMSE).
compute_l2_residuals
(data, predictions)Compute the squared residuals of the given predictions.
compute_nll
(data, predictions, *[, ...])Negative log-likelihood without summation (and its gradient w.r.t.
compute_residuals
(data, predictions)Compute the residuals of the given predictions.
compute_rmse
(data, predictions)Computes root mean squared error of provided data vs.
compute_sufficient_statistics
(data, predictions)Compute the specific sufficient statistics and metrics for this noise-model.
alias of
Normal
move_to_device
(device)Move all torch tensors stored in this instance to the provided device (parameters & hyperparameters).
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.
update_parameters_from_predictions
(data, ...)In-place update of free parameters from provided predictions.
In-place update of free parameters from provided sufficient statistics.
validate
(**params)Validation function for parameters (based on 'validate_xxx' methods).
validate_scale
(scale)Ensure the scale is valid.
- classmethod compute_canonical_loss(data: Dataset, predictions: Tensor) Tensor
Compute a human-friendly overall loss (RMSE).
- Parameters:
- data
Dataset
The dataset related to the computation of the log likelihood.
- predictions
torch.Tensor
The model’s predictions from which to compute the canonical loss.
- data
- Returns:
torch.Tensor
The computed loss.
- classmethod compute_l2_residuals(data: Dataset, predictions: Tensor) Tensor
Compute the squared residuals of the given predictions.
- Parameters:
- data
Dataset
The dataset related to the computation of the squared residuals.
- predictions
torch.Tensor
The model’s predictions from which to compute the squared residuals.
- data
- Returns:
torch.Tensor
The squared residuals.
- compute_nll(data: Dataset, predictions: Tensor, *, with_gradient: bool = False) Tensor | Tuple[Tensor, Tensor]
Negative log-likelihood without summation (and its gradient w.r.t. predictions if requested).
- Parameters:
- data
Dataset
The dataset related to the computation of the log likelihood.
- predictions
torch.Tensor
The model’s predictions from which to compute the log likelihood.
- with_gradient
bool
, optional If True, returns also the gradient of the negative log likelihood wrt the predictions. If False, only returns the negative log likelihood. Default=False.
- data
- Returns:
torch.Tensor
ortuple
oftorch.Tensor
The negative log likelihood (and its jacobian if requested).
- static compute_residuals(data: Dataset, predictions: Tensor) Tensor
Compute the residuals of the given predictions.
- Parameters:
- data
Dataset
The dataset related to the computation of the residuals.
- predictions
torch.Tensor
The model’s predictions from which to compute the residuals.
- data
- Returns:
torch.Tensor
The residuals.
- classmethod compute_rmse(data: Dataset, predictions: Tensor) Tensor
Computes root mean squared error of provided data vs. predictions.
- Parameters:
- data
Dataset
The dataset related to the computation of the root mean squared error.
- predictions
torch.Tensor
The model’s predictions from which to compute the root mean squared error.
- data
- Returns:
torch.Tensor
The root mean squared error.
- compute_sufficient_statistics(data: Dataset, predictions: Tensor) Dict[str, Tensor]
Compute the specific sufficient statistics and metrics for this noise-model.
- Parameters:
- data
Dataset
The dataset related to the computation of the sufficient statistics.
- predictions
torch.Tensor
The model’s predictions from which to compute the sufficient statistics.
- data
- Returns:
- DictParamsTorch
The sufficient statistics.
- move_to_device(device: device) None
Move all torch tensors stored in this instance to the provided device (parameters & hyperparameters).
- Parameters:
- device
torch.device
Torch device on which to move the tensors.
- device
- 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:
- loc
torch.Tensor
The loc around which to sample.
- loc
- 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:
- loc
torch.Tensor
The loc around which to sample.
- loc
- Returns:
torch.Tensor
The requested sample.
- sampler_around(loc: Tensor) Callable[[], Tensor]
Return the sampling function around input values.
- Parameters:
- loc
torch.Tensor
The loc around which to sample.
- loc
- 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:
- validate
bool
, optional If True, the provided parameters are validated before being updated. Default=False.
- **parameters
torch.Tensor
The new parameters.
- validate
- update_parameters_from_predictions(data: Dataset, predictions: Tensor) None
In-place update of free parameters from provided predictions.
- Parameters:
- data
Dataset
The dataset related to the computation of the log likelihood.
- predictions
torch.Tensor
The model’s predictions from which to update the parameters.
- data
- update_parameters_from_sufficient_statistics(data: Dataset, sufficient_statistics: Dict[str, Tensor]) None
In-place update of free parameters from provided sufficient statistics.
- Parameters:
- data
Dataset
The dataset related to the computation of the log likelihood.
- sufficient_statisticsDictParamsTorch
The sufficient statistics to use for parameter update.
- data
- 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.
- validate_scale(scale: Tensor) Tensor
Ensure the scale is valid.
- Parameters:
- scale
torch.Tensor
The scale to validate.
- scale
- Returns:
torch.Tensor
The validated scale.