leaspy.models.time_reparametrized

Classes

TimeReparametrizedModel

Contains the common attributes & methods of the multivariate time-reparametrized models.

Module Contents

class TimeReparametrizedModel(name, source_dimension=None, **kwargs)[source]

Bases: leaspy.models.mcmc_saem_compatible.McmcSaemCompatibleModel

Contains the common attributes & methods of the multivariate time-reparametrized models.

Parameters:
namestr

Name of the model.

source_dimensionOptional[int]

Number of sources. Dimension of spatial components (default is None).

**kwargs

Hyperparameters for the model (including obs_models).

Raises:
LeaspyModelInputError

If inconsistent hyperparameters.

Parameters:
  • name (str)

  • source_dimension (Optional[int])

property xi_std: Tensor

Return the standard deviation of xi as a tensor.

Return type:

Tensor

property tau_std: Tensor

Return the standard deviation of tau as a tensor.

Return type:

Tensor

property noise_std: Tensor

Return the standard deviation of the model as a tensor.

Return type:

Tensor

property sources_std: float

Return the standard deviation of sources as a float.

Return type:

float

property source_dimension: int | None

Return the number of the sources

Return type:

Optional[int]

property has_sources: bool

Indicates whether the model includes sources.

Returns:
bool

True if source_dimension is a positive integer. False otherwise.

Return type:

bool

static time_reparametrization(*, t, alpha, tau)[source]

Tensorized time reparametrization formula.

Warning

Shapes of tensors must be compatible between them.

Parameters:
ttorch.Tensor

Timepoints to reparametrize

alphatorch.Tensor

Acceleration factors of individual(s)

tautorch.Tensor

Time-shift(s) of individual(s)

Returns:
torch.Tensor

Reparametrized time of same shape as timepoints

Parameters:
Return type:

TensorOrWeightedTensor[float]

get_variables_specs()[source]

Return the specifications of the variables (latent variables, derived variables, model ‘parameters’) that are part of the model.

Returns:
NamedVariables

A dictionary-like object containing specifications for the variables

Return type:

NamedVariables

put_individual_parameters(state, dataset)[source]

Initialize individual latent parameters in the given state if not already set.

Parameters:
stateState

The current state object that holds all the variables

datasetDataset

Dataset used to initialize latent variables accordingly.

Parameters:
to_dict(*, with_mixing_matrix=True)[source]

Export model object as dictionary ready for JSON saving.

Parameters:
with_mixing_matrixbool (default True)

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…

Returns:
KwargsType

The object as a dictionary.

Parameters:

with_mixing_matrix (bool)

Return type:

KwargsType

abstractmethod compute_individual_ages_from_biomarker_values(value, individual_parameters, feature=None)[source]

For one individual, compute age(s) at which the given features values are reached (given the subject’s individual parameters).

Consistency checks are done in the main API layer.

Parameters:
valuescalar or array_like[scalar] (list, tuple, numpy.ndarray)

Contains the biomarker value(s) of the subject.

individual_parametersdict

Contains the individual parameters. Each individual parameter should be a scalar or array_like.

featurestr (or None)

Name of the considered biomarker.

Note

Optional for UnivariateModel, compulsory for MultivariateModel.

Returns:
torch.Tensor

Contains the subject’s ages computed at the given values(s). Shape of tensor is (1, n_values).

Raises:
LeaspyModelInputError

If computation is tried on more than 1 individual.

Parameters:
Return type:

Tensor

abstractmethod compute_individual_ages_from_biomarker_values_tensorized(value, individual_parameters, feature)[source]

For one individual, compute age(s) at which the given features values are reached (given the subject’s individual parameters), with tensorized inputs.

Parameters:
valuetorch.Tensor of shape (1, n_values)

Contains the biomarker value(s) of the subject.

individual_parametersDictParamsTorch

Contains the individual parameters. Each individual parameter should be a torch.Tensor.

featurestr (or None)

Name of the considered biomarker.

Note

Optional for UnivariateModel, compulsory for MultivariateModel.

Returns:
torch.Tensor

Contains the subject’s ages computed at the given values(s). Shape of tensor is (n_values, 1).

Parameters:
Return type:

Tensor