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)[source]¶
Bases:
leaspy.models.stateful.StatefulModelDefines probabilistic models compatible with an MCMC SAEM estimation.
- Parameters:
- name
str The name of the model.
- obs_models
obs_modelsorIterable[obs_models] The noise model for observations (keyword-only parameter).
- fit_metrics
dict Metrics that should be measured during the fit of the model and reported back to the user.
- **kwargs
Hyperparameters for the model
- name
- Attributes:
- is_initialized
bool Indicates if the model is initialized.
- name
str The model’s name.
- features
list[str] Names of the model features.
- parameters
dict Contains the model’s parameters
- obs_models
tuple[obs_models, …] 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.
- _state
State 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¶
- has_observation_model_with_name(name)[source]¶
Check if the model has an observation model with the given name. Parameters ———- name :
strThe name of the observation model to check.
- to_dict(**kwargs)[source]¶
Export model as a dictionary ready for export.
- Returns:
KwargsTypeThe model instance serialized as a dictionary.
- Return type:
- compute_individual_trajectory(timepoints, individual_parameters, *, skip_ips_checks=False)[source]¶
Compute scores values at the given time-point(s) given a subject’s individual parameters.
Note
The model uses its current internal state.
- Parameters:
- timepoints
scalarorarray_like[scalar] (list,tuple,numpy.ndarray) Contains the age(s) of the subject.
- individual_parameters
DictParams 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).
- timepoints
- Returns:
torch.TensorContains the subject’s scores computed at the given age(s) Shape of tensor is
(1, n_tpts, n_features).
- Parameters:
individual_parameters (DictParams)
skip_ips_checks (bool)
- Return type:
- compute_prior_trajectory(timepoints, prior_type, *, n_individuals=None)[source]¶
Compute trajectory of the model for prior mode or mean of individual parameters.
- Parameters:
- timepoints
torch.Tensor[1, n_timepoints] Contains the timepoints (age(s) of the subject).
- prior_type
LatentVariableInitType The type of prior to use for the individual parameters.
- n_individuals
int, optional The number of individuals.
- timepoints
- Returns:
torch.Tensor[1, n_timepoints, dimension]The group-average values at given timepoints.
- Raises:
LeaspyModelInputErrorIf n_individuals is provided but not a positive integer, or if it is provided while prior_type is not LatentVariableInitType.PRIOR_SAMPLES.
- Parameters:
timepoints (Tensor)
prior_type (LatentVariableInitType)
n_individuals (Optional[int])
- Return type:
- compute_mean_traj(timepoints)[source]¶
Trajectory for average of individual parameters (not really meaningful for non-linear models).
- Parameters:
- timepoints
torch.Tensor[1, n_timepoints]
- timepoints
- Returns:
torch.Tensor[1, n_timepoints, dimension]The group-average values at given timepoints.
- Parameters:
timepoints (Tensor)
- Return type:
- compute_mode_traj(timepoints)[source]¶
Most typical individual trajectory.
- Parameters:
- timepoints
torch.Tensor[1, n_timepoints]
- timepoints
- Returns:
torch.Tensor[1, n_timepoints, dimension]The group-average values at given timepoints.
- Parameters:
timepoints (Tensor)
- Return type:
- abstractmethod compute_jacobian_tensorized(state)[source]¶
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)
- state
- Returns:
DictParamsTorchTensors are of shape
(n_individuals, n_timepoints, n_features, n_dims_param).
- Raises:
- Parameters:
state (State)
- Return type:
- classmethod compute_sufficient_statistics(state)[source]¶
Compute sufficient statistics from state.
- Parameters:
- state
State
- state
- Returns:
SuffStatsRWContains the sufficient statistics computed from the state.
- Parameters:
state (State)
- Return type:
- classmethod update_parameters(state, sufficient_statistics, *, burn_in)[source]¶
Update model parameters of the provided state.
- Parameters:
- cls
McmcSaemCompatibleModel Model class to which the parameters belong.
- state
State Instance holding values for all model variables (including latent individual variables)
- sufficient_statistics
SuffStatsRO Contains the sufficient statistics computed from the state.
- burn_in
bool If True, the parameters are updated in a burn-in phase.
- cls
- Parameters:
state (State)
sufficient_statistics (SuffStatsRO)
burn_in (bool)
- Return type:
None
- get_variables_specs()[source]¶
Get the specifications of the variables used in the model.
- Returns:
NamedVariablesSpecifications of the variables used in the model, including timepoints and observation models.
- Return type:
- abstractmethod put_individual_parameters(state, dataset)[source]¶
Put the individual parameters inside the provided state (in-place).
- Raises:
- Parameters:
- put_data_variables(state, dataset)[source]¶
Put all the needed data variables inside the provided state (in-place).
- 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)- dataset
Dataset The dataset containing the data to be put in the state.
- state
- Parameters:
- Return type:
None
- reset_data_variables(state)[source]¶
Reset all data variables inside the provided state (in-place).
- 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
- Parameters:
state (State)
- Return type:
None