mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-26 15:49:40 +02:00
Merge branch 'params' of github.com:SheffieldML/GPy into params
This commit is contained in:
commit
607ed98e51
8 changed files with 65 additions and 32 deletions
|
|
@ -142,7 +142,12 @@ class Likelihood(Parameterized):
|
|||
"""
|
||||
#conditional_mean: the edpected value of y given some f, under this likelihood
|
||||
def int_mean(f,m,v):
|
||||
return self.conditional_mean(f)*np.exp(-(0.5/v)*np.square(f - m))
|
||||
p = np.exp(-(0.5/v)*np.square(f - m))
|
||||
#If p is zero then conditional_mean will overflow
|
||||
if p < 1e-10:
|
||||
return 0.
|
||||
else:
|
||||
return self.conditional_mean(f)*p
|
||||
scaled_mean = [quad(int_mean, -np.inf, np.inf,args=(mj,s2j))[0] for mj,s2j in zip(mu,variance)]
|
||||
mean = np.array(scaled_mean)[:,None] / np.sqrt(2*np.pi*(variance))
|
||||
|
||||
|
|
@ -165,7 +170,12 @@ class Likelihood(Parameterized):
|
|||
|
||||
# E( V(Y_star|f_star) )
|
||||
def int_var(f,m,v):
|
||||
return self.conditional_variance(f)*np.exp(-(0.5/v)*np.square(f - m))
|
||||
p = np.exp(-(0.5/v)*np.square(f - m))
|
||||
#If p is zero then conditional_variance will overflow
|
||||
if p < 1e-10:
|
||||
return 0.
|
||||
else:
|
||||
return self.conditional_variance(f)*p
|
||||
scaled_exp_variance = [quad(int_var, -np.inf, np.inf,args=(mj,s2j))[0] for mj,s2j in zip(mu,variance)]
|
||||
exp_var = np.array(scaled_exp_variance)[:,None] / normalizer
|
||||
|
||||
|
|
@ -178,7 +188,13 @@ class Likelihood(Parameterized):
|
|||
|
||||
#E( E(Y_star|f_star)**2 )
|
||||
def int_pred_mean_sq(f,m,v,predictive_mean_sq):
|
||||
return self.conditional_mean(f)**2*np.exp(-(0.5/v)*np.square(f - m))
|
||||
p = np.exp(-(0.5/v)*np.square(f - m))
|
||||
#If p is zero then conditional_mean**2 will overflow
|
||||
if p < 1e-10:
|
||||
return 0.
|
||||
else:
|
||||
return self.conditional_mean(f)**2*p
|
||||
|
||||
scaled_exp_exp2 = [quad(int_pred_mean_sq, -np.inf, np.inf,args=(mj,s2j,pm2j))[0] for mj,s2j,pm2j in zip(mu,variance,predictive_mean_sq)]
|
||||
exp_exp2 = np.array(scaled_exp_exp2)[:,None] / normalizer
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ from scipy import stats
|
|||
import scipy as sp
|
||||
from GPy.util.univariate_Gaussian import std_norm_pdf,std_norm_cdf,inv_std_norm_cdf
|
||||
|
||||
_exp_lim_val = np.finfo(np.float64).max
|
||||
_lim_val = np.log(_exp_lim_val)
|
||||
|
||||
class GPTransformation(object):
|
||||
"""
|
||||
Link function class for doing non-Gaussian likelihoods approximation
|
||||
|
|
@ -92,16 +95,16 @@ class Log(GPTransformation):
|
|||
|
||||
"""
|
||||
def transf(self,f):
|
||||
return np.exp(f)
|
||||
return np.exp(np.clip(f, -_lim_val, _lim_val))
|
||||
|
||||
def dtransf_df(self,f):
|
||||
return np.exp(f)
|
||||
return np.exp(np.clip(f, -_lim_val, _lim_val))
|
||||
|
||||
def d2transf_df2(self,f):
|
||||
return np.exp(f)
|
||||
return np.exp(np.clip(f, -_lim_val, _lim_val))
|
||||
|
||||
def d3transf_df3(self,f):
|
||||
return np.exp(f)
|
||||
return np.exp(np.clip(f, -_lim_val, _lim_val))
|
||||
|
||||
class Log_ex_1(GPTransformation):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class Poisson(Likelihood):
|
|||
"""
|
||||
def __init__(self, gp_link=None):
|
||||
if gp_link is None:
|
||||
gp_link = link_functions.Log_ex_1()
|
||||
gp_link = link_functions.Log()
|
||||
|
||||
super(Poisson, self).__init__(gp_link, name='Poisson')
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ class Poisson(Likelihood):
|
|||
"""
|
||||
return self.gp_link.transf(gp)
|
||||
|
||||
def samples(self, gp):
|
||||
def samples(self, gp, Y_metadata=None):
|
||||
"""
|
||||
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