mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-18 13:55:14 +02:00
predictive_values implemented in EP
This commit is contained in:
parent
4211cad89d
commit
2b40ee6f7e
4 changed files with 26 additions and 6 deletions
|
|
@ -18,7 +18,6 @@ class EP:
|
||||||
self.likelihood_function = likelihood_function
|
self.likelihood_function = likelihood_function
|
||||||
self.epsilon = epsilon
|
self.epsilon = epsilon
|
||||||
self.eta, self.delta = power_ep
|
self.eta, self.delta = power_ep
|
||||||
self.jitter = 1e-12 # TODO: is this needed?
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Initial values - Likelihood approximation parameters:
|
Initial values - Likelihood approximation parameters:
|
||||||
|
|
@ -27,6 +26,16 @@ class EP:
|
||||||
self.tau_tilde = np.zeros(self.N)
|
self.tau_tilde = np.zeros(self.N)
|
||||||
self.v_tilde = np.zeros(self.N)
|
self.v_tilde = np.zeros(self.N)
|
||||||
|
|
||||||
|
def predictive_values(self,mu,var):
|
||||||
|
return self.likelihood_function.predictive_values(mu,var)
|
||||||
|
|
||||||
|
def _get_params(self):
|
||||||
|
return np.zeros(0)
|
||||||
|
def _get_param_names(self):
|
||||||
|
return []
|
||||||
|
def _set_params(self,p):
|
||||||
|
pass # TODO: the EP likelihood might want to take some parameters...
|
||||||
|
|
||||||
def _compute_GP_variables(self):
|
def _compute_GP_variables(self):
|
||||||
#Variables to be called from GP
|
#Variables to be called from GP
|
||||||
mu_tilde = self.v_tilde/self.tau_tilde #When calling EP, this variable is used instead of Y in the GP model
|
mu_tilde = self.v_tilde/self.tau_tilde #When calling EP, this variable is used instead of Y in the GP model
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,16 @@ class Gaussian:
|
||||||
self._variance = x
|
self._variance = x
|
||||||
self.variance = np.eye(self.N)*self._variance
|
self.variance = np.eye(self.N)*self._variance
|
||||||
|
|
||||||
|
def predictive_values(self,mu,var):
|
||||||
|
"""
|
||||||
|
Un-normalise the prediction and add the likelihood variance, then return the 5%, 95% interval
|
||||||
|
"""
|
||||||
|
mean = mu*self._std + self._mean
|
||||||
|
true_var = (var + self._variance)*self._std**2
|
||||||
|
_5pc = mean + mean - 2.*np.sqrt(var)
|
||||||
|
_95pc = mean + 2.*np.sqrt(var)
|
||||||
|
return mean, _5pc, _95pc
|
||||||
|
|
||||||
def fit(self):
|
def fit(self):
|
||||||
"""
|
"""
|
||||||
No approximations needed
|
No approximations needed
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class probit(likelihood):
|
||||||
|
|
||||||
def predictive_values(self,mu,var,all=False):
|
def predictive_values(self,mu,var,all=False):
|
||||||
"""
|
"""
|
||||||
Compute mean, variance, and conficence interval (percentiles 5 and 95) of the prediction
|
Compute mean, and conficence interval (percentiles 5 and 95) of the prediction
|
||||||
"""
|
"""
|
||||||
mu = mu.flatten()
|
mu = mu.flatten()
|
||||||
var = var.flatten()
|
var = var.flatten()
|
||||||
|
|
@ -57,7 +57,7 @@ class probit(likelihood):
|
||||||
if all:
|
if all:
|
||||||
p_05 = np.zeros([mu.size])
|
p_05 = np.zeros([mu.size])
|
||||||
p_95 = np.ones([mu.size])
|
p_95 = np.ones([mu.size])
|
||||||
return mean, mean*(1-mean),p_05,p_95
|
return mean, p_05, p_95
|
||||||
else:
|
else:
|
||||||
return mean
|
return mean
|
||||||
|
|
||||||
|
|
@ -136,14 +136,14 @@ class poisson(likelihood):
|
||||||
|
|
||||||
def predictive_values(self,mu,var,all=False):
|
def predictive_values(self,mu,var,all=False):
|
||||||
"""
|
"""
|
||||||
Compute mean, variance, and conficence interval (percentiles 5 and 95) of the prediction
|
Compute mean, and conficence interval (percentiles 5 and 95) of the prediction
|
||||||
"""
|
"""
|
||||||
mean = np.exp(mu*self.scale + self.location)
|
mean = np.exp(mu*self.scale + self.location)
|
||||||
if all:
|
if all:
|
||||||
tmp = stats.poisson.ppf(np.array([.05,.95]),mu)
|
tmp = stats.poisson.ppf(np.array([.05,.95]),mu)
|
||||||
p_05 = tmp[:,0]
|
p_05 = tmp[:,0]
|
||||||
p_95 = tmp[:,1]
|
p_95 = tmp[:,1]
|
||||||
return mean,mean,p_05,p_95
|
return mean,p_05,p_95
|
||||||
else:
|
else:
|
||||||
return mean
|
return mean
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,9 +164,10 @@ class GP(model):
|
||||||
"""
|
"""
|
||||||
#normalise X values
|
#normalise X values
|
||||||
Xnew = (Xnew.copy() - self._Xmean) / self._Xstd
|
Xnew = (Xnew.copy() - self._Xmean) / self._Xstd
|
||||||
mu, var, phi = self._raw_predict(Xnew, slices, full_cov=full_cov)
|
mu, var = self._raw_predict(Xnew, slices, full_cov=full_cov)
|
||||||
|
|
||||||
#now push through likelihood TODO
|
#now push through likelihood TODO
|
||||||
|
mean, _5pc, _95pc = self.likelihood.predictive_values(mu, var)
|
||||||
|
|
||||||
return mean, _5pc, _95pc
|
return mean, _5pc, _95pc
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue