leaspy.utils.distributions
Module defining useful distribution for ordinal noise model.
Classes
Class for a multinomial distribution with only one sample based on the Multinomial torch distrib. |
|
Class for a multinomial distribution with only sample method. |
Functions
|
Compute the discrete survival function values [P(X > l), i.e. |
|
Computes the probability density (or its jacobian) of an ordinal |
Module Contents
- discrete_sf_from_pdf(pdf)
Compute the discrete survival function values [P(X > l), i.e. P(X >= l+1), l=0..L-1] (l=0..L-1) from the discrete probability density [P(X = l), l=0..L] (assuming discrete levels are in last dimension).
- compute_ordinal_pdf_from_ordinal_sf(ordinal_sf, dim_ordinal_levels=3)
Computes the probability density (or its jacobian) of an ordinal model [P(X = l), l=0..L] from ordinal_sf which are the survival function probabilities [P(X > l), i.e. P(X >= l+1), l=0..L-1] (or its jacobian).
- Parameters:
- ordinal_sftorch.FloatTensor
Survival function values : ordinal_sf[…, l] is the proba to be superior or equal to l+1 Dimensions are: * 0=individual * 1=visit * 2=feature * 3=ordinal_level [l=0..L-1] * [4=individual_parameter_dim_when_gradient]
- dim_ordinal_levelsint, default = 3
The dimension of the tensor where the ordinal levels are.
- Returns:
- ordinal_pdftorch.FloatTensor (same shape as input, except for dimension 3 which has one more element)
ordinal_pdf[…, l] is the proba to be equal to l (l=0..L)
- Parameters:
- Return type:
- class MultinomialDistribution(probs, **kwargs)
Bases:
torch.distributions.MultinomialClass for a multinomial distribution with only one sample based on the Multinomial torch distrib.
- Parameters:
- probstorch.Tensor
The pdf of the multinomial distribution.
- Attributes:
- arg_constraints: ClassVar
Returns a dictionary from argument names to
Constraintobjects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
- classmethod from_sf(sf, **kws)
Generate a new MultinomialDistribution from its survival function instead of its probability density function.
- Parameters:
- pdf
torch.Tensor The input probability density function.
- **kws
Additional keyword arguments to be passed for instance initialization.
- pdf
- Parameters:
sf (Tensor)
- class MultinomialCdfDistribution(sf, *, validate_args=True)
Bases:
torch.distributions.DistributionClass for a multinomial distribution with only sample method.
- Parameters:
- sftorch.Tensor
Values of the survival function [P(X > l) for l=0..L-1 where L is max_level] from which the distribution samples. Ordinal levels are assumed to be in the last dimension. Those values must be in [0, 1], and decreasing when ordinal level increases (not checked).
- validate_argsbool, optional (default True)
Whether to validate the arguments or not (None for default behavior, which changed after torch >= 1.8 to True).
- Attributes:
- cdftorch.Tensor
The cumulative distribution function [P(X <= l) for l=0..L] from which the distribution samples. The shape of latest dimension is L+1 where L is max_level. We always have P(X <= L) = 1
- arg_constraintsdict
Contains the constraints on the arguments.
- Parameters:
- arg_constraints: ClassVar
Returns a dictionary from argument names to
Constraintobjects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
- cdf
Returns the cumulative density/mass function evaluated at value.
- Args:
value (Tensor):
- classmethod from_pdf(pdf, **kws)
Generate a new MultinomialDistribution from its probability density function instead of its survival function.
- Parameters:
- pdf
torch.Tensor The input probability density function.
- **kws
Additional keyword arguments to be passed for instance initialization.
- pdf
- Parameters:
pdf (Tensor)
- sample()
Multinomial sampling.
We sample uniformly on [0, 1( but for the latest dimension corresponding to ordinal levels this latest dimension will be broadcast when comparing with cdf.
- Returns:
- torch.Tensor
Vector of integer values corresponding to the multinomial sampling. Result is in [[0, L]]
- Return type: