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.
is_ordinal_ranking
Property to check if the model is of ordinal-ranking sub-type (working with survival functions).
ordinal_infos
Property to return the ordinal info dictionary.
Methods
Check compatibility between the model instance and provided noise model.
Post-process model values (or their gradient) if needed.
Compute the sufficient statistics given realizations.
compute_ordinal_pdf_from_ordinal_sf
(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).
get_additional_ordinal_population_random_variable_information
()Return the information of additional population random variables for the ordinal model.
get_ordinal_parameters_updates_from_sufficient_statistics
(...)Return a dictionary computed from provided sufficient statistics for updating the parameters.
postprocess_model_estimation
(estimation, *)Extra layer of processing used to output nice estimated values in main API Leaspy.estimate.
Update (in-place) the provided variable information dictionary.
- check_noise_model_compatibility(model: BaseNoiseModel) None
Check compatibility between the model instance and provided noise model.
- compute_appropriate_ordinal_model(model_or_model_grad: Tensor) Tensor
Post-process model values (or their gradient) if needed.
- compute_ordinal_model_sufficient_statistics(realizations: CollectionRealization) Dict[str, Tensor]
Compute the sufficient statistics given realizations.
- static 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)
- get_additional_ordinal_population_random_variable_information() Dict[str, Any]
Return the information of additional population random variables for the ordinal model.
- get_ordinal_parameters_updates_from_sufficient_statistics(sufficient_statistics: Dict[str, Tensor]) Dict[str, Tensor]
Return a dictionary computed from provided sufficient statistics for updating the parameters.
- property is_ordinal_ranking: bool
Property to check if the model is of ordinal-ranking sub-type (working with survival functions).
- postprocess_model_estimation(estimation: ndarray, *, ordinal_method: str = 'MLE', **kws) 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)
- update_ordinal_population_random_variable_information(variables_info: Dict[str, Any]) None
Update (in-place) the provided variable information dictionary.
Nota: this is needed due to different signification of v0 in ordinal model (common per-level velocity)
- Parameters:
- variables_infoDictParams
The variables information to be updated with ordinal logic.