leaspy.models.time_reparametrized

Classes

TimeReparametrizedModel

Contains the common attributes & methods of the multivariate models.

Module Contents

class TimeReparametrizedModel(name, source_dimension=None, **kwargs)

Bases: leaspy.models.mcmc_saem_compatible.McmcSaemCompatibleModel

Contains the common attributes & methods of the multivariate models.

Parameters:
namestr

Name of the model.

**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 type:

Tensor

property tau_std: Tensor
Return type:

Tensor

property noise_std: Tensor
Return type:

Tensor

property sources_std: float
Return type:

float

property source_dimension: int | None
Return type:

Optional[int]

property has_sources: bool
Return type:

bool

static time_reparametrization(*, t, alpha, tau)

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

Returns:
torch.Tensor of same shape as timepoints
Parameters:
  • t (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])

  • alpha (Tensor)

  • tau (Tensor)

Return type:

leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float]

get_variables_specs()

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

Returns:
NamedVariables

The specifications of the model’s variables.

Return type:

NamedVariables

put_individual_parameters(state, dataset)
Parameters:
to_dict(*, with_mixing_matrix=True)

Export Leaspy 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:

leaspy.utils.typing.KwargsType

abstractmethod compute_individual_ages_from_biomarker_values(value, individual_parameters, feature=None)

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:
  • value (Union[float, list[float]])

  • individual_parameters (leaspy.utils.typing.DictParams)

  • feature (Optional[leaspy.utils.typing.FeatureType])

Return type:

Tensor

abstractmethod compute_individual_ages_from_biomarker_values_tensorized(value, individual_parameters, feature)

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:
  • value (Tensor)

  • individual_parameters (leaspy.utils.typing.DictParamsTorch)

  • feature (Optional[leaspy.utils.typing.FeatureType])

Return type:

Tensor