leaspy.models
Submodules
- leaspy.models.base
- leaspy.models.constant
- leaspy.models.factory
- leaspy.models.generic
- leaspy.models.joint
- leaspy.models.lme
- leaspy.models.mcmc_saem_compatible
- leaspy.models.obs_models
- leaspy.models.riemanian_manifold
- leaspy.models.settings
- leaspy.models.shared_speed_logistic
- leaspy.models.time_reparametrized
- leaspy.models.utilities
- leaspy.models.utils
Attributes
Classes
Base model class from which all |
|
str(object='') -> str |
|
ConstantModel is a benchmark model that predicts constant values (no matter what the patient's ages are). |
|
The available models that users can instantiate in Leaspy. |
|
Generic model (temporary until |
|
Joint model for multiple repeated measures (logistic) and multiple competing events. |
|
LMEModel is a benchmark model that fits and personalize a linear mixed-effects model. |
|
Defines probabilistic models compatible with an MCMC SAEM estimation. |
|
Manifold model for multiple variables of interest (linear formulation). |
|
Manifold model for multiple variables of interest (logistic formulation). |
|
Manifold model for multiple variables of interest (logistic or linear formulation). |
|
Used in |
|
Logistic model for multiple variables of interest, imposing same average |
|
Contains the common attributes & methods of the multivariate models. |
Functions
|
Return the model object corresponding to |
Package Contents
- class BaseModel(name, **kwargs)
Bases:
abc.ABCBase model class from which all
Leaspymodels should inherit.It defines the interface that a model should implement to be compatible with
Leaspy.- Parameters:
- name
str The name of the model.
- **kwargs
Hyperparameters of the model
- name
- Attributes:
- Parameters:
name (str)
- name
- property features: list[leaspy.utils.typing.FeatureType] | None
- Return type:
Optional[list[leaspy.utils.typing.FeatureType]]
- property dimension: int | None
The dimension of the model. If the private attribute is defined, then it takes precedence over the feature length. The associated setters are responsible for their coherence.
- Return type:
Optional[int]
- initialize(dataset=None, method=None)
Initialize the model given a
Datasetand an initialization method.After calling this method
is_initializedshould beTrueand model should be ready for use.- Parameters:
- dataset
Dataset, optional The dataset we want to initialize from.
- methodInitializationMethod, optional
A custom method to initialize the model
- dataset
- Parameters:
dataset (Optional[Dataset])
method (Optional[InitializationMethod])
- Return type:
None
- class InitializationMethod
-
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- DEFAULT = 'default'
- RANDOM = 'random'
- class ConstantModel(name, **kwargs)
Bases:
leaspy.models.generic.GenericModelConstantModel is a benchmark model that predicts constant values (no matter what the patient’s ages are).
These constant values depend on the algorithm setting and the patient’s values provided during calibration.
- It could predict:
last: last value seen during calibration (even ifNaN).last_known: last nonNaNvalue seen during calibration.max: maximum (=worst) value seen during calibration.mean: average of values seen during calibration.
Warning
Depending on
features, thelast_known/maxvalue may correspond to different visits.Warning
For a given feature, value will be
NaNif and only if all values for this feature wereNaN.- Parameters:
- name
str The model’s name.
- **kwargs
Hyperparameters for the model. None supported for now.
- name
- Attributes:
- name
str The model’s name.
- is_initialized
bool Always
True(no true initialization needed for constant model).- features
listofstr List of the model features. Unlike most models features will be determined at personalization only (because it does not needed any fit).
- dimension
int Number of features (read-only).
- parameters
dict The model has no parameters: empty dictionary. The
prediction_typeparameter should be defined during personalization. Example:>>> AlgorithmSettings('constant_prediction', prediction_type='last_known')
- name
- Parameters:
name (str)
See also
ConstantPredictionAlgorithm
- is_initialized = True
- compute_individual_trajectory(timepoints, individual_parameters)
Compute scores values at the given time-point(s) given a subject’s individual parameters.
- Parameters:
- timepointsscalar or array_like[scalar] (
list,tuple,numpy.ndarray) Contains the age(s) of the subject.
- individual_parameters
dict[str, Any] Contains the individual parameters. Each individual parameter should be a scalar or array_like.
- timepointsscalar or array_like[scalar] (
- Returns:
torch.TensorContains the subject’s scores computed at the given age(s). The shape of the tensor is
(1, n_tpts, n_features).
- Parameters:
- Return type:
- class ModelName
-
The available models that users can instantiate in Leaspy.
- JOINT = 'joint'
- LOGISTIC = 'logistic'
- LINEAR = 'linear'
- SHARED_SPEED_LOGISTIC = 'shared_speed_logistic'
- LME = 'lme'
- CONSTANT = 'constant'
- model_factory(name, instance_name=None, **kwargs)
Return the model object corresponding to
namearg with possiblekwargs.- Parameters:
- namestr or ModelName
The name of the model class to be instantiated.
- instance_namestr, optional
The custom name of the instance to be created. If not provided, it will be the model class name.
- **kwargs
Contains model’s hyper-parameters. Raise an error if the keyword is inappropriate for the given model’s name.
- Returns:
BaseModelA child class object of
models.BaseModelclass object determined byname.
- Parameters:
- Return type:
- class GenericModel(name, **kwargs)
Bases:
leaspy.models.base.BaseModelGeneric model (temporary until
AbstractModelis really abstract).TODO: change naming after AbstractModel was renamed?
- Parameters:
- name
str The name of the model.
- **kwargs
Hyperparameters of the model.
- name
- Attributes:
- Parameters:
name (str)
- parameters: leaspy.utils.typing.KwargsType
- get_hyperparameters(*, with_features=True, with_properties=True, default=None)
Get all model hyperparameters.
- Parameters:
- with_features, with_properties
bool(defaultTrue) Whether to include features and respectively all _properties (i.e. _dynamic_ hyperparameters) in the returned dictionary.
- defaultAny
Default value is something is an hyperparameter is missing (should not!).
- with_features, with_properties
- Returns:
- :obj:`dict` { hyperparam_name
str-> hyperparam_valueAny }
- :obj:`dict` { hyperparam_name
- Return type:
leaspy.utils.typing.KwargsType
- load_parameters(parameters, *, list_converter=np.array)
Instantiate or update the model’s parameters.
- Parameters:
- parameters
dict Contains the model’s parameters.
- list_convertercallable
The function to convert list objects.
- parameters
- Return type:
None
- load_hyperparameters(hyperparameters, *, with_defaults=False)
Load model hyperparameters from a
dict.- Parameters:
- Raises:
LeaspyModelInputErrorIf inconsistent hyperparameters.
- Parameters:
hyperparameters (leaspy.utils.typing.KwargsType)
with_defaults (bool)
- Return type:
None
- save(path, **kwargs)
Save
Leaspyobject as JSON model parameter file.Default save method: it can be overwritten in child class but should be generic…
- abstractmethod compute_individual_trajectory(timepoints, individual_parameters)
Compute scores values at the given time-point(s) given a subject’s individual parameters.
- Parameters:
- timepointsscalar or array_like[scalar] (
list,tuple,numpy.ndarray) Contains the age(s) of the subject.
- individual_parameters
dict[str, Any] Contains the individual parameters. Each individual parameter should be a scalar or array_like.
- timepointsscalar or array_like[scalar] (
- Returns:
torch.TensorContains the subject’s scores computed at the given age(s). The shape of the tensor is
(1, n_tpts, n_features).
- Parameters:
individual_parameters (dict)
- Return type:
- class JointModel(name, **kwargs)
Bases:
leaspy.models.riemanian_manifold.LogisticModelJoint model for multiple repeated measures (logistic) and multiple competing events. The model implemented is associated to this [publication](https://arxiv.org/abs/2501.08960) on arxiv.
- Parameters:
- name
str The name of the model.
- **kwargs
Hyperparameters of the model (including noise_model)
- name
- Raises:
LeaspyModelInputErrorIf name is not one of allowed sub-type: ‘univariate_linear’ or ‘univariate_logistic’
If hyperparameters are inconsistent
- Parameters:
name (str)
- 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:
- to_dict(*, with_mixing_matrix=True)
Export model as a dictionary ready for export. Add the number of events compare to the multivariate output
- put_individual_parameters(state, dataset)
Initialise the individual parameters of the state thanks to the dataset.
- compute_individual_trajectory(timepoints, individual_parameters, *, skip_ips_checks=False)
This method computes the individual trajectory of a patient for given timepoint(s) using his/her individual parameters (random effects). For the longitudinal sub-model:
Compute longitudinal values
- For the event sub-model:
only one event: return the survival rate corrected by the probability of the first time point of the prediction assuming that the patient was alive,
more than one event: return the Cumulative Incidence function corrected by the probability of the first time point of the prediction assuming that the patient was alive.
Nota: model uses its current internal state.
- Parameters:
- timepointsscalar or array_like[scalar] (
list,tuple,numpy.ndarray) Contains the age(s) of the subject.
- individual_parameters
dict Contains the individual parameters. Each individual parameter should be a scalar or array_like.
- skip_ips_checks
bool(default:False) Flag to skip consistency/compatibility checks and tensorization of
individual_parameterswhen it was done earlier (speed-up).
- timepointsscalar or array_like[scalar] (
- Returns:
torch.TensorContains the subject’s scores computed at the given age(s) Shape of tensor is
(1, n_tpts, n_features).
- Raises:
LeaspyModelInputErrorIf computation is tried on more than 1 individual.
LeaspyIndividualParamsInputErrorif invalid individual parameters.
- Parameters:
individual_parameters (leaspy.utils.typing.DictParams)
skip_ips_checks (bool)
- Return type:
- class LMEModel(name, **kwargs)
Bases:
leaspy.models.generic.GenericModelLMEModel is a benchmark model that fits and personalize a linear mixed-effects model.
The model specification is the following:
\[y_{ij} = fixed_{intercept} + random_{intercept_i} + (fixed_{slopeAge} + random_{slopeAge_i}) * age_{ij} + \epsilon_{ij}\]- with:
\(y_{ij}\): value of the feature of the i-th subject at his j-th visit,
\(age_{ij}\): age of the i-th subject at his j-th visit.
\(\epsilon_{ij}\): residual Gaussian noise (independent between visits)
Warning
This model must be fitted on one feature only (univariate model).
TODO? should inherit from AbstractModel. TODO? add some covariates in this very simple model.
- Parameters:
- Attributes:
- name
str The model’s name.
- is_initialized
bool Trueif the model is initialized,Falseotherwise.- with_random_slope_age
bool(defaultTrue) Has the LME a random slope for subject’s age? Otherwise it only has a random intercept per subject.
- features
listofstr List of the model features.
Warning
LME has only one feature.
- dimension
int Will always be 1 (univariate).
- parameters
dict - Contains the model parameters. In particular:
ages_meanfloatMean of ages (for normalization).
ages_stdfloatStd-dev of ages (for normalization).
fe_paramsnp.ndarrayoffloatFixed effects.
cov_renp.ndarrayVariance-covariance matrix of random-effects.
cov_re_unscaled_invnp.ndarrayInverse of unscaled (= divided by variance of noise) variance-covariance matrix of random-effects. This matrix is used for personalization to new subjects.
noise_stdfloatStd-dev of Gaussian noise.
bse_fe,bse_renp.ndarrayoffloatStandard errors on fixed-effects and random-effects respectively (not used in
Leaspy).
- name
- Parameters:
name (str)
See also
LMEFitAlgorithmLMEPersonalizeAlgorithm
- dimension = 1
The dimension of the model. If the private attribute is defined, then it takes precedence over the feature length. The associated setters are responsible for their coherence.
- compute_individual_trajectory(timepoints, individual_parameters)
Compute scores values at the given time-point(s) given a subject’s individual parameters.
- Parameters:
- timepointsarray-like of ages (not normalized)
Timepoints to compute individual trajectory at.
- individual_parameters
dict - Individual parameters:
random_intercept
random_slope_age (if
with_random_slope_age == True)
- Returns:
torch.TensoroffloatThe individual trajectories. The shape of the tensor is
(n_individuals == 1, n_tpts == len(timepoints), n_features == 1).
- Parameters:
individual_parameters (dict)
- class McmcSaemCompatibleModel(name, *, obs_models, fit_metrics=None, **kwargs)
Bases:
leaspy.models.base.BaseModelDefines probabilistic models compatible with an MCMC SAEM estimation.
- Parameters:
- Attributes:
- is_initialized
bool Indicates if the model is initialized.
- name
str The model’s name.
- features
listofstr Names of the model features.
- parameters
dict Contains the model’s parameters
- obs_modelsTuple[ObservationModel, …]
The observation model(s) associated to the model.
- fit_metrics
dict Contains the metrics that are measured during the fit of the model and reported to the user.
- _stateState
Private instance holding all values for model variables and their derived variables.
- is_initialized
- Parameters:
name (str)
obs_models (Union[ObservationModel, Iterable[ObservationModel]])
- obs_models
- fit_metrics = None
- track_variable(variable)
- Parameters:
variable (leaspy.variables.specs.VariableName)
- Return type:
None
- track_variables(variables)
- Parameters:
variables (Iterable[leaspy.variables.specs.VariableName])
- Return type:
None
- untrack_variable(variable)
- Parameters:
variable (leaspy.variables.specs.VariableName)
- Return type:
None
- untrack_variables(variables)
- Parameters:
variables (Iterable[leaspy.variables.specs.VariableName])
- Return type:
None
- property dag: VariablesDAG
- Return type:
- property hyperparameters_names: tuple[leaspy.variables.specs.VariableName, Ellipsis]
- Return type:
tuple[leaspy.variables.specs.VariableName, Ellipsis]
- property parameters_names: tuple[leaspy.variables.specs.VariableName, Ellipsis]
- Return type:
tuple[leaspy.variables.specs.VariableName, Ellipsis]
- property population_variables_names: tuple[leaspy.variables.specs.VariableName, Ellipsis]
- Return type:
tuple[leaspy.variables.specs.VariableName, Ellipsis]
- property individual_variables_names: tuple[leaspy.variables.specs.VariableName, Ellipsis]
- Return type:
tuple[leaspy.variables.specs.VariableName, Ellipsis]
- property parameters: leaspy.utils.typing.DictParamsTorch
Dictionary of values for model parameters.
- Return type:
leaspy.utils.typing.DictParamsTorch
- property hyperparameters: leaspy.utils.typing.DictParamsTorch
Dictionary of values for model hyperparameters.
- Return type:
leaspy.utils.typing.DictParamsTorch
- abstractmethod to_dict()
Export model as a dictionary ready for export.
- Returns:
- KwargsType
The model instance serialized as a dictionary.
- Return type:
leaspy.utils.typing.KwargsType
- save(path, **kwargs)
Save
Leaspyobject as json model parameter file.TODO move logic upstream?
- load_parameters(parameters)
Instantiate or update the model’s parameters.
It assumes that all model hyperparameters are defined.
- compute_individual_trajectory(timepoints, individual_parameters, *, skip_ips_checks=False)
Compute scores values at the given time-point(s) given a subject’s individual parameters.
Note
The model uses its current internal state.
- Parameters:
- timepointsscalar or array_like[scalar] (
list,tuple,numpy.ndarray) Contains the age(s) of the subject.
- individual_parameters
dict Contains the individual parameters. Each individual parameter should be a scalar or array_like.
- skip_ips_checks
bool(default:False) Flag to skip consistency/compatibility checks and tensorization of
individual_parameterswhen it was done earlier (speed-up).
- timepointsscalar or array_like[scalar] (
- Returns:
torch.TensorContains the subject’s scores computed at the given age(s) Shape of tensor is
(1, n_tpts, n_features).
- Raises:
LeaspyModelInputErrorIf computation is tried on more than 1 individual.
LeaspyIndividualParamsInputErrorif invalid individual parameters.
- Parameters:
individual_parameters (leaspy.utils.typing.DictParams)
skip_ips_checks (bool)
- Return type:
- compute_prior_trajectory(timepoints, prior_type, *, n_individuals=None)
Compute trajectory of the model for prior mode or mean of individual parameters.
- Parameters:
- timepoints
torch.Tensor[1, n_timepoints] - prior_typeLatentVariableInitType
- n_individualsint, optional
The number of individuals.
- timepoints
- Returns:
torch.Tensor[1, n_timepoints, dimension]The group-average values at given timepoints.
- Parameters:
timepoints (Tensor)
prior_type (LatentVariableInitType)
n_individuals (Optional[int])
- Return type:
leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float]
- compute_mean_traj(timepoints)
Trajectory for average of individual parameters (not really meaningful for non-linear models).
- Parameters:
timepoints (Tensor)
- abstractmethod compute_jacobian_tensorized(state)
Compute the jacobian of the model w.r.t. each individual parameter, given the input state.
This function aims to be used in
ScipyMinimizeto speed up optimization.- Parameters:
- state
State Instance holding values for all model variables (including latent individual variables), as well as: - timepoints :
torch.Tensorof shape (n_individuals, n_timepoints)
- state
- Returns:
dict[ param_name:str,torch.Tensor]Tensors are of shape
(n_individuals, n_timepoints, n_features, n_dims_param).
- Parameters:
state (State)
- Return type:
leaspy.utils.typing.DictParamsTorch
- classmethod compute_sufficient_statistics(state)
Compute sufficient statistics from state.
- Parameters:
- state
State
- state
- Returns:
dict[ suff_stat:str,torch.Tensor]
- Parameters:
state (State)
- Return type:
leaspy.variables.specs.SuffStatsRW
- classmethod update_parameters(state, sufficient_statistics, *, burn_in)
Update model parameters of the provided state.
- Parameters:
- state
State - sufficient_statisticsdict[suff_stat: str,
torch.Tensor] - burn_inbool
- state
- Parameters:
- Return type:
None
- 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:
- initialize(dataset=None, method=None)
Overloads base model initialization (in particular to handle internal model State).
<!> We do not put data variables in internal model state at this stage (done in algorithm)
- Parameters:
- dataset
Dataset, optional Input dataset from which to initialize the model.
- methodInitializationMethod, optional
The initialization method to be used. Default=’default’.
- dataset
- Parameters:
dataset (Optional[Dataset])
method (Optional[InitializationMethod])
- Return type:
None
- abstractmethod put_individual_parameters(state, dataset)
- put_data_variables(state, dataset)
Put all the needed data variables inside the provided state (in-place).
- reset_data_variables(state)
Reset all data variables inside the provided state (in-place).
- Parameters:
state (State)
- Return type:
None
- move_to_device(device)
Move a model and its relevant attributes to the specified
torch.device.- Parameters:
- device
torch.device
- device
- Parameters:
device (device)
- Return type:
None
- class LinearModel(name, **kwargs)
Bases:
LinearInitializationMixin,RiemanianManifoldModelManifold model for multiple variables of interest (linear formulation).
- Parameters:
name (str)
- 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:
- static metric(*, g)
Used to define the corresponding variable.
- class LogisticModel(name, **kwargs)
Bases:
LogisticInitializationMixin,RiemanianManifoldModelManifold model for multiple variables of interest (logistic formulation).
- Parameters:
name (str)
- 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:
- static metric(*, g)
Used to define the corresponding variable.
- classmethod model_with_sources(*, rt, space_shifts, metric, v0, g)
Returns a model with sources.
- Parameters:
rt (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
space_shifts (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
metric (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
v0 (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
g (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
- Return type:
- class RiemanianManifoldModel(name, variables_to_track=None, **kwargs)
Bases:
leaspy.models.time_reparametrized.TimeReparametrizedModelManifold model for multiple variables of interest (logistic or linear formulation).
- Parameters:
- name
str The name of the model.
- **kwargs
Hyperparameters of the model (including noise_model)
- name
- Raises:
LeaspyModelInputErrorIf hyperparameters are inconsistent
- Parameters:
name (str)
variables_to_track (Optional[Iterable[leaspy.variables.specs.VariableName]])
- classmethod compute_sufficient_statistics(state)
Compute the model’s sufficient statistics.
- 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:
- classmethod model_no_sources(*, rt, metric, v0, g)
Returns a model without source. A bit dirty?
- class ModelSettings(path_to_model_settings_or_dict)
Used in
Leaspy.load()to create aLeaspyclass object from a json file.- Parameters:
- path_to_model_settings_or_dictdict or str
If a str: path to a json file containing model settings
If a dict: content of model settings
- Raises:
- Parameters:
- parameters: leaspy.utils.typing.KwargsType
- hyperparameters: leaspy.utils.typing.KwargsType
Bases:
leaspy.models.riemanian_manifold.LogisticInitializationMixin,leaspy.models.time_reparametrized.TimeReparametrizedModelLogistic model for multiple variables of interest, imposing same average evolution pace for all variables (logistic curves are only time-shifted).
- Parameters:
- name
str The name of the model.
- **kwargs
Hyperparameters of the model.
- name
- Parameters:
name (str)
Prepend deltas with a zero as delta_1 is set to zero in the equations.
Returns a model with sources.
- Parameters:
rt (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
space_shifts (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
metric (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
deltas_padded (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
log_g (leaspy.utils.weighted_tensor.TensorOrWeightedTensor[float])
- Return type:
Returns a model without source. A bit dirty?
- Parameters:
- Return type:
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:
- class TimeReparametrizedModel(name, source_dimension=None, **kwargs)
Bases:
leaspy.models.mcmc_saem_compatible.McmcSaemCompatibleModelContains the common attributes & methods of the multivariate models.
- Parameters:
- name
str Name of the model.
- **kwargs
Hyperparameters for the model (including obs_models).
- name
- Raises:
LeaspyModelInputErrorIf inconsistent hyperparameters.
- Parameters:
- static time_reparametrization(*, t, alpha, tau)
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).
- t
- Returns:
torch.Tensorof same shape as timepoints
- Parameters:
- 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:
- to_dict(*, with_mixing_matrix=True)
Export
Leaspyobject 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:
- 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_parameters
dict Contains the individual parameters. Each individual parameter should be a scalar or array_like.
- feature
str(or None) Name of the considered biomarker.
Note
Optional for
UnivariateModel, compulsory forMultivariateModel.
- valuescalar or array_like[scalar] (
- Returns:
torch.TensorContains the subject’s ages computed at the given values(s). Shape of tensor is
(1, n_values).
- Raises:
LeaspyModelInputErrorIf computation is tried on more than 1 individual.
- Parameters:
- Return type:
- 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:
- value
torch.Tensorof 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.- feature
str(or None) Name of the considered biomarker.
Note
Optional for
UnivariateModel, compulsory forMultivariateModel.
- value
- Returns:
torch.TensorContains 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:
- ModelType