leaspy.models
.LMEModel
- class LMEModel(name: str, **kwargs)
Bases:
GenericModel
LMEModel is a benchmark model that fits and personalize a linear mixed-effects model.
The model specification is the following:
- with:
: value of the feature of the i-th subject at his j-th visit,
: age of the i-th subject at his j-th visit.
: 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:
See also
- Attributes:
- name
str
The model’s name.
- is_initialized
bool
True
if the model is initialized,False
otherwise.- 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
list
ofstr
List of the model features.
Warning
LME has only one feature.
dimension
int
The dimension of the model.
- parameters
dict
- Contains the model parameters. In particular:
ages_mean
float
Mean of ages (for normalization).
ages_std
float
Std-dev of ages (for normalization).
fe_params
np.ndarray
offloat
Fixed effects.
cov_re
np.ndarray
Variance-covariance matrix of random-effects.
cov_re_unscaled_inv
np.ndarray
Inverse of unscaled (= divided by variance of noise) variance-covariance matrix of random-effects. This matrix is used for personalization to new subjects.
noise_std
float
Std-dev of Gaussian noise.
bse_fe
,bse_re
np.ndarray
offloat
Standard errors on fixed-effects and random-effects respectively (not used in
Leaspy
).
- name
Methods
compute_individual_trajectory
(timepoints, ...)Compute scores values at the given time-point(s) given a subject's individual parameters.
get_hyperparameters
(*[, with_features, ...])Get all model hyperparameters.
Check all model hyperparameters are ok.
initialize
(dataset[, method])Initialize the model given a
Dataset
and an initialization method.load_hyperparameters
(hyperparameters, *[, ...])Load model hyperparameters from a
dict
.load_parameters
(parameters, *[, list_converter])Instantiate or update the model's parameters.
save
(path, **kwargs)Save
Leaspy
object as JSON model parameter file.validate_compatibility_of_dataset
(dataset)Raise if the given
Dataset
is not compatible with the current model.- compute_individual_trajectory(timepoints, individual_parameters: dict)
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.Tensor
offloat
The individual trajectories. The shape of the tensor is
(n_individuals == 1, n_tpts == len(timepoints), n_features == 1)
.
- 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.
- get_hyperparameters(*, with_features=True, with_properties=True, default=None) Dict[str, Any]
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
- initialize(dataset: Dataset, method: str = 'default') None
Initialize the model given a
Dataset
and an initialization method.After calling this method
is_initialized
should beTrue
and model should be ready for use.
- load_hyperparameters(hyperparameters: Dict[str, Any], *, with_defaults: bool = False) None
Load model hyperparameters from a
dict
.- Parameters:
- Raises:
LeaspyModelInputError
If inconsistent hyperparameters.
- load_parameters(parameters, *, list_converter=<built-in function array>) None
Instantiate or update the model’s parameters.
- Parameters:
- parameters
dict
Contains the model’s parameters.
- list_convertercallable
The function to convert list objects.
- parameters
- save(path: str, **kwargs) None
Save
Leaspy
object as JSON model parameter file.Default save method: it can be overwritten in child class but should be generic…
- Parameters:
- path
str
Path to store the model’s parameters.
- **kwargs
Keyword arguments for
json.dump
method.
- path