leaspy.models.mcmc_saem_compatible ================================== .. py:module:: leaspy.models.mcmc_saem_compatible Classes ------- .. autoapisummary:: leaspy.models.mcmc_saem_compatible.McmcSaemCompatibleModel Module Contents --------------- .. py:class:: McmcSaemCompatibleModel(name, *, obs_models, fit_metrics = None, **kwargs) Bases: :py:obj:`leaspy.models.stateful.StatefulModel` Defines probabilistic models compatible with an MCMC SAEM estimation. :Parameters: **name** : :obj:`str` The name of the model. **obs_models** : :class:`~leaspy.models.obs_models` or :class:`~typing.Iterable` [:class:`~leaspy.models.obs_models`] The noise model for observations (keyword-only parameter). **fit_metrics** : :obj:`dict` Metrics that should be measured during the fit of the model and reported back to the user. **\*\*kwargs** Hyperparameters for the model :Attributes: **is_initialized** : :obj:`bool` Indicates if the model is initialized. **name** : :obj:`str` The model's name. **features** : :obj:`list` [:obj:`str`] Names of the model features. **parameters** : :obj:`dict` Contains the model's parameters **obs_models** : :obj:`tuple` [:class:`~leaspy.models.obs_models`, ...] The observation model(s) associated to the model. **fit_metrics** : :obj:`dict` Contains the metrics that are measured during the fit of the model and reported to the user. **_state** : :class:`~leaspy.variables.state.State` Private instance holding all values for model variables and their derived variables. .. !! processed by numpydoc !! .. py:attribute:: obs_models .. py:attribute:: fit_metrics :value: None .. py:property:: observation_model_names :type: list[str] Get the names of the observation models. :Returns: :obj:`list` [:obj:`str`] The names of the observation models. .. !! processed by numpydoc !! .. py:method:: has_observation_model_with_name(name) Check if the model has an observation model with the given name. Parameters ---------- name : :obj:`str` The name of the observation model to check. :Returns: :obj:`bool`: True if the model has an observation model with the given name, False otherwise. .. !! processed by numpydoc !! .. py:method:: to_dict(**kwargs) Export model as a dictionary ready for export. :Returns: :class:`~leaspy.utils.typing.KwargsType` The model instance serialized as a dictionary. .. !! processed by numpydoc !! .. py:method:: 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: **timepoints** : :obj:`scalar` or :obj:`array_like` [:obj:`scalar`] (:obj:`list`, :obj:`tuple`, :class:`numpy.ndarray`) Contains the age(s) of the subject. **individual_parameters** : :class:`~leaspy.utils.typing.DictParams` Contains the individual parameters. Each individual parameter should be a scalar or array_like. **skip_ips_checks** : :obj:`bool` (default: ``False``) Flag to skip consistency/compatibility checks and tensorization of ``individual_parameters`` when it was done earlier (speed-up). :Returns: :class:`torch.Tensor` Contains the subject's scores computed at the given age(s) Shape of tensor is ``(1, n_tpts, n_features)``. .. !! processed by numpydoc !! .. py:method:: compute_prior_trajectory(timepoints, prior_type, *, n_individuals = None) Compute trajectory of the model for prior mode or mean of individual parameters. :Parameters: **timepoints** : :obj:`torch.Tensor` [1, n_timepoints] Contains the timepoints (age(s) of the subject). **prior_type** : :class:`~leaspy.variables.specs.LatentVariableInitType` The type of prior to use for the individual parameters. **n_individuals** : :obj:`int`, optional The number of individuals. :Returns: :class:`torch.Tensor` [1, n_timepoints, dimension] The group-average values at given timepoints. :Raises: :exc:`.LeaspyModelInputError` If `n_individuals` is provided but not a positive integer, or if it is provided while `prior_type` is not `LatentVariableInitType.PRIOR_SAMPLES`. .. !! processed by numpydoc !! .. py:method:: compute_mean_traj(timepoints) Trajectory for average of individual parameters (not really meaningful for non-linear models). :Parameters: **timepoints** : :obj:`torch.Tensor` [1, n_timepoints] .. :Returns: :class:`torch.Tensor` [1, n_timepoints, dimension] The group-average values at given timepoints. .. !! processed by numpydoc !! .. py:method:: compute_mode_traj(timepoints) Most typical individual trajectory. :Parameters: **timepoints** : :obj:`torch.Tensor` [1, n_timepoints] .. :Returns: :class:`torch.Tensor` [1, n_timepoints, dimension] The group-average values at given timepoints. .. !! processed by numpydoc !! .. py:method:: compute_jacobian_tensorized(state) :abstractmethod: Compute the jacobian of the model w.r.t. each individual parameter, given the input state. This function aims to be used in :class:`.ScipyMinimize` to speed up optimization. :Parameters: **state** : :class:`~leaspy.variables.state.State` Instance holding values for all model variables (including latent individual variables) :Returns: :class:`~leaspy.utils.typing.DictParamsTorch` Tensors are of shape ``(n_individuals, n_timepoints, n_features, n_dims_param)``. :Raises: :exc:`NotImplementedError` .. .. !! processed by numpydoc !! .. py:method:: compute_sufficient_statistics(state) :classmethod: Compute sufficient statistics from state. :Parameters: **state** : :class:`~leaspy.variables.state.State` .. :Returns: :class:`~leaspy.variables.specs.SuffStatsRW` Contains the sufficient statistics computed from the state. .. !! processed by numpydoc !! .. py:method:: update_parameters(state, sufficient_statistics, *, burn_in) :classmethod: Update model parameters of the provided state. :Parameters: **cls** : :class:`~leaspy.models.mcmc_saem_compatible.McmcSaemCompatibleModel` Model class to which the parameters belong. **state** : :class:`~leaspy.variables.state.State` Instance holding values for all model variables (including latent individual variables) **sufficient_statistics** : :class:`~leaspy.variables.specs.SuffStatsRO` Contains the sufficient statistics computed from the state. **burn_in** : :obj:`bool` If True, the parameters are updated in a burn-in phase. .. !! processed by numpydoc !! .. py:method:: get_variables_specs() Get the specifications of the variables used in the model. :Returns: :class:`~leaspy.variables.specs.NamedVariables` Specifications of the variables used in the model, including timepoints and observation models. .. !! processed by numpydoc !! .. py:method:: put_individual_parameters(state, dataset) :abstractmethod: Put the individual parameters inside the provided state (in-place). :Raises: :exc:`NotImplementedError` .. .. !! processed by numpydoc !! .. py:method:: put_data_variables(state, dataset) Put all the needed data variables inside the provided state (in-place). :Parameters: **state** : :class:`~leaspy.variables.state.State` Instance holding values for all model variables (including latent individual variables), as well as: - timepoints : :class:`torch.Tensor` of shape (n_individuals, n_timepoints) **dataset** : :class:`~leaspy.io.data.dataset.Dataset` The dataset containing the data to be put in the state. .. !! processed by numpydoc !! .. py:method:: reset_data_variables(state) Reset all data variables inside the provided state (in-place). :Parameters: **state** : :class:`~leaspy.variables.state.State` Instance holding values for all model variables (including latent individual variables), as well as: - timepoints : :class:`torch.Tensor` of shape (n_individuals, n_timepoints) .. !! processed by numpydoc !!