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.epsilon = epsilon
|
||||
self.eta, self.delta = power_ep
|
||||
self.jitter = 1e-12 # TODO: is this needed?
|
||||
|
||||
"""
|
||||
Initial values - Likelihood approximation parameters:
|
||||
|
|
@ -27,6 +26,16 @@ class EP:
|
|||
self.tau_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):
|
||||
#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
|
||||
|
|
|
|||
|
|
@ -29,6 +29,16 @@ class Gaussian:
|
|||
self._variance = x
|
||||
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):
|
||||
"""
|
||||
No approximations needed
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class probit(likelihood):
|
|||
|
||||
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()
|
||||
var = var.flatten()
|
||||
|
|
@ -57,7 +57,7 @@ class probit(likelihood):
|
|||
if all:
|
||||
p_05 = np.zeros([mu.size])
|
||||
p_95 = np.ones([mu.size])
|
||||
return mean, mean*(1-mean),p_05,p_95
|
||||
return mean, p_05, p_95
|
||||
else:
|
||||
return mean
|
||||
|
||||
|
|
@ -136,14 +136,14 @@ class poisson(likelihood):
|
|||
|
||||
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)
|
||||
if all:
|
||||
tmp = stats.poisson.ppf(np.array([.05,.95]),mu)
|
||||
p_05 = tmp[:,0]
|
||||
p_95 = tmp[:,1]
|
||||
return mean,mean,p_05,p_95
|
||||
return mean,p_05,p_95
|
||||
else:
|
||||
return mean
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue