leaspy.models.generic

Classes

GenericModel

Generic model (temporary until AbstractModel is really abstract).

Module Contents

class GenericModel(name, **kwargs)

Bases: leaspy.models.base.BaseModel

Generic model (temporary until AbstractModel is really abstract).

TODO: change naming after AbstractModel was renamed?

Parameters:
namestr

The name of the model.

**kwargs

Hyperparameters of the model.

Attributes:
namestr

The name of the model.

is_initializedbool

True if the model is initialized, False otherwise.

featureslist of str

List of model features (None if not initialization).

dimensionint (read-only)

Number of features.

parametersdict

Contains internal parameters of the model.

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_propertiesbool (default True)

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

Returns:
:obj:`dict` { hyperparam_namestr -> hyperparam_valueAny }
Return type:

leaspy.utils.typing.KwargsType

hyperparameters_ok()

Check all model hyperparameters are ok.

Returns:
bool
Return type:

bool

load_parameters(parameters, *, list_converter=np.array)

Instantiate or update the model’s parameters.

Parameters:
parametersdict

Contains the model’s parameters.

list_convertercallable

The function to convert list objects.

Return type:

None

load_hyperparameters(hyperparameters, *, with_defaults=False)

Load model hyperparameters from a dict.

Parameters:
hyperparametersdict [ str, Any]

Contains the model’s hyperparameters.

with_defaultsbool (default False)

If True, it also resets hyperparameters that are part of the model but not included in hyperparameters to their default value.

Raises:
LeaspyModelInputError

If inconsistent hyperparameters.

Parameters:
  • hyperparameters (leaspy.utils.typing.KwargsType)

  • with_defaults (bool)

Return type:

None

save(path, **kwargs)

Save Leaspy object as JSON model parameter file.

Default save method: it can be overwritten in child class but should be generic…

Parameters:
pathstr

Path to store the model’s parameters.

**kwargs

Keyword arguments for json.dump method.

Parameters:

path (str)

Return type:

None

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_parametersdict [ str, Any]

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

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

Parameters:

individual_parameters (dict)

Return type:

Tensor