aepsych.likelihoods

aepsych.likelihoods module

class aepsych.likelihoods.BernoulliObjectiveLikelihood(objective)[source]

Bases: _OneDimensionalLikelihood

Bernoulli likelihood with a flexible link (objective) defined by a callable (which can be a botorch objective)

Initialize BernoulliObjectiveLikelihood.

Parameters:

objective (Callable) – Objective function that maps function samples to probabilities.

forward(function_samples, **kwargs)[source]

Forward pass for BernoulliObjectiveLikelihood.

Parameters:
  • function_samples (torch.Tensor) – Function samples.

  • kwargs (Any) –

Returns:

Bernoulli distribution object.

Return type:

torch.distributions.Bernoulli

classmethod from_config(config)[source]

Create an instance from a configuration object.

Parameters:

config (Config) – Configuration object.

Returns:

BernoulliObjectiveLikelihood instance.

Return type:

BernoulliObjectiveLikelihood

class aepsych.likelihoods.OrdinalLikelihood(n_levels, link=None)[source]

Bases: Likelihood

Ordinal likelihood, suitable for rating models (e.g. likert scales). Formally, .. math:: z_k(xmid f) := p(d_k < f(x) le d_{k+1}) = sigma(d_{k+1}-f(x)) - sigma(d_{k}-f(x)), where \(\sigma()\) is the link function (equivalent to the perceptual noise distribution in psychophysics terms), \(f(x)\) is the latent GP evaluated at x, and \(d_k\) is a learned cutpoint parameter for each level.

Initialize OrdinalLikelihood.

Parameters:
  • n_levels (int) – Number of levels in the ordinal scale.

  • link (Callable, optional) – Link function. Defaults to None.

property cutpoints: Tensor
forward(function_samples, *params, **kwargs)[source]

Forward pass for Ordinal

Parameters:

function_samples (torch.Tensor) – Function samples.

Returns:

Categorical distribution object.

Return type:

Categorical

classmethod from_config(config)[source]

Creates an instance fron configuration object

Parameters:

config (Config) – Configuration object.

Returns:

OrdinalLikelihood instance

Return type:

OrdinalLikelihood

class aepsych.likelihoods.LinearBernoulliLikelihood(objective=None)[source]

Bases: _OneDimensionalLikelihood

A likelihood of the form Bernoulli(sigma(k(x+c))), where k and c are GPs and sigma is a flexible link function.

Initializes the linear bernoulli likelihood.

Parameters:

objective (AEPsychObjective, optional) – Link function to use (sigma in the notation above). Defaults to probit with no floor.

f(function_samples, Xi)[source]

Return the latent function value, k(x-c).

Parameters:
  • function_samples (torch.Tensor) – Samples from a batched GP

  • Xi (torch.Tensor) – Intensity values.

Returns:

latent function value.

Return type:

torch.Tensor

p(function_samples, Xi)[source]

Returns the response probability sigma(k(x+c)).

Parameters:
  • function_samples (torch.Tensor) – Samples from the batched GP (see documentation for self.f)

  • Xi (torch.Tensor) – Intensity Values.

Returns:

Response probabilities.

Return type:

torch.Tensor

forward(function_samples, Xi, **kwargs)[source]

Forward pass for the likelihood

Parameters:
  • function_samples (torch.Tensor) – Samples from a batched GP of batch size 2.

  • Xi (torch.Tensor) – Intensity values.

Returns:

Outcome likelihood.

Return type:

torch.distributions.Bernoulli

expected_log_prob(observations, function_dist, *args, **kwargs)[source]

This has to be overridden to fix a bug in gpytorch where the kwargs aren’t being passed along to self.forward.

Parameters:
  • observations (torch.Tensor) – Observations.

  • function_dist (torch.Tensor) – Function distribution.

Returns:

Expected log probability.

Return type:

torch.Tensor

classmethod from_config(config)[source]

Create an instance from a configuration object.

Parameters:

config (Config) – Configuration object.

Returns:

LinearBernoulliLikelihood instance.

Return type:

LinearBernoulliLikelihood