some minor edit to Bernoulli

This commit is contained in:
James Hensman 2013-12-12 02:27:20 -08:00
parent 12c3877b50
commit cd3bcee11c

View file

@ -1,4 +1,4 @@
# Copyright (c) 2012, 2013 The GPy authors # Copyright (c) 2012, 2013 The GPy authors (see AUTHORS.txt)
# Licensed under the BSD 3-clause license (see LICENSE.txt) # Licensed under the BSD 3-clause license (see LICENSE.txt)
import numpy as np import numpy as np
@ -16,8 +16,8 @@ class Bernoulli(Likelihood):
p(y_{i}|\\lambda(f_{i})) = \\lambda(f_{i})^{y_{i}}(1-f_{i})^{1-y_{i}} p(y_{i}|\\lambda(f_{i})) = \\lambda(f_{i})^{y_{i}}(1-f_{i})^{1-y_{i}}
.. Note:: .. Note::
Y is expected to take values in {-1, 1} Y is expected to take values in {-1, 1} TODO: {0, 1}??
Probit likelihood usually used link function should have the domain [0, 1], e.g. probit (default) or Heaviside
.. See also:: .. See also::
likelihood.py, for the parent class likelihood.py, for the parent class
@ -68,9 +68,8 @@ class Bernoulli(Likelihood):
N = std_norm_pdf(a) N = std_norm_pdf(a)
mu_hat = v_i/tau_i + sign*N/Z_hat/np.sqrt(tau_i) mu_hat = v_i/tau_i + sign*N/Z_hat/np.sqrt(tau_i)
sigma2_hat = (1. - a*N/Z_hat - np.square(N/Z_hat))/tau_i sigma2_hat = (1. - a*N/Z_hat - np.square(N/Z_hat))/tau_i
if np.any(np.isnan([Z_hat, mu_hat, sigma2_hat])):
stop
else: else:
#TODO: do we want to revert to numerical quadrature here?
raise ValueError("Exact moment matching not available for link {}".format(self.gp_link.__name__)) raise ValueError("Exact moment matching not available for link {}".format(self.gp_link.__name__))
return Z_hat, mu_hat, sigma2_hat return Z_hat, mu_hat, sigma2_hat
@ -198,19 +197,6 @@ class Bernoulli(Likelihood):
d3logpdf_dlink3 = 2*(y/(link_f**3) - (1-y)/((1-link_f)**3)) d3logpdf_dlink3 = 2*(y/(link_f**3) - (1-y)/((1-link_f)**3))
return d3logpdf_dlink3 return d3logpdf_dlink3
def _mean(self, gp):
"""
Mass (or density) function
"""
return self.gp_link.transf(gp)
def _variance(self, gp):
"""
Mass (or density) function
"""
p = self.gp_link.transf(gp)
return p*(1.-p)
def samples(self, gp): def samples(self, gp):
""" """
Returns a set of samples of observations based on a given value of the latent variable. Returns a set of samples of observations based on a given value of the latent variable.