leaspy.models
.GenericModel
- class GenericModel(name: str, **kwargs)
Bases:
BaseModel
Generic model (temporary until
AbstractModel
is really abstract).TODO: change naming after AbstractModel was renamed?
- Parameters:
- name
str
The name of the model.
- **kwargs
Hyperparameters of the model.
- name
- Attributes:
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.- abstract compute_individual_trajectory(timepoints, individual_parameters: dict) Tensor
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.Tensor
Contains the subject’s scores computed at the given age(s). The shape of the tensor is
(1, n_tpts, n_features)
.
- 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