mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-05 17:52:39 +02:00
work on likeluhoods and likelihoods tests
This commit is contained in:
parent
5cf792504a
commit
2876e5a07a
11 changed files with 186 additions and 222 deletions
|
|
@ -18,13 +18,12 @@ class Exponential(Likelihood):
|
|||
L(x) = \exp(\lambda) * \lambda**Y_i / Y_i!
|
||||
$$
|
||||
"""
|
||||
def __init__(self,gp_link=None,analytical_mean=False,analytical_variance=False):
|
||||
super(Exponential, self).__init__(gp_link,analytical_mean,analytical_variance)
|
||||
def __init__(self,gp_link=None):
|
||||
if gp_link is None:
|
||||
gp_link = link_functions.Log()
|
||||
super(Exponential, self).__init__(gp_link, 'ExpLikelihood')
|
||||
|
||||
def _preprocess_values(self,Y):
|
||||
return Y
|
||||
|
||||
def pdf_link(self, link_f, y, extra_data=None):
|
||||
def pdf_link(self, link_f, y, Y_metadata=None):
|
||||
"""
|
||||
Likelihood function given link(f)
|
||||
|
||||
|
|
@ -35,16 +34,15 @@ class Exponential(Likelihood):
|
|||
:type link_f: Nx1 array
|
||||
:param y: data
|
||||
:type y: Nx1 array
|
||||
:param extra_data: extra_data which is not used in exponential distribution
|
||||
:param Y_metadata: Y_metadata which is not used in exponential distribution
|
||||
:returns: likelihood evaluated for this point
|
||||
:rtype: float
|
||||
"""
|
||||
assert np.atleast_1d(link_f).shape == np.atleast_1d(y).shape
|
||||
log_objective = link_f*np.exp(-y*link_f)
|
||||
return np.exp(np.sum(np.log(log_objective)))
|
||||
#return np.exp(np.sum(-y/link_f - np.log(link_f) ))
|
||||
|
||||
def logpdf_link(self, link_f, y, extra_data=None):
|
||||
def logpdf_link(self, link_f, y, Y_metadata=None):
|
||||
"""
|
||||
Log Likelihood Function given link(f)
|
||||
|
||||
|
|
@ -55,17 +53,16 @@ class Exponential(Likelihood):
|
|||
:type link_f: Nx1 array
|
||||
:param y: data
|
||||
:type y: Nx1 array
|
||||
:param extra_data: extra_data which is not used in exponential distribution
|
||||
:param Y_metadata: Y_metadata which is not used in exponential distribution
|
||||
:returns: likelihood evaluated for this point
|
||||
:rtype: float
|
||||
|
||||
"""
|
||||
assert np.atleast_1d(link_f).shape == np.atleast_1d(y).shape
|
||||
log_objective = np.log(link_f) - y*link_f
|
||||
#logpdf_link = np.sum(-np.log(link_f) - y/link_f)
|
||||
return np.sum(log_objective)
|
||||
|
||||
def dlogpdf_dlink(self, link_f, y, extra_data=None):
|
||||
def dlogpdf_dlink(self, link_f, y, Y_metadata=None):
|
||||
"""
|
||||
Gradient of the log likelihood function at y, given link(f) w.r.t link(f)
|
||||
|
||||
|
|
@ -76,7 +73,7 @@ class Exponential(Likelihood):
|
|||
:type link_f: Nx1 array
|
||||
:param y: data
|
||||
:type y: Nx1 array
|
||||
:param extra_data: extra_data which is not used in exponential distribution
|
||||
:param Y_metadata: Y_metadata which is not used in exponential distribution
|
||||
:returns: gradient of likelihood evaluated at points
|
||||
:rtype: Nx1 array
|
||||
|
||||
|
|
@ -86,7 +83,7 @@ class Exponential(Likelihood):
|
|||
#grad = y/(link_f**2) - 1./link_f
|
||||
return grad
|
||||
|
||||
def d2logpdf_dlink2(self, link_f, y, extra_data=None):
|
||||
def d2logpdf_dlink2(self, link_f, y, Y_metadata=None):
|
||||
"""
|
||||
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)
|
||||
|
|
@ -99,7 +96,7 @@ class Exponential(Likelihood):
|
|||
:type link_f: Nx1 array
|
||||
:param y: data
|
||||
:type y: Nx1 array
|
||||
:param extra_data: extra_data which is not used in exponential distribution
|
||||
:param Y_metadata: Y_metadata which is not used in exponential distribution
|
||||
:returns: Diagonal of hessian matrix (second derivative of likelihood evaluated at points f)
|
||||
:rtype: Nx1 array
|
||||
|
||||
|
|
@ -112,7 +109,7 @@ class Exponential(Likelihood):
|
|||
#hess = -2*y/(link_f**3) + 1/(link_f**2)
|
||||
return hess
|
||||
|
||||
def d3logpdf_dlink3(self, link_f, y, extra_data=None):
|
||||
def d3logpdf_dlink3(self, link_f, y, Y_metadata=None):
|
||||
"""
|
||||
Third order derivative log-likelihood function at y given link(f) w.r.t link(f)
|
||||
|
||||
|
|
@ -123,7 +120,7 @@ class Exponential(Likelihood):
|
|||
:type link_f: Nx1 array
|
||||
:param y: data
|
||||
:type y: Nx1 array
|
||||
:param extra_data: extra_data which is not used in exponential distribution
|
||||
:param Y_metadata: Y_metadata which is not used in exponential distribution
|
||||
:returns: third derivative of likelihood evaluated at points f
|
||||
:rtype: Nx1 array
|
||||
"""
|
||||
|
|
@ -132,18 +129,6 @@ class Exponential(Likelihood):
|
|||
#d3lik_dlink3 = 6*y/(link_f**4) - 2./(link_f**3)
|
||||
return d3lik_dlink3
|
||||
|
||||
def _mean(self,gp):
|
||||
"""
|
||||
Mass (or density) function
|
||||
"""
|
||||
return self.gp_link.transf(gp)
|
||||
|
||||
def _variance(self,gp):
|
||||
"""
|
||||
Mass (or density) function
|
||||
"""
|
||||
return self.gp_link.transf(gp)**2
|
||||
|
||||
def samples(self, gp):
|
||||
"""
|
||||
Returns a set of samples of observations based on a given value of the latent variable.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue