def predict_f(self, x, full_cov=False): x = convert_2D_format(x) if full_cov: mean, cov = self.model.predict_f_full_cov(x) else: mean, cov = self.model.predict_f(x) return mean + self.center, cov
def create_model(self, x, y, noise_var, noise_prior='fixed'): x = convert_2D_format(x) y = convert_2D_format(y) - self.center self.outdim = y.shape[1] noise_var = np.array(noise_var) if noise_var.ndim == 0: self.model = GPy.models.GPRegression(x, y, self.kernel, noise_var=noise_var) noise = self.model.Gaussian_noise else: assert noise_var.shape == y.shape self.model = GPy.models.GPHeteroscedasticRegression(x, y, self.kernel) self.model['.*het_Gauss.variance'] = noise_var noise = self.model.het_Gauss.variance if noise_prior == 'fixed': noise.fix() else: raise ValueError('Not Implemented yet.')
def predict_f(self, x, full_cov=False): ''' Returns: posterior mean, posterior variance ''' x = convert_2D_format(x) post_mean, post_var = self.model.predict_noiseless(x, full_cov=full_cov) if self.outdim > 1: post_var = np.concatenate([post_var]*self.outdim, axis=-1) return post_mean + self.center, post_var
def create_model(self, x, y, noise_var, noise_prior='fixed'): x = convert_2D_format(x) y = convert_2D_format(y) - self.center numdata = x.shape[0] outdim = y.shape[1] indim = x.shape[1] yy = y.transpose().ravel() ind = np.concatenate([ o*np.ones(numdata) for o in range(outdim)]) xx = np.concatenate([x]*outdim) xx = np.concatenate((xx,ind[:,np.newaxis]), axis=1) print(xx.shape, yy.shape) self.model = GPy.models.GPRegression(x, y, self.kernel, noise_var=noise_var) if noise_prior == 'fixed': self.model.Gaussian_noise.fix() else: raise ValueError('Not Implemented yet.')
def create_model(self, x, y, noise_var, noise_prior='fixed'): x = convert_2D_format(x) y = convert_2D_format(y) - self.center if self.model is None: self.model = gpflow.models.GPR(x, y, self.kernel) if noise_prior == 'fixed': self.model.likelihood.variance = noise_var self.model.likelihood.variance.set_trainable(False) else: raise ValueError('Not Implemented yet.') self.model.compile() #shape = [None, x.shape[1]] #self.x_pred = tf.placeholder(tf.float32, shape=shape, name='x_pred') #self.mean_full, self.cov_full = self.model.predict_f_full_cov(self.x_pred) #self.mean, self.cov = self.model.predict_f(self.x_pred) #print(self.mean) #print(self.cov) else: self.model.X = x self.model.Y = y
def predict_withGradients(self, x): ''' Borrowed from https://github.com/SheffieldML/GPyOpt/blob/master/GPyOpt/models/gpmodel.py Returns the mean, standard deviation, mean gradient and standard deviation gradient at X. ''' x = convert_2D_format(x) m, v = self.model.predict(x) v = np.clip(v, 1e-10, np.inf) dmdx, dvdx = self.model.predictive_gradients(x) dmdx = dmdx[:,:,0] dsdx = dvdx / (2*np.sqrt(v)) return m + self.center, np.sqrt(v), dmdx, dsdx
def predict_prob(self, x): x = convert_2D_format(x) prob = self.model.predict(x, full_cov=False)[0] return prob
def create_model(self, x, y): assert self.center == 0.0 x = convert_2D_format(x) y = convert_2D_format(y) self.outdim = y.shape[1] self.model = GPy.models.GPClassification(x, y, self.kernel)