GPy.likelihoods package¶
Submodules¶
GPy.likelihoods.bernoulli module¶
-
class
GPy.likelihoods.bernoulli.Bernoulli(gp_link=None)[source]¶ Bases:
GPy.likelihoods.likelihood.LikelihoodBernoulli likelihood

Note
Y takes values in either {-1, 1} or {0, 1}. link function should have the domain [0, 1], e.g. probit (default) or Heaviside
-
d2logpdf_dlink2(inv_link_f, y, Y_metadata=None)[source]¶ Hessian at y, given inv_link_f, w.r.t inv_link_f the hessian will be 0 unless i == j i.e. second derivative logpdf at y given inverse link of f_i and inverse link of f_j w.r.t inverse link of f_i and inverse link of f_j.

Parameters: - inv_link_f (Nx1 array) – latent variables inverse link of f.
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in bernoulli
Returns: Diagonal of log hessian matrix (second derivative of log likelihood evaluated at points inverse link of f.
Return type: Nx1 array
Note
Will return diagonal of hessian, since every where else it is 0, as the likelihood factorizes over cases (the distribution for y_i depends only on inverse link of f_i not on inverse link of f_(j!=i)
-
d3logpdf_dlink3(inv_link_f, y, Y_metadata=None)[source]¶ Third order derivative log-likelihood function at y given inverse link of f w.r.t inverse link of f

Parameters: - inv_link_f (Nx1 array) – latent variables passed through inverse link of f.
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in bernoulli
Returns: third derivative of log likelihood evaluated at points inverse_link(f)
Return type: Nx1 array
-
dlogpdf_dlink(inv_link_f, y, Y_metadata=None)[source]¶ Gradient of the pdf at y, given inverse link of f w.r.t inverse link of f.

Parameters: - inv_link_f (Nx1 array) – latent variables inverse link of f.
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in bernoulli
Returns: gradient of log likelihood evaluated at points inverse link of f.
Return type: Nx1 array
-
logpdf_link(inv_link_f, y, Y_metadata=None)[source]¶ Log Likelihood function given inverse link of f.

Parameters: - inv_link_f (Nx1 array) – latent variables inverse link of f.
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in bernoulli
Returns: log likelihood evaluated at points inverse link of f.
Return type: float
-
moments_match_ep(Y_i, tau_i, v_i)[source]¶ Moments match of the marginal approximation in EP algorithm
Parameters: - i – number of observation (int)
- tau_i – precision of the cavity distribution (float)
- v_i – mean/variance of the cavity distribution (float)
-
GPy.likelihoods.exponential module¶
-
class
GPy.likelihoods.exponential.Exponential(gp_link=None)[source]¶ Bases:
GPy.likelihoods.likelihood.LikelihoodExpoential likelihood Y is expected to take values in {0,1,2,...} —– $$ L(x) = exp(lambda) * lambda**Y_i / Y_i! $$
-
d2logpdf_dlink2(link_f, y, Y_metadata=None)[source]¶ Hessian at y, given link(f), w.r.t link(f) i.e. second derivative logpdf at y given link(f_i) and link(f_j) w.r.t link(f_i) and link(f_j) The hessian will be 0 unless i == j

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in exponential distribution
Returns: Diagonal of hessian matrix (second derivative of likelihood evaluated at points f)
Return type: Nx1 array
Note
Will return diagonal of hessian, since every where else it is 0, as the likelihood factorizes over cases (the distribution for y_i depends only on link(f_i) not on link(f_(j!=i))
-
d3logpdf_dlink3(link_f, y, Y_metadata=None)[source]¶ Third order derivative log-likelihood function at y given link(f) w.r.t link(f)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in exponential distribution
Returns: third derivative of likelihood evaluated at points f
Return type: Nx1 array
-
dlogpdf_dlink(link_f, y, Y_metadata=None)[source]¶ Gradient of the log likelihood function at y, given link(f) w.r.t link(f)

Parameters: - link_f (Nx1 array) – latent variables (f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in exponential distribution
Returns: gradient of likelihood evaluated at points
Return type: Nx1 array
-
logpdf_link(link_f, y, Y_metadata=None)[source]¶ Log Likelihood Function given link(f)

Parameters: - link_f (Nx1 array) – latent variables (link(f))
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in exponential distribution
Returns: likelihood evaluated for this point
Return type: float
-
GPy.likelihoods.gamma module¶
-
class
GPy.likelihoods.gamma.Gamma(gp_link=None, beta=1.0)[source]¶ Bases:
GPy.likelihoods.likelihood.LikelihoodGamma likelihood

-
d2logpdf_dlink2(link_f, y, Y_metadata=None)[source]¶ Hessian at y, given link(f), w.r.t link(f) i.e. second derivative logpdf at y given link(f_i) and link(f_j) w.r.t link(f_i) and link(f_j) The hessian will be 0 unless i == j

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in gamma distribution
Returns: Diagonal of hessian matrix (second derivative of likelihood evaluated at points f)
Return type: Nx1 array
Note
Will return diagonal of hessian, since every where else it is 0, as the likelihood factorizes over cases (the distribution for y_i depends only on link(f_i) not on link(f_(j!=i))
-
d3logpdf_dlink3(link_f, y, Y_metadata=None)[source]¶ Third order derivative log-likelihood function at y given link(f) w.r.t link(f)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in gamma distribution
Returns: third derivative of likelihood evaluated at points f
Return type: Nx1 array
-
dlogpdf_dlink(link_f, y, Y_metadata=None)[source]¶ Gradient of the log likelihood function at y, given link(f) w.r.t link(f)

Parameters: - link_f (Nx1 array) – latent variables (f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in gamma distribution
Returns: gradient of likelihood evaluated at points
Return type: Nx1 array
-
GPy.likelihoods.gaussian module¶
A lot of this code assumes that the link function is the identity.
I think laplace code is okay, but I’m quite sure that the EP moments will only work if the link is identity.
Furthermore, exact Guassian inference can only be done for the identity link, so we should be asserting so for all calls which relate to that.
James 11/12/13
-
class
GPy.likelihoods.gaussian.Gaussian(gp_link=None, variance=1.0, name='Gaussian_noise')[source]¶ Bases:
GPy.likelihoods.likelihood.LikelihoodGaussian likelihood

Parameters: - variance – variance value of the Gaussian distribution
- N (int) – Number of data points
-
d2logpdf_dlink2(link_f, y, Y_metadata=None)[source]¶ Hessian at y, given link_f, w.r.t link_f. i.e. second derivative logpdf at y given link(f_i) link(f_j) w.r.t link(f_i) and link(f_j)
The hessian will be 0 unless i == j

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in gaussian
Returns: Diagonal of log hessian matrix (second derivative of log likelihood evaluated at points link(f))
Return type: Nx1 array
Note
Will return diagonal of hessian, since every where else it is 0, as the likelihood factorizes over cases (the distribution for y_i depends only on link(f_i) not on link(f_(j!=i))
-
d2logpdf_dlink2_dvar(link_f, y, Y_metadata=None)[source]¶ Gradient of the hessian (d2logpdf_dlink2) w.r.t variance parameter (noise_variance)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in gaussian
Returns: derivative of log hessian evaluated at points link(f_i) and link(f_j) w.r.t variance parameter
Return type: Nx1 array
-
d3logpdf_dlink3(link_f, y, Y_metadata=None)[source]¶ Third order derivative log-likelihood function at y given link(f) w.r.t link(f)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in gaussian
Returns: third derivative of log likelihood evaluated at points link(f)
Return type: Nx1 array
-
dlogpdf_dlink(link_f, y, Y_metadata=None)[source]¶ Gradient of the pdf at y, given link(f) w.r.t link(f)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in gaussian
Returns: gradient of log likelihood evaluated at points link(f)
Return type: Nx1 array
-
dlogpdf_dlink_dvar(link_f, y, Y_metadata=None)[source]¶ Derivative of the dlogpdf_dlink w.r.t variance parameter (noise_variance)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in gaussian
Returns: derivative of log likelihood evaluated at points link(f) w.r.t variance parameter
Return type: Nx1 array
-
dlogpdf_link_dvar(link_f, y, Y_metadata=None)[source]¶ Gradient of the log-likelihood function at y given link(f), w.r.t variance parameter (noise_variance)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in gaussian
Returns: derivative of log likelihood evaluated at points link(f) w.r.t variance parameter
Return type: float
-
logpdf_link(link_f, y, Y_metadata=None)[source]¶ Log likelihood function given link(f)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in gaussian
Returns: log likelihood evaluated for this point
Return type: float
-
pdf_link(link_f, y, Y_metadata=None)[source]¶ Likelihood function given link(f)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata not used in gaussian
Returns: likelihood evaluated for this point
Return type: float
GPy.likelihoods.likelihood module¶
-
class
GPy.likelihoods.likelihood.Likelihood(gp_link, name)[source]¶ Bases:
GPy.core.parameterization.parameterized.ParameterizedLikelihood base class, used to defing p(y|f).
All instances use _inverse_ link functions, which can be swapped out. It is expected that inheriting classes define a default inverse link function
To use this class, inherit and define missing functionality.
- Inheriting classes must implement:
- pdf_link : a bound method which turns the output of the link function into the pdf logpdf_link : the logarithm of the above
- To enable use with EP, inheriting classes must define:
- TODO: a suitable derivative function for any parameters of the class
- It is also desirable to define:
- moments_match_ep : a function to compute the EP moments If this isn’t defined, the moments will be computed using 1D quadrature.
- To enable use with Laplace approximation, inheriting classes must define:
- Some derivative functions AS TODO
For exact Gaussian inference, define JH TODO
-
conditional_variance(gp)[source]¶ The variance of the random variable conditioned on one value of the GP
-
d2logpdf_df2(f, y, Y_metadata=None)[source]¶ Evaluates the link function link(f) then computes the second derivative of log likelihood using it Uses the Faa di Bruno’s formula for the chain rule

Parameters: - f (Nx1 array) – latent variables f
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution - not used
Returns: second derivative of log likelihood evaluated for this point (diagonal only)
Return type: 1xN array
-
d3logpdf_df3(f, y, Y_metadata=None)[source]¶ Evaluates the link function link(f) then computes the third derivative of log likelihood using it Uses the Faa di Bruno’s formula for the chain rule

Parameters: - f (Nx1 array) – latent variables f
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution - not used
Returns: third derivative of log likelihood evaluated for this point
Return type: float
-
dlogpdf_df(f, y, Y_metadata=None)[source]¶ Evaluates the link function link(f) then computes the derivative of log likelihood using it Uses the Faa di Bruno’s formula for the chain rule

Parameters: - f (Nx1 array) – latent variables f
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution - not used
Returns: derivative of log likelihood evaluated for this point
Return type: 1xN array
-
log_predictive_density(y_test, mu_star, var_star)[source]¶ Calculation of the log predictive density
Parameters: - y_test ((Nx1) array) – test observations (y_{*})
- mu_star ((Nx1) array) – predictive mean of gaussian p(f_{*}|mu_{*}, var_{*})
- var_star ((Nx1) array) – predictive variance of gaussian p(f_{*}|mu_{*}, var_{*})
-
logpdf(f, y, Y_metadata=None)[source]¶ Evaluates the link function link(f) then computes the log likelihood (log pdf) using it
Parameters: - f (Nx1 array) – latent variables f
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution - not used
Returns: log likelihood evaluated for this point
Return type: float
-
pdf(f, y, Y_metadata=None)[source]¶ Evaluates the link function link(f) then computes the likelihood (pdf) using it
Parameters: - f (Nx1 array) – latent variables f
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution - not used
Returns: likelihood evaluated for this point
Return type: float
-
predictive_mean(mu, variance, Y_metadata=None)[source]¶ Quadrature calculation of the predictive mean: E(Y_star|Y) = E( E(Y_star|f_star, Y) )
Parameters: - mu – mean of posterior
- sigma – standard deviation of posterior
-
predictive_values(mu, var, full_cov=False, Y_metadata=None)[source]¶ Compute mean, variance of the predictive distibution.
Parameters: - mu – mean of the latent variable, f, of posterior
- var – variance of the latent variable, f, of posterior
- full_cov (Boolean) – whether to use the full covariance or just the diagonal
-
predictive_variance(mu, variance, predictive_mean=None, Y_metadata=None)[source]¶ Approximation to the predictive variance: V(Y_star)
The following variance decomposition is used: V(Y_star) = E( V(Y_star|f_star) ) + V( E(Y_star|f_star) )
Parameters: - mu – mean of posterior
- sigma – standard deviation of posterior
Predictive_mean: output’s predictive mean, if None _predictive_mean function will be called.
-
samples(gp, Y_metadata=None)[source]¶ Returns a set of samples of observations based on a given value of the latent variable.
Parameters: gp – latent variable
-
variational_expectations(Y, m, v, gh_points=None)[source]¶ Use Gauss-Hermite Quadrature to compute
E_p(f) [ log p(y|f) ] d/dm E_p(f) [ log p(y|f) ] d/dv E_p(f) [ log p(y|f) ]where p(f) is a Gaussian with mean m and variance v. The shapes of Y, m and v should match.
if no gh_points are passed, we construct them using defualt options
GPy.likelihoods.link_functions module¶
-
class
GPy.likelihoods.link_functions.Cloglog[source]¶ Bases:
GPy.likelihoods.link_functions.GPTransformationComplementary log-log link .. math:
p(f) = 1 - e^{-e^f} or f = \log (-\log(1-p))
-
class
GPy.likelihoods.link_functions.GPTransformation[source]¶ Bases:
objectLink function class for doing non-Gaussian likelihoods approximation
Parameters: Y – observed output (Nx1 numpy.darray) Note
Y values allowed depend on the likelihood_function used
-
class
GPy.likelihoods.link_functions.Heaviside[source]¶ Bases:
GPy.likelihoods.link_functions.GPTransformation
-
class
GPy.likelihoods.link_functions.Identity[source]¶ Bases:
GPy.likelihoods.link_functions.GPTransformation
-
class
GPy.likelihoods.link_functions.Log[source]¶ Bases:
GPy.likelihoods.link_functions.GPTransformation
-
class
GPy.likelihoods.link_functions.Log_ex_1[source]¶ Bases:
GPy.likelihoods.link_functions.GPTransformation
-
class
GPy.likelihoods.link_functions.Probit[source]¶ Bases:
GPy.likelihoods.link_functions.GPTransformation
GPy.likelihoods.mixed_noise module¶
-
class
GPy.likelihoods.mixed_noise.MixedNoise(likelihoods_list, name='mixed_noise')[source]¶
GPy.likelihoods.poisson module¶
-
class
GPy.likelihoods.poisson.Poisson(gp_link=None)[source]¶ Bases:
GPy.likelihoods.likelihood.LikelihoodPoisson likelihood

Note
Y is expected to take values in {0,1,2,...}
-
conditional_variance(gp)[source]¶ The variance of the random variable conditioned on one value of the GP
-
d2logpdf_dlink2(link_f, y, Y_metadata=None)[source]¶ Hessian at y, given link(f), w.r.t link(f) i.e. second derivative logpdf at y given link(f_i) and link(f_j) w.r.t link(f_i) and link(f_j) The hessian will be 0 unless i == j

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in poisson distribution
Returns: Diagonal of hessian matrix (second derivative of likelihood evaluated at points f)
Return type: Nx1 array
Note
Will return diagonal of hessian, since every where else it is 0, as the likelihood factorizes over cases (the distribution for y_i depends only on link(f_i) not on link(f_(j!=i))
-
d3logpdf_dlink3(link_f, y, Y_metadata=None)[source]¶ Third order derivative log-likelihood function at y given link(f) w.r.t link(f)

Parameters: - link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in poisson distribution
Returns: third derivative of likelihood evaluated at points f
Return type: Nx1 array
-
dlogpdf_dlink(link_f, y, Y_metadata=None)[source]¶ Gradient of the log likelihood function at y, given link(f) w.r.t link(f)

Parameters: - link_f (Nx1 array) – latent variables (f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in poisson distribution
Returns: gradient of likelihood evaluated at points
Return type: Nx1 array
-
logpdf_link(link_f, y, Y_metadata=None)[source]¶ Log Likelihood Function given link(f)

Parameters: - link_f (Nx1 array) – latent variables (link(f))
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in poisson distribution
Returns: likelihood evaluated for this point
Return type: float
-
GPy.likelihoods.student_t module¶
-
class
GPy.likelihoods.student_t.StudentT(gp_link=None, deg_free=5, sigma2=2)[source]¶ Bases:
GPy.likelihoods.likelihood.LikelihoodStudent T likelihood
For nomanclature see Bayesian Data Analysis 2003 p576

-
d2logpdf_dlink2(inv_link_f, y, Y_metadata=None)[source]¶ Hessian at y, given link(f), w.r.t link(f) i.e. second derivative logpdf at y given link(f_i) and link(f_j) w.r.t link(f_i) and link(f_j) The hessian will be 0 unless i == j

Parameters: - inv_link_f (Nx1 array) – latent variables inv_link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution
Returns: Diagonal of hessian matrix (second derivative of likelihood evaluated at points f)
Return type: Nx1 array
Note
Will return diagonal of hessian, since every where else it is 0, as the likelihood factorizes over cases (the distribution for y_i depends only on link(f_i) not on link(f_(j!=i))
-
d2logpdf_dlink2_dvar(inv_link_f, y, Y_metadata=None)[source]¶ Gradient of the hessian (d2logpdf_dlink2) w.r.t variance parameter (t_noise)

Parameters: - inv_link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution
Returns: derivative of hessian evaluated at points f and f_j w.r.t variance parameter
Return type: Nx1 array
-
d3logpdf_dlink3(inv_link_f, y, Y_metadata=None)[source]¶ Third order derivative log-likelihood function at y given link(f) w.r.t link(f)

Parameters: - inv_link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution
Returns: third derivative of likelihood evaluated at points f
Return type: Nx1 array
-
dlogpdf_dlink(inv_link_f, y, Y_metadata=None)[source]¶ Gradient of the log likelihood function at y, given link(f) w.r.t link(f)

Parameters: - inv_link_f (Nx1 array) – latent variables (f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution
Returns: gradient of likelihood evaluated at points
Return type: Nx1 array
-
dlogpdf_dlink_dvar(inv_link_f, y, Y_metadata=None)[source]¶ Derivative of the dlogpdf_dlink w.r.t variance parameter (t_noise)

Parameters: - inv_link_f (Nx1 array) – latent variables inv_link_f
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution
Returns: derivative of likelihood evaluated at points f w.r.t variance parameter
Return type: Nx1 array
-
dlogpdf_link_dvar(inv_link_f, y, Y_metadata=None)[source]¶ Gradient of the log-likelihood function at y given f, w.r.t variance parameter (t_noise)

Parameters: - inv_link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution
Returns: derivative of likelihood evaluated at points f w.r.t variance parameter
Return type: float
-
logpdf_link(inv_link_f, y, Y_metadata=None)[source]¶ Log Likelihood Function given link(f)

Parameters: - inv_link_f (Nx1 array) – latent variables (link(f))
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution
Returns: likelihood evaluated for this point
Return type: float
-
pdf_link(inv_link_f, y, Y_metadata=None)[source]¶ Likelihood function given link(f)

Parameters: - inv_link_f (Nx1 array) – latent variables link(f)
- y (Nx1 array) – data
- Y_metadata – Y_metadata which is not used in student t distribution
Returns: likelihood evaluated for this point
Return type: float
-

