mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-21 14:05:14 +02:00
Merge branch 'devel' of github.com:SheffieldML/GPy into devel
This commit is contained in:
commit
a32f9bf9dd
6 changed files with 22 additions and 18 deletions
|
|
@ -20,7 +20,7 @@ from GPy.core.domains import POSITIVE, REAL
|
|||
class model(parameterised):
|
||||
def __init__(self):
|
||||
parameterised.__init__(self)
|
||||
self.priors = [None for i in range(self._get_params().size)]
|
||||
self.priors = None
|
||||
self.optimization_runs = []
|
||||
self.sampling_runs = []
|
||||
self.preferred_optimizer = 'tnc'
|
||||
|
|
@ -55,7 +55,7 @@ class model(parameterised):
|
|||
if self.priors is None:
|
||||
self.priors = [None for i in range(self._get_params().size)]
|
||||
|
||||
which = self.grep_param_names(which)
|
||||
which = self.grep_param_names(regexp)
|
||||
|
||||
# check tied situation
|
||||
tie_partial_matches = [tie for tie in self.tied_indices if (not set(tie).isdisjoint(set(which))) & (not set(tie) == set(which))]
|
||||
|
|
@ -316,7 +316,10 @@ class model(parameterised):
|
|||
def __str__(self):
|
||||
s = parameterised.__str__(self).split('\n')
|
||||
# add priors to the string
|
||||
if self.priors is not None:
|
||||
strs = [str(p) if p is not None else '' for p in self.priors]
|
||||
else:
|
||||
strs = ['']*len(self._get_params())
|
||||
width = np.array(max([len(p) for p in strs] + [5])) + 4
|
||||
|
||||
log_like = self.log_likelihood()
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ def sparse_GP_regression_1D(N = 400, M = 5, max_nb_eval_optim=100):
|
|||
# create simple GP model
|
||||
m = GPy.models.sparse_GP_regression(X, Y, kernel, M=M)
|
||||
|
||||
m.constrain_positive('(variance|lengthscale|precision)')
|
||||
m.ensure_default_constraints()
|
||||
|
||||
m.checkgrad(verbose=1)
|
||||
m.optimize('tnc', messages = 1, max_f_eval=max_nb_eval_optim)
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class EP(likelihood):
|
|||
self.tau_[i] = 1./Sigma[i,i] - self.eta*self.tau_tilde[i]
|
||||
self.v_[i] = mu[i]/Sigma[i,i] - self.eta*self.v_tilde[i]
|
||||
#Marginal moments
|
||||
self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self.data[i],self.tau_[i],self.v_[i])
|
||||
self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self._transf_data[i],self.tau_[i],self.v_[i])
|
||||
#Site parameters update
|
||||
Delta_tau = self.delta/self.eta*(1./sigma2_hat[i] - 1./Sigma[i,i])
|
||||
Delta_v = self.delta/self.eta*(mu_hat[i]/sigma2_hat[i] - mu[i]/Sigma[i,i])
|
||||
|
|
@ -200,7 +200,7 @@ class EP(likelihood):
|
|||
self.tau_[i] = 1./Sigma_diag[i] - self.eta*self.tau_tilde[i]
|
||||
self.v_[i] = mu[i]/Sigma_diag[i] - self.eta*self.v_tilde[i]
|
||||
#Marginal moments
|
||||
self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self.data[i],self.tau_[i],self.v_[i])
|
||||
self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self._transf_data[i],self.tau_[i],self.v_[i])
|
||||
#Site parameters update
|
||||
Delta_tau = self.delta/self.eta*(1./sigma2_hat[i] - 1./Sigma_diag[i])
|
||||
Delta_v = self.delta/self.eta*(mu_hat[i]/sigma2_hat[i] - mu[i]/Sigma_diag[i])
|
||||
|
|
@ -295,7 +295,7 @@ class EP(likelihood):
|
|||
self.tau_[i] = 1./Sigma_diag[i] - self.eta*self.tau_tilde[i]
|
||||
self.v_[i] = mu[i]/Sigma_diag[i] - self.eta*self.v_tilde[i]
|
||||
#Marginal moments
|
||||
self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self.data[i],self.tau_[i],self.v_[i])
|
||||
self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self._transf_data[i],self.tau_[i],self.v_[i])
|
||||
#Site parameters update
|
||||
Delta_tau = self.delta/self.eta*(1./sigma2_hat[i] - 1./Sigma_diag[i])
|
||||
Delta_v = self.delta/self.eta*(mu_hat[i]/sigma2_hat[i] - mu[i]/Sigma_diag[i])
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ class link_function(object):
|
|||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class identity(link_function):
|
||||
def transf(self,mu):
|
||||
return mu
|
||||
|
|
@ -53,6 +51,10 @@ class log_ex_1(link_function):
|
|||
return np.log(np.log(np.exp(f)+1))
|
||||
|
||||
class probit(link_function):
|
||||
pass
|
||||
|
||||
def inv_transf(self,f):
|
||||
return std_norm_cdf(f)
|
||||
|
||||
def log_inv_transf(self,f):
|
||||
return np.log(std_norm_cdf(f))
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ class PriorTests(unittest.TestCase):
|
|||
X, y = X[:, None], y[:, None]
|
||||
m = GPy.models.GP_regression(X, y)
|
||||
m.ensure_default_constraints()
|
||||
lognormal = GPy.priors.log_Gaussian(1, 2)
|
||||
lognormal = GPy.priors.LogGaussian(1, 2)
|
||||
m.set_prior('rbf', lognormal)
|
||||
m.randomize()
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
def test_gamma(self):
|
||||
def test_Gamma(self):
|
||||
xmin, xmax = 1, 2.5*np.pi
|
||||
b, C, SNR = 1, 0, 0.1
|
||||
X = np.linspace(xmin, xmax, 500)
|
||||
|
|
@ -29,8 +29,8 @@ class PriorTests(unittest.TestCase):
|
|||
X, y = X[:, None], y[:, None]
|
||||
m = GPy.models.GP_regression(X, y)
|
||||
m.ensure_default_constraints()
|
||||
gamma = GPy.priors.gamma(1, 1)
|
||||
m.set_prior('rbf', gamma)
|
||||
Gamma = GPy.priors.Gamma(1, 1)
|
||||
m.set_prior('rbf', Gamma)
|
||||
m.randomize()
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ class GradientTests(unittest.TestCase):
|
|||
X = np.hstack([np.random.normal(5,2,N/2),np.random.normal(10,2,N/2)])[:,None]
|
||||
Y = np.hstack([np.ones(N/2),np.zeros(N/2)])[:,None]
|
||||
kernel = GPy.kern.rbf(1)
|
||||
distribution = GPy.likelihoods.likelihood_functions.probit()
|
||||
distribution = GPy.likelihoods.likelihood_functions.binomial()
|
||||
likelihood = GPy.likelihoods.EP(Y, distribution)
|
||||
m = GPy.core.GP(X, likelihood, kernel)
|
||||
m.ensure_default_constraints()
|
||||
|
|
@ -183,20 +183,19 @@ class GradientTests(unittest.TestCase):
|
|||
Y = np.hstack([np.ones(N/2),np.zeros(N/2)])[:,None]
|
||||
Z = np.linspace(0,15,4)[:,None]
|
||||
kernel = GPy.kern.rbf(1)
|
||||
distribution = GPy.likelihoods.likelihood_functions.probit()
|
||||
distribution = GPy.likelihoods.likelihood_functions.binomial()
|
||||
likelihood = GPy.likelihoods.EP(Y, distribution)
|
||||
m = GPy.core.sparse_GP(X, likelihood, kernel,Z)
|
||||
m.ensure_default_constraints()
|
||||
m.update_likelihood_approximation()
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
@unittest.skip("FITC will be broken for a while")
|
||||
def test_generalized_FITC(self):
|
||||
N = 20
|
||||
X = np.hstack([np.random.rand(N/2)+1,np.random.rand(N/2)-1])[:,None]
|
||||
k = GPy.kern.rbf(1) + GPy.kern.white(1)
|
||||
Y = np.hstack([np.ones(N/2),-np.ones(N/2)])[:,None]
|
||||
likelihood = GPy.inference.likelihoods.probit(Y)
|
||||
likelihood = GPy.inference.likelihoods.binomial(Y)
|
||||
m = GPy.models.generalized_FITC(X,likelihood,k,inducing=4)
|
||||
m.constrain_positive('(var|len)')
|
||||
m.approximate_likelihood()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue