leaspy.models.mixture¶
Classes¶
A time-reparametrized model tailored to handle mixture models with multiple clusters. |
|
A riemannian manifold model tailored to handle mixture models with multiple clusters. |
|
Mixture Manifold model for multiple variables of interest (logistic formulation). |
Module Contents¶
- class TimeReparametrizedMixtureModel(name, **kwargs)[source]¶
Bases:
leaspy.models.mcmc_saem_compatible.McmcSaemCompatibleModelA time-reparametrized model tailored to handle mixture models with multiple clusters.
This class extends TimeReparametrizedModel to incorporate mixture-specific behaviors, including support for multiple clusters (n_clusters) and corresponding vectorized parameters.
- Parameters:
- name
str Name of the model.
- source_dimensionOptional[
int] Number of sources. Dimension of spatial components (default is None).
- **kwargs: :obj:`dict`
- Additional hyperparameters for the model. Must include:
- ‘n_clusters’: int
Number of mixture components (must be ≥ 2).
- ‘dimension’ or ‘features’: int or list
Dimensionality of the input data.
- ‘obs_models’: str, list, or dict (optional)
Specification of the observation model(s). Defaults to “gaussian-diagonal”.
- name
- Raises:
LeaspyModelInputErrorIf inconsistent hyperparameters.
- Parameters:
name (str)
- property sources_std: Tensor¶
Return the standard deviation of the sources as a tensor.
- Return type:
- get_variables_specs()[source]¶
Return the specifications of the variables (latent variables, derived variables, model ‘parameters’) that are part of the model.
- Returns:
NamedVariablesA dictionary-like object containing specifications for the variables
- Return type:
- static time_reparametrization(*, t, alpha, tau)[source]¶
Tensorized time reparametrization formula.
Warning
Shapes of tensors must be compatible between them.
- Parameters:
- t
torch.Tensor Timepoints to reparametrize
- alpha
torch.Tensor Acceleration factors of individual(s)
- tau
torch.Tensor Time-shift(s) of individual(s)
- t
- Returns:
torch.TensorReparametrized time of same shape as timepoints
- Parameters:
- Return type:
- put_individual_parameters(state, dataset)[source]¶
Initialize individual latent parameters in the given state if not already set.
- to_dict(*, with_mixing_matrix=True)[source]¶
Export model object as dictionary ready for JSON saving.
- Parameters:
- with_mixing_matrix
bool(defaultTrue) Save the mixing matrix in the exported file in its ‘parameters’ section.
Warning
It is not a real parameter and its value will be overwritten at model loading (orthonormal basis is recomputed from other “true” parameters and mixing matrix is then deduced from this orthonormal basis and the betas)! It was integrated historically because it is used for convenience in browser webtool and only there…
- with_mixing_matrix
- Returns:
KwargsTypeThe object as a dictionary.
- Parameters:
with_mixing_matrix (bool)
- Return type:
- class RiemanianManifoldMixtureModel(name, variables_to_track=None, **kwargs)[source]¶
Bases:
TimeReparametrizedMixtureModelA riemannian manifold model tailored to handle mixture models with multiple clusters.
This class extends RiemanianManifoldModel to incorporate mixture-specific behaviors, mainly the handling of sources for multiple clusters.
- Parameters:
- name
str The name of the model.
- **kwargs
Hyperparameters of the model (including noise_model)
- name
- Raises:
LeaspyModelInputErrorIf hyperparameters are inconsistent
- Parameters:
- tracked_variables¶
- tracked_variables_ordered = ['g', 'v0', 'noise_std', 'tau_mean', 'tau_std', 'xi_mean', 'xi_std', 'nll_attach',...¶
- classmethod compute_sufficient_statistics(state)[source]¶
Compute the model’s sufficient statistics.
- get_variables_specs()[source]¶
Return the specifications of the variables (latent variables, derived variables, model ‘parameters’) that are part of the model.
- Returns:
NamedVariablesA dictionary-like object mapping variable names to their specifications. These include ModelParameter, Hyperparameter, PopulationLatentVariable, and LinkedVariable instances.
- Return type:
- classmethod model_no_sources(*, rt, metric, v0, g)[source]¶
Return the model output when sources(spatial components) are not present.
- Parameters:
- rt
torch.Tensor The reparametrized time.
- metricAny
The metric tensor used for computing the spatial/temporal influence.
- v0Any
The values of the population parameter v0 for each feature.
- gAny
The values of the population parameter g for each feature.
- rt
- Returns:
torch.TensorThe model output without contribution from source shifts.
- Parameters:
rt (Tensor)
- Return type:
Notes
This implementation delegates to model_with_sources with space_shifts set to a zero tensor of shape (1, 1), effectively removing source effects.
- class LogisticMultivariateMixtureModel(name, **kwargs)[source]¶
Bases:
LogisticMixtureInitializationMixin,RiemanianManifoldMixtureModelMixture Manifold model for multiple variables of interest (logistic formulation).
- Parameters:
name (str)
- get_variables_specs()[source]¶
Return the specifications of the variables (latent variables, derived variables, model ‘parameters’) that are part of the model.
- Returns:
NamedVariablesA dictionary-like object mapping variable names to their specifications. These include ModelParameter, Hyperparameter, PopulationLatentVariable, and LinkedVariable instances.
- Return type:
- static metric(*, g)[source]¶
Compute the metric tensor from input tensor g. This function calculates the metric as ((g + 1)^2 / g) element-wise.
- Parameters:
- gt
torch.Tensor Input tensor with values of the population parameter g for each feature.
- gt
- Returns:
torch.TensorThe computed metric tensor, same shape as g(number of features)
- Parameters:
g (Tensor)
- Return type:
- classmethod model_with_sources(*, rt, space_shifts, metric, v0, g)[source]¶
Return the model output when sources(spatial components) are present.
- Parameters:
- rt
TensorOrWeightedTensor`[:obj:`float] Tensor containing the reparametrized time.
- space_shifts~leaspy.uitls.weighted_tensor._weighted_tensor.TensorOrWeightedTensor`[:obj:`float]
Tensor containing the values of the space-shifts
- metric :`~leaspy.uitls.weighted_tensor._weighted_tensor.TensorOrWeightedTensor`[:obj:`float`]
Tensor containing the metric tensor used for computing the spatial/temporal influence.
- v0~leaspy.uitls.weighted_tensor._weighted_tensor.TensorOrWeightedTensor`[:obj:`float]
Tensor containing the values of the population parameter v0 for each feature.
- g~leaspy.uitls.weighted_tensor._weighted_tensor.TensorOrWeightedTensor`[:obj:`float]
Tensor containing the values of the population parameter g for each feature.
- rt
- Returns:
torch.TensorWeighted value tensor after applying sigmoid transformation, representing the model output with sources.
- Parameters:
rt (TensorOrWeightedTensor[float])
space_shifts (TensorOrWeightedTensor[float])
metric (TensorOrWeightedTensor[float])
v0 (TensorOrWeightedTensor[float])
- Return type: