[testing] more restructuring, almost ready to ship, added some tests for testing with travis

This commit is contained in:
mzwiessele 2015-10-04 16:10:35 +01:00
parent 831e032ade
commit fa8f73326e
65 changed files with 628 additions and 1046 deletions

View file

@ -31,11 +31,10 @@ import numpy as np
import GPy, os, sys
from nose import SkipTest
raise SkipTest('Not Testing plotting yet, will be later')
try:
from matplotlib import cbook
import matplotlib
matplotlib.rcParams['text.usetex'] = False
except:
raise SkipTest("Matplotlib not installed, not testing plots")
@ -66,120 +65,57 @@ matplotlib.testing.decorators._image_directories = _image_directories
from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
@image_comparison(baseline_images=['gp'], extensions=['pdf','png'])
@image_comparison(baseline_images=['gp_{}'.format(sub) for sub in ["data", "mean", 'conf', 'density', 'error']], extensions=['pdf','png'])
def testPlot():
fig, ax = plt.subplots()
np.random.seed(11111)
X = np.random.uniform(0, 1, (40, 1))
f = .2 * np.sin(1.3*X) + 1.3*np.cos(2*X)
Y = f+np.random.normal(0, .1, f.shape)
m = GPy.models.GPRegression(X, Y)
m.optimize()
m.plot_data(ax=ax)
m.plot_mean(ax=ax)
m.plot_mean(ax=ax, plot_raw=True)
m.plot_mean(ax=ax, apply_link=True)
m.plot_mean(ax=ax, plot_raw=True, apply_link=True)
m.plot_confidence(ax=ax)
m.plot_density(ax=ax)
return ax
m.plot_data()
m.plot_mean()
m.plot_confidence()
m.plot_density()
m.plot_errorbars_trainset()
@image_comparison(baseline_images=['sparse_gp_{}'.format(sub) for sub in ["data", "mean", 'conf', 'density', 'error', 'inducing']], extensions=['pdf','png'])
def testPlotSparse():
np.random.seed(11111)
X = np.random.uniform(0, 1, (40, 1))
f = .2 * np.sin(1.3*X) + 1.3*np.cos(2*X)
Y = f+np.random.normal(0, .1, f.shape)
m = GPy.models.SparseGPRegression(X, Y)
m.optimize()
m.plot_data()
m.plot_mean()
m.plot_confidence()
m.plot_density()
m.plot_errorbars_trainset()
m.plot_inducing()
@image_comparison(baseline_images=['gp_class'], extensions=['pdf','png'])
@image_comparison(baseline_images=['gp_class_{}'.format(sub) for sub in ["", "raw", 'link', 'raw_link']], extensions=['pdf','png'])
def testPlotClassification():
fig, ax = plt.subplots()
np.random.seed(11111)
X = np.random.uniform(0, 1, (40, 1))
f = .2 * np.sin(1.3*X) + 1.3*np.cos(2*X)
Y = f+np.random.normal(0, .1, f.shape)
m = GPy.models.GPClassification(X, Y>Y.mean())
m.optimize()
m.plot_data(ax=ax)
m.plot_mean(ax=ax)
m.plot_mean(ax=ax, plot_raw=True)
m.plot_mean(ax=ax, apply_link=True)
m.plot_mean(ax=ax, plot_raw=True, apply_link=True)
m.plot_confidence(ax=ax)
m.plot_confidence(ax=ax, plot_raw=True)
m.plot_confidence(ax=ax, apply_link=True)
m.plot_confidence(ax=ax, plot_raw=True, apply_link=True)
m.plot_density(ax=ax)
m.plot_density(ax=ax, plot_raw=True)
m.plot_density(ax=ax, apply_link=True)
m.plot_density(ax=ax, plot_raw=True, apply_link=True)
return ax
m.plot()
m.plot(plot_raw=True)
m.plot(plot_raw=False, apply_link=True)
m.plot(plot_raw=True, apply_link=True)
@image_comparison(baseline_images=['sparse_gp_class'], extensions=['pdf','png'])
@image_comparison(baseline_images=['sparse_gp_class_{}'.format(sub) for sub in ["", "raw", 'link', 'raw_link']], extensions=['pdf','png'])
def testPlotSparseClassification():
fig, ax = plt.subplots()
np.random.seed(11111)
X = np.random.uniform(0, 1, (40, 1))
f = .2 * np.sin(1.3*X) + 1.3*np.cos(2*X)
Y = f+np.random.normal(0, .1, f.shape)
m = GPy.models.SparseGPClassification(X, Y>Y.mean())
m.optimize()
m.plot_data(ax=ax)
m.plot_mean(ax=ax)
m.plot_mean(ax=ax, plot_raw=True)
m.plot_mean(ax=ax, apply_link=True)
m.plot_mean(ax=ax, plot_raw=True, apply_link=True)
m.plot_confidence(ax=ax)
m.plot_confidence(ax=ax, plot_raw=True)
m.plot_confidence(ax=ax, apply_link=True)
m.plot_confidence(ax=ax, plot_raw=True, apply_link=True)
m.plot_density(ax=ax)
m.plot_density(ax=ax, plot_raw=True)
m.plot_density(ax=ax, apply_link=True)
m.plot_density(ax=ax, plot_raw=True, apply_link=True)
m.plot_inducing(ax=ax)
return ax
@image_comparison(baseline_images=['sparse_gp'], extensions=['pdf','png'])
def testPlotSparse():
fig, ax = plt.subplots()
np.random.seed(11111)
X = np.random.uniform(0, 1, (40, 1))
f = .2 * np.sin(1.3*X) + 1.3*np.cos(2*X)
Y = f+np.random.normal(0, .1, f.shape)
m = GPy.models.SparseGPRegression(X, Y)
m.optimize()
m.plot_data(ax=ax)
m.plot_mean(ax=ax)
m.plot_mean(ax=ax, plot_raw=True)
m.plot_mean(ax=ax, apply_link=True)
m.plot_mean(ax=ax, plot_raw=True, apply_link=True)
m.plot_confidence(ax=ax)
m.plot_confidence(ax=ax, plot_raw=True)
m.plot_confidence(ax=ax, apply_link=True)
m.plot_confidence(ax=ax, plot_raw=True, apply_link=True)
m.plot_density(ax=ax)
m.plot_density(ax=ax, plot_raw=True)
m.plot_density(ax=ax, apply_link=True)
m.plot_density(ax=ax, plot_raw=True, apply_link=True)
m.plot_inducing(ax=ax)
return ax
@image_comparison(baseline_images=['sparse_latent'], extensions=['pdf','png'])
def testPlotSparse():
fig, ax = plt.subplots()
np.random.seed(11111)
X = np.random.uniform(0, 1, (40, 1))
f = .2 * np.sin(1.3*X) + 1.3*np.cos(2*X)
Y = f+np.random.normal(0, .1, f.shape)
m = GPy.models.SparseGPRegression(X, Y)
m.optimize()
m.plot_data(ax=ax)
m.plot_mean(ax=ax)
m.plot_mean(ax=ax, plot_raw=True)
m.plot_mean(ax=ax, apply_link=True)
m.plot_mean(ax=ax, plot_raw=True, apply_link=True)
m.plot_confidence(ax=ax)
m.plot_confidence(ax=ax, plot_raw=True)
m.plot_confidence(ax=ax, apply_link=True)
m.plot_confidence(ax=ax, plot_raw=True, apply_link=True)
m.plot_density(ax=ax)
m.plot_density(ax=ax, plot_raw=True)
m.plot_density(ax=ax, apply_link=True)
m.plot_density(ax=ax, plot_raw=True, apply_link=True)
m.plot_inducing(ax=ax)
return ax
m.plot()
m.plot(plot_raw=True)
m.plot(plot_raw=False, apply_link=True)
m.plot(plot_raw=True, apply_link=True)