Likelihood ClassesΒΆ

Bernoulli Bernoulli likelihood class for (binary) classification tasks.
Binomial Binomial likelihood class.
Gaussian([var, bounds, shape]) A univariate Gaussian likelihood for general regression tasks.
Poisson([tranfcn]) A Poisson likelihood, useful for various Poisson process tasks.

Likelihood objects for inference within the GLM framework.

class revrand.likelihoods.Bernoulli

Bernoulli likelihood class for (binary) classification tasks.

A logistic transformation function is used to map the latent function from the GLM prior into a probability.

\[p(y_i | f_i) = \sigma(f_i) ^ {y_i} (1 - \sigma(f_i))^{1 - y_i}\]

where \(y_i\) is a target, \(f_i\) the value of the latent function corresponding to the target, and \(\sigma(\cdot)\) is the logistic sigmoid.

Ey(f)

Expected value of the Bernoulli likelihood.

Parameters:f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:Ey – expected value of y, \(\mathbb{E}[\mathbf{y}|\mathbf{f}]\).
Return type:ndarray
cdf(y, f)

Cumulative density function of the likelihood.

Parameters:
  • y (ndarray) – query quantiles, i.e. \(P(Y \leq y)\).
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:

cdf – Cumulative density function evaluated at y.

Return type:

ndarray

df(y, f)

Derivative of Bernoulli log likelihood w.r.t. f.

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:

df – the derivative \(\partial \log p(y|f) / \partial f\)

Return type:

ndarray

dp(y, f, *args)

Derivative of Bernoulli log likelihood w.r.t.the parameters, \(\theta\).

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:

dp – the derivative \(\partial \log p(y|f, \theta)/ \partial \theta\) for each parameter. If there is only one parameter, this is not a list.

Return type:

list, float or ndarray

loglike(y, f)

Bernoulli log likelihood.

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:

logp – the log likelihood of each y given each f under this likelihood.

Return type:

ndarray

params

Get this object’s Parameter types.

class revrand.likelihoods.Binomial

Binomial likelihood class.

A logistic transformation function is used to map the latent function from the GLM prior into a probability.

\[p(y_i | f_i) = \genfrac(){0pt}{}{n}{y_i} \sigma(f_i) ^ {y_i} (1 - \sigma(f_i))^{n - y_i}\]

where \(y_i\) is a target, \(f_i\) the value of the latent function corresponding to the target, \(n\) is the total possible count, and \(\sigma(\cdot)\) is the logistic sigmoid. \(n\) can also be applied per observation.

Ey(f, n)

Expected value of the Binomial likelihood.

Parameters:
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • n (ndarray) – the total number of observations
Returns:

Ey – expected value of y, \(\mathbb{E}[\mathbf{y}|\mathbf{f}]\).

Return type:

ndarray

cdf(y, f, n)

Cumulative density function of the likelihood.

Parameters:
  • y (ndarray) – query quantiles, i.e. \(P(Y \leq y)\).
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • n (ndarray) – the total number of observations
Returns:

cdf – Cumulative density function evaluated at y.

Return type:

ndarray

df(y, f, n)

Derivative of Binomial log likelihood w.r.t. f.

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • n (ndarray) – the total number of observations
Returns:

df – the derivative \(\partial \log p(y|f) / \partial f\)

Return type:

ndarray

loglike(y, f, n)

Binomial log likelihood.

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • n (ndarray) – the total number of observations
Returns:

logp – the log likelihood of each y given each f under this likelihood.

Return type:

ndarray

class revrand.likelihoods.Gaussian(var=Parameter(value=1.0, bounds=Positive(upper=None), shape=()))

A univariate Gaussian likelihood for general regression tasks.

No transformation function is needed since this is (conditionally) conjugate to the GLM prior.

\[p(y_i | f_i) = \frac{1}{\sqrt{2 \pi \sigma^2}} \exp\left(- \frac{(y_i - f_i)^2}{2 \sigma^2} \right)\]

where \(y_i\) is a target, \(f_i\) the value of the latent function corresponding to the target and \(\sigma\) is the observation noise (standard deviation).

Parameters:var (Parameter, optional) – A scalar Parameter describing the initial point and bounds for an optimiser to learn the variance parameter of this object.
Ey(f, var)

Expected value of the Gaussian likelihood.

Parameters:
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • var (float, ndarray, optional) – The variance of the distribution, if not input, the initial value of variance is used.
Returns:

Ey – expected value of y, \(\mathbb{E}[\mathbf{y}|\mathbf{f}]\).

Return type:

ndarray

cdf(y, f, var)

Cumulative density function of the likelihood.

Parameters:
  • y (ndarray) – query quantiles, i.e. \(P(Y \leq y)\).
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • var (float, ndarray, optional) – The variance of the distribution, if not input, the initial value of variance is used.
Returns:

cdf – Cumulative density function evaluated at y.

Return type:

ndarray

df(y, f, var)

Derivative of Gaussian log likelihood w.r.t. f.

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • var (float, ndarray, optional) – The variance of the distribution, if not input, the initial value of variance is used.
Returns:

df – the derivative \(\partial \log p(y|f) / \partial f\)

Return type:

ndarray

dp(y, f, var)

Derivative of Gaussian log likelihood w.r.t.the variance \(\sigma^2\).

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • var (float, ndarray, optional) – The variance of the distribution, if not input, the initial value of variance is used.
Returns:

dp – the derivative \(\partial \log p(y|f, \sigma^2)/ \partial \sigma^2\) where \(sigma^2\) is the variance.

Return type:

float

loglike(y, f, var=None)

Gaussian log likelihood.

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
  • var (float, ndarray, optional) – The variance of the distribution, if not input, the initial value of variance is used.
Returns:

logp – the log likelihood of each y given each f under this likelihood.

Return type:

ndarray

class revrand.likelihoods.Poisson(tranfcn='exp')

A Poisson likelihood, useful for various Poisson process tasks.

An exponential transformation function and a softplus transformation function have been implemented.

\[p(y_i | f_i) = \frac{g(f_i)^{y_i} e^{-g(f_i)}}{y_i!}\]

where \(y_i\) is a target, \(f_i\) the value of the latent function corresponding to the target, and \(g(\cdot)\) is the tranformation function, which can be either an exponential function, or a softplus function (\(\log(1 + \exp(f_i)\)).

Parameters:tranfcn (string, optional) – this may be ‘exp’ for an exponential transformation function, or ‘softplus’ for a softplut transformation function.
Ey(f)

Expected value of the Poisson likelihood.

Parameters:f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:Ey – expected value of y, \(\mathbb{E}[\mathbf{y}|\mathbf{f}]\).
Return type:ndarray
cdf(y, f)

Cumulative density function of the likelihood.

Parameters:
  • y (ndarray) – query quantiles, i.e. \(P(Y \leq y)\).
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:

cdf – Cumulative density function evaluated at y.

Return type:

ndarray

df(y, f)

Derivative of Poisson log likelihood w.r.t. f.

Parameters:
  • y (ndarray) – array of 0, 1 valued integers of targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:

df – the derivative \(\partial \log p(y|f) / \partial f\)

Return type:

ndarray

loglike(y, f)

Poisson log likelihood.

Parameters:
  • y (ndarray) – array of integer targets
  • f (ndarray) – latent function from the GLM prior (\(\mathbf{f} = \boldsymbol\Phi \mathbf{w}\))
Returns:

logp – the log likelihood of each y given each f under this likelihood.

Return type:

ndarray