leaspy.models.mcmc_saem_compatible
Classes
Defines probabilistic models compatible with an MCMC SAEM estimation. |
Module Contents
- 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