leaspy.samplers.base ==================== .. py:module:: leaspy.samplers.base Classes ------- .. autoapisummary:: leaspy.samplers.base.AbstractSampler leaspy.samplers.base.AbstractIndividualSampler leaspy.samplers.base.AbstractPopulationSampler Module Contents --------------- .. py:class:: AbstractSampler(name, shape, *, acceptation_history_length = 25) Bases: :py:obj:`abc.ABC` Abstract sampler class. :Parameters: **name** : :obj:`str` The name of the random variable to sample. **shape** : :obj:`tuple` of :obj:`int` The shape of the random variable to sample. **acceptation_history_length** : :obj:`int` > 0 (default 25) Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (It is the same for population or individual variables.) :Attributes: **name** : :obj:`str` Name of variable **shape** : :obj:`tuple` of :obj:`int` Shape of variable **acceptation_history_length** : :obj:`int` Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (Same for population or individual variables by default.) **acceptation_history** : :class:`torch.Tensor` History of binary acceptations to compute mean acceptation rate for the sampler in MCMC-SAEM algorithm. It keeps the history of the last `acceptation_history_length` steps. :Raises: :exc:`.LeaspyModelInputError` .. .. !! processed by numpydoc !! .. py:attribute:: name .. py:attribute:: shape .. py:attribute:: acceptation_history_length :value: 25 .. py:attribute:: acceptation_history .. py:property:: ndim :type: int Number of dimensions. .. !! processed by numpydoc !! .. py:property:: shape_acceptation :type: Tuple[int, Ellipsis] :abstractmethod: Return the shape of acceptation tensor for a single iteration. :Returns: :obj:`tuple` of :obj:`int` The shape of the acceptation history. .. !! processed by numpydoc !! .. py:method:: sample(state, *, temperature_inv) :abstractmethod: Apply a sampling step It will modify in-place the internal state, caching all intermediate values needed to efficient. :Parameters: **state** : :class:`.State` Object containing values for all model variables, including latent variables **temperature_inv** : :obj:`float` > 0 Inverse of the temperature used in tempered MCMC-SAEM .. !! processed by numpydoc !! .. py:class:: AbstractIndividualSampler(name, shape, *, n_patients, acceptation_history_length = 25) Bases: :py:obj:`AbstractSampler` Abstract class for samplers of individual random variables. :Parameters: **name** : :obj:`str` The name of the random variable to sample. **shape** : :obj:`tuple` of :obj:`int` The shape of the random variable to sample. **n_patients** : :obj:`int` Number of patients. **acceptation_history_length** : :obj:`int` > 0 (default 25) Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (It is the same for population or individual variables.) :Attributes: **name** : :obj:`str` Name of variable **shape** : :obj:`tuple` of :obj:`int` Shape of variable **n_patients** : :obj:`int` Number of patients. **acceptation_history_length** : :obj:`int` Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (It is the same for population or individual variables.) **acceptation_history** : :class:`torch.Tensor` History of binary acceptations to compute mean acceptation rate for the sampler in MCMC-SAEM algorithm. It keeps the history of the last `acceptation_history_length` steps. .. !! processed by numpydoc !! .. py:attribute:: n_patients .. py:class:: AbstractPopulationSampler(name, shape, *, acceptation_history_length = 25, mask = None) Bases: :py:obj:`AbstractSampler` Abstract class for samplers of population random variables. :Parameters: **name** : :obj:`str` The name of the random variable to sample. **shape** : :obj:`tuple` of :obj:`int` The shape of the random variable to sample. **acceptation_history_length** : :obj:`int` > 0 (default 25) Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (It is the same for population or individual variables.) **mask** : :class:`torch.Tensor`, optional A binary (0/1) tensor indicating which elements to sample. Elements with value 1 (True) are included in the sampling; elements with 0 (False) are excluded. :Attributes: **name** : :obj:`str` Name of variable **shape** : :obj:`tuple` of :obj:`int` Shape of variable **acceptation_history_length** : :obj:`int` Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (It is the same for population or individual variables.) **acceptation_history** : :class:`torch.Tensor` History of binary acceptations to compute mean acceptation rate for the sampler in MCMC-SAEM algorithm. It keeps the history of the last `acceptation_history_length` steps. **mask** : :class:`torch.Tensor` of :obj:`bool`, optional A binary (0/1) tensor indicating which elements to sample. Elements with value 1 (True) are included in the sampling; elements with 0 (False) are excluded. .. !! processed by numpydoc !! .. py:attribute:: mask :value: None