leaspy.samplers.base

Classes

AbstractSampler

Abstract sampler class.

AbstractIndividualSampler

Abstract class for samplers of individual random variables.

AbstractPopulationSampler

Abstract class for samplers of population random variables.

Module Contents

class AbstractSampler(name, shape, *, acceptation_history_length=25)[source]

Bases: abc.ABC

Abstract sampler class.

Parameters:
namestr

The name of the random variable to sample.

shapetuple of int

The shape of the random variable to sample.

acceptation_history_lengthint > 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:
namestr

Name of variable

shapetuple of int

Shape of variable

acceptation_history_lengthint

Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (Same for population or individual variables by default.)

acceptation_historytorch.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:
LeaspyModelInputError
Parameters:
  • name (str)

  • shape (Tuple[int, Ellipsis])

  • acceptation_history_length (int)

name
shape
acceptation_history_length = 25
acceptation_history
property ndim: int

Number of dimensions.

Return type:

int

property shape_acceptation: Tuple[int, Ellipsis]
Abstractmethod:

Return type:

Tuple[int, Ellipsis]

Return the shape of acceptation tensor for a single iteration.

Returns:
tuple of int

The shape of the acceptation history.

Return type:

Tuple[int, Ellipsis]

abstractmethod sample(state, *, temperature_inv)[source]

Apply a sampling step

<!> It will modify in-place the internal state, caching all intermediate values needed to efficient.

Parameters:
stateState

Object containing values for all model variables, including latent variables

temperature_invfloat > 0

Inverse of the temperature used in tempered MCMC-SAEM

Parameters:
Return type:

None

class AbstractIndividualSampler(name, shape, *, n_patients, acceptation_history_length=25)[source]

Bases: AbstractSampler

Abstract class for samplers of individual random variables.

Parameters:
namestr

The name of the random variable to sample.

shapetuple of int

The shape of the random variable to sample.

n_patientsint

Number of patients.

acceptation_history_lengthint > 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:
namestr

Name of variable

shapetuple of int

Shape of variable

n_patientsint

Number of patients.

acceptation_history_lengthint

Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (It is the same for population or individual variables.)

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

Parameters:
  • name (str)

  • shape (Tuple[int, Ellipsis])

  • n_patients (int)

  • acceptation_history_length (int)

n_patients
class AbstractPopulationSampler(name, shape, *, acceptation_history_length=25, mask=None)[source]

Bases: AbstractSampler

Abstract class for samplers of population random variables.

Parameters:
namestr

The name of the random variable to sample.

shapetuple of int

The shape of the random variable to sample.

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

masktorch.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:
namestr

Name of variable

shapetuple of int

Shape of variable

acceptation_history_lengthint

Deepness (= number of iterations) of the history kept for computing the mean acceptation rate. (It is the same for population or individual variables.)

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

masktorch.Tensor of 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.

Parameters:
  • name (str)

  • shape (Tuple[int, Ellipsis])

  • acceptation_history_length (int)

  • mask (Optional[Tensor])

mask = None