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 from a discrete probability density. |
|
Compute the probability density of an ordinal model from its survival function. |
Module Contents¶
- discrete_sf_from_pdf(pdf)[source]¶
Compute the discrete survival function values from a discrete probability density.
For a discrete variable with levels
l=0..Lthe survival function is \(P(X>l)=P(X\ge l+1)\) forl=0..L-1. This function assumes the last dimension ofpdfindexes the discrete levels.- Parameters:
- pdf
torch.Tensorornp.ndarray The discrete probability density.
- pdf
- Returns:
np.ndarrayThe discrete survival function values.
- Parameters:
- Return type:
- compute_ordinal_pdf_from_ordinal_sf(ordinal_sf, dim_ordinal_levels=3)[source]¶
Compute the probability density of an ordinal model from its survival function.
Given the survival function probabilities \(P(X>l)=P(X\ge l+1)\) for
l=0..L-1, compute \(P(X=l)\) forl=0..L.- Parameters:
- ordinal_sf
torch.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.
- ordinal_sf
- Returns:
- ordinal_pdf
torch.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)
- ordinal_pdf
- Parameters:
- Return type:
- class MultinomialDistribution(probs, **kwargs)[source]¶
Bases:
torch.distributions.MultinomialClass for a multinomial distribution with only one sample based on the Multinomial torch distrib.
- Parameters:
- probs
torch.Tensor The pdf of the multinomial distribution.
- probs
- 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)[source]¶
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)[source]¶
Bases:
torch.distributions.DistributionClass for a multinomial distribution with only sample method.
- Parameters:
- sf
torch.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).
- sf
- Attributes:
- cdf
torch.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_constraints
dict Contains the constraints on the arguments.
- cdf
- 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)[source]¶
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()[source]¶
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.TensorVector of integer values corresponding to the multinomial sampling. Result is in [[0, L]]
- Return type: