mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-18 13:55:14 +02:00
Removing unnecessary stuff...
This commit is contained in:
parent
c129b98b3b
commit
40e4f19187
6 changed files with 29 additions and 57 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# Copyright (c) 2012, 2013 Ricardo Andrade
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
|
||||
import numpy as np
|
||||
from scipy import stats,special
|
||||
import scipy as sp
|
||||
|
|
@ -116,18 +117,3 @@ class Binomial(NoiseDistribution):
|
|||
|
||||
def _d2variance_dgp2(self,gp):
|
||||
return self.gp_link.d2transf_df2(gp)*(1. - 2.*self.gp_link.transf(gp)) - 2*self.gp_link.dtransf_df(gp)**2
|
||||
|
||||
"""
|
||||
def predictive_values(self,mu,var): #TODO remove
|
||||
mu = mu.flatten()
|
||||
var = var.flatten()
|
||||
#mean = stats.norm.cdf(mu/np.sqrt(1+var))
|
||||
mean = self._predictive_mean_analytical(mu,np.sqrt(var))
|
||||
norm_025 = [stats.norm.ppf(.025,m,v) for m,v in zip(mu,var)]
|
||||
norm_975 = [stats.norm.ppf(.975,m,v) for m,v in zip(mu,var)]
|
||||
#p_025 = stats.norm.cdf(norm_025/np.sqrt(1+var))
|
||||
#p_975 = stats.norm.cdf(norm_975/np.sqrt(1+var))
|
||||
p_025 = self._predictive_mean_analytical(norm_025,np.sqrt(var))
|
||||
p_975 = self._predictive_mean_analytical(norm_975,np.sqrt(var))
|
||||
return mean[:,None], np.nan*var, p_025[:,None], p_975[:,None] # TODO: var
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from noise_distributions import NoiseDistribution
|
|||
|
||||
class Exponential(NoiseDistribution):
|
||||
"""
|
||||
Gamma likelihood
|
||||
Expoential likelihood
|
||||
Y is expected to take values in {0,1,2,...}
|
||||
-----
|
||||
$$
|
||||
|
|
|
|||
|
|
@ -57,12 +57,12 @@ class Gaussian(NoiseDistribution):
|
|||
new_sigma2 = self.predictive_variance(mu,sigma)
|
||||
return new_sigma2*(mu/sigma**2 + self.gp_link.transf(mu)/self.variance)
|
||||
|
||||
def _predictive_variance_analytical(self,mu,sigma,*args): #TODO *args?
|
||||
def _predictive_variance_analytical(self,mu,sigma):
|
||||
return 1./(1./self.variance + 1./sigma**2)
|
||||
|
||||
def _mass(self,gp,obs):
|
||||
#return std_norm_pdf( (self.gp_link.transf(gp)-obs)/np.sqrt(self.variance) )
|
||||
return stats.norm.pdf(obs,self.gp_link.transf(gp),np.sqrt(self.variance)) #FIXME
|
||||
return stats.norm.pdf(obs,self.gp_link.transf(gp),np.sqrt(self.variance))
|
||||
|
||||
def _nlog_mass(self,gp,obs):
|
||||
return .5*((self.gp_link.transf(gp)-obs)**2/self.variance + np.log(2.*np.pi*self.variance))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ from GPy.util.univariate_Gaussian import std_norm_pdf,std_norm_cdf,inv_std_norm_
|
|||
|
||||
class GPTransformation(object):
|
||||
"""
|
||||
|
||||
Link function class for doing non-Gaussian likelihoods approximation
|
||||
|
||||
:param Y: observed output (Nx1 numpy.darray)
|
||||
|
|
@ -21,6 +20,24 @@ class GPTransformation(object):
|
|||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transf(self,f):
|
||||
"""
|
||||
Gaussian process tranformation function, latent space -> output space
|
||||
"""
|
||||
pass
|
||||
|
||||
def dtransf_df(self,f):
|
||||
"""
|
||||
derivative of transf(f) w.r.t. f
|
||||
"""
|
||||
pass
|
||||
|
||||
def d2transf_df2(self,f):
|
||||
"""
|
||||
second derivative of transf(f) w.r.t. f
|
||||
"""
|
||||
pass
|
||||
|
||||
class Identity(GPTransformation):
|
||||
"""
|
||||
.. math::
|
||||
|
|
@ -28,9 +45,6 @@ class Identity(GPTransformation):
|
|||
g(f) = f
|
||||
|
||||
"""
|
||||
#def transf(self,mu):
|
||||
# return mu
|
||||
|
||||
def transf(self,f):
|
||||
return f
|
||||
|
||||
|
|
@ -48,9 +62,6 @@ class Probit(GPTransformation):
|
|||
g(f) = \\Phi^{-1} (mu)
|
||||
|
||||
"""
|
||||
#def transf(self,mu):
|
||||
# return inv_std_norm_cdf(mu)
|
||||
|
||||
def transf(self,f):
|
||||
return std_norm_cdf(f)
|
||||
|
||||
|
|
@ -63,12 +74,10 @@ class Probit(GPTransformation):
|
|||
class Log(GPTransformation):
|
||||
"""
|
||||
.. math::
|
||||
|
||||
g(f) = \\log(\\mu)
|
||||
|
||||
"""
|
||||
#def transf(self,mu):
|
||||
# return np.log(mu)
|
||||
|
||||
def transf(self,f):
|
||||
return np.exp(f)
|
||||
|
||||
|
|
@ -81,19 +90,11 @@ class Log(GPTransformation):
|
|||
class Log_ex_1(GPTransformation):
|
||||
"""
|
||||
.. math::
|
||||
|
||||
g(f) = \\log(\\exp(\\mu) - 1)
|
||||
|
||||
"""
|
||||
#def transf(self,mu):
|
||||
# """
|
||||
# function: output space -> latent space
|
||||
# """
|
||||
# return np.log(np.exp(mu) - 1)
|
||||
|
||||
def transf(self,f):
|
||||
"""
|
||||
function: latent space -> output space
|
||||
"""
|
||||
return np.log(1.+np.exp(f))
|
||||
|
||||
def dtransf_df(self,f):
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class NoiseDistribution(object):
|
|||
.. note:: Y values allowed depend on the LikelihoodFunction used
|
||||
"""
|
||||
def __init__(self,gp_link,analytical_mean=False,analytical_variance=False):
|
||||
#assert isinstance(gp_link,gp_transformations.GPTransformation), "gp_link is not a valid GPTransformation."#FIXME
|
||||
assert isinstance(gp_link,gp_transformations.GPTransformation), "gp_link is not a valid GPTransformation."
|
||||
self.gp_link = gp_link
|
||||
self.analytical_mean = analytical_mean
|
||||
self.analytical_variance = analytical_variance
|
||||
|
|
@ -51,7 +51,8 @@ class NoiseDistribution(object):
|
|||
"""
|
||||
In case it is needed, this function assess the output values or makes any pertinent transformation on them.
|
||||
|
||||
:param Y: observed output (Nx1 numpy.darray)
|
||||
:param Y: observed output
|
||||
:type Y: Nx1 numpy.darray
|
||||
|
||||
"""
|
||||
return Y
|
||||
|
|
|
|||
|
|
@ -12,29 +12,22 @@ from noise_distributions import NoiseDistribution
|
|||
class Poisson(NoiseDistribution):
|
||||
"""
|
||||
Poisson likelihood
|
||||
Y is expected to take values in {0,1,2,...}
|
||||
|
||||
.. math::
|
||||
L(x) = \\exp(\\lambda) * \\frac{\\lambda^Y_i}{Y_i!}
|
||||
|
||||
..Note: Y is expected to take values in {0,1,2,...}
|
||||
"""
|
||||
def __init__(self,gp_link=None,analytical_mean=False,analytical_variance=False):
|
||||
#self.discrete = True
|
||||
#self.support_limits = (0,np.inf)
|
||||
|
||||
#self.analytical_mean = False
|
||||
super(Poisson, self).__init__(gp_link,analytical_mean,analytical_variance)
|
||||
|
||||
def _preprocess_values(self,Y): #TODO
|
||||
#self.scale = .5*Y.max()
|
||||
#self.shift = Y.mean()
|
||||
return Y #(Y - self.shift)/self.scale
|
||||
return Y
|
||||
|
||||
def _mass(self,gp,obs):
|
||||
"""
|
||||
Mass (or density) function
|
||||
"""
|
||||
#obs = obs*self.scale + self.shift
|
||||
return stats.poisson.pmf(obs,self.gp_link.transf(gp))
|
||||
|
||||
def _nlog_mass(self,gp,obs):
|
||||
|
|
@ -51,15 +44,6 @@ class Poisson(NoiseDistribution):
|
|||
transf = self.gp_link.transf(gp)
|
||||
return obs * ((self.gp_link.dtransf_df(gp)/transf)**2 - d2_df/transf) + d2_df
|
||||
|
||||
def _dnlog_mass_dobs(self,obs,gp): #TODO not needed
|
||||
return special.psi(obs+1) - np.log(self.gp_link.transf(gp))
|
||||
|
||||
def _d2nlog_mass_dobs2(self,obs,gp=None): #TODO not needed
|
||||
return special.polygamma(1,obs)
|
||||
|
||||
def _d2nlog_mass_dcross(self,obs,gp): #TODO not needed
|
||||
return -self.gp_link.dtransf_df(gp)/self.gp_link.transf(gp)
|
||||
|
||||
def _mean(self,gp):
|
||||
"""
|
||||
Mass (or density) function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue