leaspy.models.utils.attributes.logistic_ordinal_attributes module
- class LogisticOrdinalAttributes(name, dimension, source_dimension, ordinal_infos)
Bases:
LogisticAttributes
Attributes of leaspy logistic models with ordinal noise model.
Contains the common attributes & methods to update the logistic ordinal model’s attributes.
- Parameters:
- namestr
- dimensionint
- source_dimensionint
- ordinal_infosdict[str, Any]
Dictionary containing the required informations for all the ordinal levels of each item
See also
UnivariateModel
MultivariateModel
- Attributes:
- namestr (default ‘logistic’)
Name of the associated leaspy model.
- dimensionint
- source_dimensionint
- univariatebool
Whether model is univariate or not (i.e. dimension == 1)
- has_sourcesbool
Whether model has sources or not (not univariate and source_dimension >= 1)
- update_possibilitiesset[str] (default {‘all’, ‘g’, ‘v0’, ‘betas’} )
Contains the available parameters to update. Different models have different parameters.
- max_level: int
Maximum level of ordinal features
- batch_deltasbool
True if samplers for deltas are batched or False if deltas are sampled separately. If True attribute deltas is a Tensor. Otherwise deltas are a dictionary associating names of features to the Tensor of corresponding deltas.
- positions
torch.Tensor
[dimension] (default None) positions = exp(realizations[‘g’]) such that “p0” = 1 / (1 + positions)
- velocities
torch.Tensor
[dimension] (default None) Always positive: exp(realizations[‘v0’])
- deltasUnion[
torch.Tensor
[dimension, max_level], dict[str,torch.Tensor
]] (default None) Always positive: exp(realizations[‘deltas’])
- orthonormal_basis
torch.Tensor
[dimension, dimension - 1] (default None) - betas
torch.Tensor
[dimension - 1, source_dimension] (default None) - mixing_matrix
torch.Tensor
[dimension, source_dimension] (default None) Matrix A such that w_i = A * s_i.
Methods
Returns the attributes of the model, which is a tuple of three torch tensors.
Returns the deltas attributes stacked in one tensor
move_to_device
(device)Move the tensor attributes of this class to the specified device.
update
(names_of_changed_values, values)Update model group average parameter(s).
- get_attributes() Tuple[FloatTensor, FloatTensor, FloatTensor]
Returns the attributes of the model, which is a tuple of three torch tensors.
For the precise definitions of those attributes please refer to the exact attributes class associated to your model.
- Returns:
- positions: torch.Tensor
- velocities: torch.Tensor
- mixing_matrix: torch.Tensor
- get_deltas()
Returns the deltas attributes stacked in one tensor
- There are max_level - 1 = nb_levels - 2 “true” deltas since:
we only model nb_levels - 1 curves, not P(X >= 0) since it’s constant = 1
the first curve P(X >= 1) is the anchor (“delta = 0”) for it
In the returned tensor, we prepend the delta=0 for all features (for the anchor curve). For the impossible levels, delta=+inf, so that survival function is always 0
- Returns:
- The deltas concatenated in a big tensor: shape (dimension, max_level)
- move_to_device(device: device)
Move the tensor attributes of this class to the specified device.
- Parameters:
- devicetorch.device
- update(names_of_changed_values: set, values: dict)
Update model group average parameter(s).
- Parameters:
- names_of_changed_valuesset[str]
- Elements of set must be either:
all
(update everything)g
correspond to the attributepositions
.v0
(only for multivariate models) correspond to the attributevelocities
. When we are sure that the v0 change is only a scalar multiplication (in particular, when we reparametrize log(v0) <- log(v0) + mean(xi)), we may update velocities usingv0_collinear
, otherwise we always assume v0 is NOT collinear to previous value (no need to perform the verification it is - would not be really efficient)betas
correspond to the linear combination of columns from the orthonormal basis so to derive themixing_matrix
.deltas
correspond to the attribute :attr: deltas.
- valuesdict [str, torch.Tensor]
New values used to update the model’s group average parameters
- Raises:
LeaspyModelInputError
If names_of_changed_values contains unknown parameters.