leaspy.models.utils.ordinal module

class OrdinalModelMixin

Bases: object

Mix-in to add some useful properties & methods for models supporting the ordinal and ranking noise (univariate or multivariate).

Attributes
is_ordinal

Property to check if the model is of ordinal sub-type.

Methods

compute_ordinal_pdf_from_ordinal_sf(...[, ...])

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).

compute_ordinal_sf_from_ordinal_pdf(ordinal_pdf)

Compute the ordinal survival function values [P(X > l), i.e. P(X >= l+1), l=0..L-1] (l=0..L-1) from the ordinal probability density [P(X = l), l=0..L] (assuming ordinal levels are in last dimension).

postprocess_model_estimation(estimation, *)

Extra layer of processing used to output nice estimated values in main API Leaspy.estimate.

compute_ordinal_pdf_from_ordinal_sf(ordinal_sf: Tensor, *, dim_ordinal_levels: int = 3) Tensor

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)

static compute_ordinal_sf_from_ordinal_pdf(ordinal_pdf: Union[Tensor, ndarray])

Compute the ordinal survival function values [P(X > l), i.e. P(X >= l+1), l=0..L-1] (l=0..L-1) from the ordinal probability density [P(X = l), l=0..L] (assuming ordinal levels are in last dimension).

property is_ordinal: bool

Property to check if the model is of ordinal sub-type.

postprocess_model_estimation(estimation: ndarray, *, ordinal_method: str = 'MLE', **kws) Union[ndarray, Dict[Hashable, ndarray]]

Extra layer of processing used to output nice estimated values in main API Leaspy.estimate.

Parameters
estimationnumpy.ndarray[float]

The raw estimated values by model (from compute_individual_trajectory)

ordinal_methodstr

<!> Only used for ordinal models. * ‘MLE’ or ‘maximum_likelihood’ returns maximum likelihood estimator for each point (int) * ‘E’ or ‘expectation’ returns expectation (float) * ‘P’ or ‘probabilities’ returns probabilities of all-possible levels for a given feature:

{feature_name: array[float]<0..max_level_ft>}

**kws

Some extra keywords arguments that may be handled in the future.

Returns
numpy.ndarray[float] or dict[str, numpy.ndarray[float]]

Post-processed values. In case using ‘probabilities’ mode, the values are a dictionary with keys being: (feature_name: str, feature_level: int<0..max_level_for_feature>) Otherwise it is a standard numpy.ndarray corresponding to different model features (in order)