mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-18 13:55:14 +02:00
Merge branch 'devel' of https://github.com/SheffieldML/GPy into wgps_improvements
Merging new devel
This commit is contained in:
commit
76f3ff65a1
45 changed files with 729 additions and 378 deletions
|
|
@ -1,14 +1,9 @@
|
|||
# Copyright (c) 2014, Max Zwiessele
|
||||
# Copyright (c) 2014, Max Zwiessele, GPy Authors
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
"""
|
||||
|
||||
MaxZ
|
||||
|
||||
"""
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
def deepTest(reason):
|
||||
if reason:
|
||||
return lambda x:x
|
||||
return unittest.skip("Not deep scanning, enable deepscan by adding 'deep' argument")
|
||||
return unittest.skip("Not deep scanning, enable deepscan by adding 'deep' argument to unittest call")
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 9 KiB |
|
|
@ -51,5 +51,20 @@ class InferenceXTestCase(unittest.TestCase):
|
|||
np.testing.assert_array_almost_equal(m.X, mi.X, decimal=2)
|
||||
|
||||
|
||||
class HMCSamplerTest(unittest.TestCase):
|
||||
|
||||
def test_sampling(self):
|
||||
np.random.seed(1)
|
||||
x = np.linspace(0.,2*np.pi,100)[:,None]
|
||||
y = -np.cos(x)+np.random.randn(*x.shape)*0.3+1
|
||||
|
||||
m = GPy.models.GPRegression(x,y)
|
||||
m.kern.lengthscale.set_prior(GPy.priors.Gamma.from_EV(1.,10.))
|
||||
m.kern.variance.set_prior(GPy.priors.Gamma.from_EV(1.,10.))
|
||||
m.likelihood.variance.set_prior(GPy.priors.Gamma.from_EV(1.,10.))
|
||||
|
||||
hmc = GPy.inference.mcmc.HMC(m,stepsize=1e-2)
|
||||
s = hmc.sample(num_samples=3)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ class Kern_check_model(GPy.core.Model):
|
|||
X = np.random.randn(20, kernel.input_dim)
|
||||
if dL_dK is None:
|
||||
if X2 is None:
|
||||
dL_dK = np.ones((X.shape[0], X.shape[0]))
|
||||
dL_dK = np.random.rand(X.shape[0], X.shape[0])
|
||||
else:
|
||||
dL_dK = np.ones((X.shape[0], X2.shape[0]))
|
||||
dL_dK = np.random.rand(X.shape[0], X2.shape[0])
|
||||
|
||||
self.kernel = kernel
|
||||
self.X = X
|
||||
|
|
@ -310,7 +310,7 @@ class KernelGradientTestsContinuous(unittest.TestCase):
|
|||
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
||||
|
||||
def test_RBF(self):
|
||||
k = GPy.kern.RBF(self.D)
|
||||
k = GPy.kern.RBF(self.D, ARD=True)
|
||||
k.randomize()
|
||||
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
||||
|
||||
|
|
@ -324,6 +324,11 @@ class KernelGradientTestsContinuous(unittest.TestCase):
|
|||
k.randomize()
|
||||
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
||||
|
||||
def test_Poly(self):
|
||||
k = GPy.kern.Poly(self.D, order=5)
|
||||
k.randomize()
|
||||
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
||||
|
||||
def test_standard_periodic(self):
|
||||
k = GPy.kern.StdPeriodic(self.D, self.D-1)
|
||||
k.randomize()
|
||||
|
|
@ -366,6 +371,7 @@ class KernelTestsNonContinuous(unittest.TestCase):
|
|||
self.X2[:(N0*2), -1] = 0
|
||||
self.X2[(N0*2):, -1] = 1
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_IndependentOutputs(self):
|
||||
k = GPy.kern.RBF(self.D, active_dims=range(self.D))
|
||||
kern = GPy.kern.IndependentOutputs(k, -1, 'ind_single')
|
||||
|
|
@ -374,6 +380,7 @@ class KernelTestsNonContinuous(unittest.TestCase):
|
|||
kern = GPy.kern.IndependentOutputs(k, -1, name='ind_split')
|
||||
self.assertTrue(check_kernel_gradient_functions(kern, X=self.X, X2=self.X2, verbose=verbose, fixed_X_dims=-1))
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_Hierarchical(self):
|
||||
k = [GPy.kern.RBF(2, active_dims=[0,2], name='rbf1'), GPy.kern.RBF(2, active_dims=[0,2], name='rbf2')]
|
||||
kern = GPy.kern.IndependentOutputs(k, -1, name='ind_split')
|
||||
|
|
@ -467,7 +474,7 @@ class Kernel_Psi_statistics_GradientTests(unittest.TestCase):
|
|||
self.w1 = np.random.randn(N)
|
||||
self.w2 = np.random.randn(N,M)
|
||||
self.w3 = np.random.randn(M,M)
|
||||
self.w3 = self.w3+self.w3.T
|
||||
self.w3 = self.w3#+self.w3.T
|
||||
self.w3n = np.random.randn(N,M,M)
|
||||
self.w3n = self.w3n+np.swapaxes(self.w3n, 1,2)
|
||||
|
||||
|
|
@ -475,7 +482,7 @@ class Kernel_Psi_statistics_GradientTests(unittest.TestCase):
|
|||
from GPy.kern import RBF,Linear,MLP,Bias,White
|
||||
Q = self.Z.shape[1]
|
||||
kernels = [RBF(Q,ARD=True), Linear(Q,ARD=True),MLP(Q,ARD=True), RBF(Q,ARD=True)+Linear(Q,ARD=True)+Bias(Q)+White(Q)
|
||||
,RBF(Q,ARD=True)+Bias(Q)+White(Q), Linear(Q,ARD=True)+Bias(Q)+White(Q)]
|
||||
,RBF(Q,ARD=True)+Bias(Q)+White(Q), Linear(Q,ARD=True)+Bias(Q)+White(Q)]
|
||||
|
||||
for k in kernels:
|
||||
k.randomize()
|
||||
|
|
|
|||
|
|
@ -27,21 +27,29 @@
|
|||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#===============================================================================
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# SKIPPING PLOTTING BECAUSE IT BEHAVES DIFFERENTLY ON DIFFERENT
|
||||
# SYSTEMS, AND WILL MISBEHAVE
|
||||
from nose import SkipTest
|
||||
raise SkipTest("Skipping Matplotlib testing")
|
||||
#===============================================================================
|
||||
|
||||
import matplotlib
|
||||
from unittest.case import TestCase
|
||||
matplotlib.use('agg')
|
||||
|
||||
import numpy as np
|
||||
import GPy, os
|
||||
from nose import SkipTest
|
||||
|
||||
from ..util.config import config
|
||||
from ..plotting import change_plotting_library, plotting_library
|
||||
from GPy.util.config import config
|
||||
from GPy.plotting import change_plotting_library, plotting_library
|
||||
|
||||
class ConfigTest(TestCase):
|
||||
def tearDown(self):
|
||||
change_plotting_library('matplotlib')
|
||||
|
||||
|
||||
def test_change_plotting(self):
|
||||
self.assertRaises(ValueError, change_plotting_library, 'not+in9names')
|
||||
change_plotting_library('none')
|
||||
|
|
@ -69,8 +77,8 @@ def _image_directories():
|
|||
#module_name = __init__.__module__
|
||||
#mods = module_name.split('.')
|
||||
#basedir = os.path.join(*mods)
|
||||
result_dir = os.path.join(basedir, 'testresult')
|
||||
baseline_dir = os.path.join(basedir, 'baseline')
|
||||
result_dir = os.path.join(basedir, 'testresult','.')
|
||||
baseline_dir = os.path.join(basedir, 'baseline','.')
|
||||
if not os.path.exists(result_dir):
|
||||
cbook.mkdirs(result_dir)
|
||||
return baseline_dir, result_dir
|
||||
|
|
@ -115,12 +123,12 @@ def test_figure():
|
|||
import warnings
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
|
||||
|
||||
ax, _ = pl().new_canvas(num=1)
|
||||
def test_func(x):
|
||||
return x[:, 0].reshape(3,3)
|
||||
pl().imshow_interact(ax, test_func, extent=(-1,1,-1,1), resolution=3)
|
||||
|
||||
|
||||
ax, _ = pl().new_canvas()
|
||||
def test_func_2(x):
|
||||
y = x[:, 0].reshape(3,3)
|
||||
|
|
@ -129,21 +137,21 @@ def test_figure():
|
|||
|
||||
pl().annotation_heatmap_interact(ax, test_func_2, extent=(-1,1,-1,1), resolution=3)
|
||||
pl().annotation_heatmap_interact(ax, test_func_2, extent=(-1,1,-1,1), resolution=3, imshow_kwargs=dict(interpolation='nearest'))
|
||||
|
||||
|
||||
ax, _ = pl().new_canvas(figsize=(4,3))
|
||||
x = np.linspace(0,1,100)
|
||||
y = [0,1,2]
|
||||
array = np.array([.4,.5])
|
||||
cmap = matplotlib.colors.LinearSegmentedColormap.from_list('WhToColor', ('r', 'b'), N=array.size)
|
||||
|
||||
pl().fill_gradient(ax, x, y, facecolors=['r', 'g'], array=array, cmap=cmap)
|
||||
|
||||
pl().fill_gradient(ax, x, y, facecolors=['r', 'g'], array=array, cmap=cmap)
|
||||
|
||||
ax, _ = pl().new_canvas(num=4, figsize=(4,3), projection='3d', xlabel='x', ylabel='y', zlabel='z', title='awsome title', xlim=(-1,1), ylim=(-1,1), zlim=(-3,3))
|
||||
z = 2-np.abs(np.linspace(-2,2,(100)))+1
|
||||
x, y = z*np.sin(np.linspace(-2*np.pi,2*np.pi,(100))), z*np.cos(np.linspace(-np.pi,np.pi,(100)))
|
||||
|
||||
|
||||
pl().plot(ax, x, y, z, linewidth=2)
|
||||
|
||||
|
||||
for do_test in _image_comparison(
|
||||
baseline_images=['coverage_{}'.format(sub) for sub in ["imshow_interact",'annotation_interact','gradient','3d_plot',]],
|
||||
extensions=extensions):
|
||||
|
|
@ -194,9 +202,9 @@ def test_plot():
|
|||
m.plot_errorbars_trainset()
|
||||
m.plot_samples()
|
||||
m.plot_data_error()
|
||||
for do_test in _image_comparison(baseline_images=['gp_{}'.format(sub) for sub in ["data", "mean", 'conf',
|
||||
'density',
|
||||
'out_error',
|
||||
for do_test in _image_comparison(baseline_images=['gp_{}'.format(sub) for sub in ["data", "mean", 'conf',
|
||||
'density',
|
||||
'out_error',
|
||||
'samples', 'in_error']], extensions=extensions):
|
||||
yield (do_test, )
|
||||
|
||||
|
|
@ -216,9 +224,9 @@ def test_twod():
|
|||
m.plot_inducing()
|
||||
#m.plot_errorbars_trainset()
|
||||
m.plot_data_error()
|
||||
for do_test in _image_comparison(baseline_images=['gp_2d_{}'.format(sub) for sub in ["data", "mean",
|
||||
'inducing',
|
||||
#'out_error',
|
||||
for do_test in _image_comparison(baseline_images=['gp_2d_{}'.format(sub) for sub in ["data", "mean",
|
||||
'inducing',
|
||||
#'out_error',
|
||||
'in_error',
|
||||
]], extensions=extensions):
|
||||
yield (do_test, )
|
||||
|
|
@ -242,7 +250,7 @@ def test_threed():
|
|||
m.plot_mean(projection='3d')
|
||||
m.plot_inducing(projection='3d')
|
||||
#m.plot_errorbars_trainset(projection='3d')
|
||||
for do_test in _image_comparison(baseline_images=['gp_3d_{}'.format(sub) for sub in ["data", "mean", 'inducing',
|
||||
for do_test in _image_comparison(baseline_images=['gp_3d_{}'.format(sub) for sub in ["data", "mean", 'inducing',
|
||||
#'error',
|
||||
#"samples", "samples_lik"
|
||||
]], extensions=extensions):
|
||||
|
|
@ -316,7 +324,7 @@ def test_gplvm():
|
|||
matplotlib.rcParams[u'figure.figsize'] = (4,3)
|
||||
matplotlib.rcParams[u'text.usetex'] = False
|
||||
Q = 3
|
||||
# Define dataset
|
||||
# Define dataset
|
||||
N = 10
|
||||
k1 = GPy.kern.RBF(5, variance=1, lengthscale=1./np.random.dirichlet(np.r_[10,10,10,0.1,0.1]), ARD=True)
|
||||
k2 = GPy.kern.RBF(5, variance=1, lengthscale=1./np.random.dirichlet(np.r_[10,0.1,10,0.1,10]), ARD=True)
|
||||
|
|
@ -325,10 +333,10 @@ def test_gplvm():
|
|||
A = np.random.multivariate_normal(np.zeros(N), k1.K(X), Q).T
|
||||
B = np.random.multivariate_normal(np.zeros(N), k2.K(X), Q).T
|
||||
C = np.random.multivariate_normal(np.zeros(N), k3.K(X), Q).T
|
||||
|
||||
|
||||
Y = np.vstack((A,B,C))
|
||||
labels = np.hstack((np.zeros(A.shape[0]), np.ones(B.shape[0]), np.ones(C.shape[0])*2))
|
||||
|
||||
|
||||
k = RBF(Q, ARD=True, lengthscale=2) # + kern.white(Q, _np.exp(-2)) # + kern.bias(Q)
|
||||
m = GPLVM(Y, Q, init="PCA", kernel=k)
|
||||
m.kern.lengthscale[:] = [1./.3, 1./.1, 1./.7]
|
||||
|
|
@ -341,7 +349,7 @@ def test_gplvm():
|
|||
np.random.seed(111)
|
||||
m.plot_magnification(labels=labels)
|
||||
m.plot_steepest_gradient_map(resolution=10, data_labels=labels)
|
||||
for do_test in _image_comparison(baseline_images=['gplvm_{}'.format(sub) for sub in ["latent", "latent_3d", "magnification", 'gradient']],
|
||||
for do_test in _image_comparison(baseline_images=['gplvm_{}'.format(sub) for sub in ["latent", "latent_3d", "magnification", 'gradient']],
|
||||
extensions=extensions,
|
||||
tol=12):
|
||||
yield (do_test, )
|
||||
|
|
@ -355,7 +363,7 @@ def test_bayesian_gplvm():
|
|||
matplotlib.rcParams[u'figure.figsize'] = (4,3)
|
||||
matplotlib.rcParams[u'text.usetex'] = False
|
||||
Q = 3
|
||||
# Define dataset
|
||||
# Define dataset
|
||||
N = 10
|
||||
k1 = GPy.kern.RBF(5, variance=1, lengthscale=1./np.random.dirichlet(np.r_[10,10,10,0.1,0.1]), ARD=True)
|
||||
k2 = GPy.kern.RBF(5, variance=1, lengthscale=1./np.random.dirichlet(np.r_[10,0.1,10,0.1,10]), ARD=True)
|
||||
|
|
@ -364,10 +372,10 @@ def test_bayesian_gplvm():
|
|||
A = np.random.multivariate_normal(np.zeros(N), k1.K(X), Q).T
|
||||
B = np.random.multivariate_normal(np.zeros(N), k2.K(X), Q).T
|
||||
C = np.random.multivariate_normal(np.zeros(N), k3.K(X), Q).T
|
||||
|
||||
|
||||
Y = np.vstack((A,B,C))
|
||||
labels = np.hstack((np.zeros(A.shape[0]), np.ones(B.shape[0]), np.ones(C.shape[0])*2))
|
||||
|
||||
|
||||
k = RBF(Q, ARD=True, lengthscale=2) # + kern.white(Q, _np.exp(-2)) # + kern.bias(Q)
|
||||
m = BayesianGPLVM(Y, Q, init="PCA", kernel=k)
|
||||
m.kern.lengthscale[:] = [1./.3, 1./.1, 1./.7]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue