mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-05 14:55:15 +02:00
Fixed examples tests, started changing datasets code which has a few bugs
This commit is contained in:
parent
9e6cc7ea6e
commit
f26455f2b2
3 changed files with 39 additions and 18 deletions
|
|
@ -206,6 +206,7 @@ def _simulate_sincos(D1, D2, D3, N, num_inducing, Q, plot_sim=False):
|
|||
|
||||
if plot_sim:
|
||||
import pylab
|
||||
import matplotlib.cm as cm
|
||||
import itertools
|
||||
fig = pylab.figure("MRD Simulation Data", figsize=(8, 6))
|
||||
fig.clf()
|
||||
|
|
@ -216,7 +217,7 @@ def _simulate_sincos(D1, D2, D3, N, num_inducing, Q, plot_sim=False):
|
|||
ax.legend()
|
||||
for i, Y in enumerate(Ylist):
|
||||
ax = fig.add_subplot(2, len(Ylist), len(Ylist) + 1 + i)
|
||||
ax.imshow(Y, aspect='auto', cmap=cm.gray) # @UndefinedVariable
|
||||
ax.imshow(Y, aspect='auto', cmap=cm.gray)
|
||||
ax.set_title("Y{}".format(i + 1))
|
||||
pylab.draw()
|
||||
pylab.tight_layout()
|
||||
|
|
@ -450,9 +451,12 @@ def cmu_mocap(subject='35', motion=['01'], in_place=True, optimize=True, verbose
|
|||
if in_place:
|
||||
# Make figure move in place.
|
||||
data['Y'][:, 0:3] = 0.0
|
||||
|
||||
m = GPy.models.GPLVM(data['Y'], 2, normalize_Y=True)
|
||||
|
||||
if optimize: m.optimize(messages=verbose, max_f_eval=10000)
|
||||
if optimize:
|
||||
m.optimize(messages=verbose, max_f_eval=10000)
|
||||
|
||||
if plot:
|
||||
ax = m.plot_latent()
|
||||
y = m.likelihood.Y[0, :]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import os
|
|||
import random
|
||||
from nose.tools import nottest
|
||||
import sys
|
||||
import itertools
|
||||
|
||||
class ExamplesTests(unittest.TestCase):
|
||||
def _checkgrad(self, Model):
|
||||
|
|
@ -39,8 +40,19 @@ def model_instance(model):
|
|||
#assert isinstance(model, GPy.core.model)
|
||||
return isinstance(model, GPy.core.model.Model)
|
||||
|
||||
@nottest
|
||||
def flatten_nested(lst):
|
||||
result = []
|
||||
for element in lst:
|
||||
if hasattr(element, '__iter__'):
|
||||
result.extend(flatten_nested(element))
|
||||
else:
|
||||
result.append(element)
|
||||
return result
|
||||
|
||||
#@nottest
|
||||
def test_models():
|
||||
optimize=False
|
||||
plot=True
|
||||
examples_path = os.path.dirname(GPy.examples.__file__)
|
||||
# Load modules
|
||||
failing_models = {}
|
||||
|
|
@ -54,29 +66,34 @@ def test_models():
|
|||
print "After"
|
||||
print functions
|
||||
for example in functions:
|
||||
if example[0] in ['oil', 'silhouette', 'GPLVM_oil_100', 'brendan_faces']:
|
||||
print "SKIPPING"
|
||||
continue
|
||||
#if example[0] in ['oil', 'silhouette', 'GPLVM_oil_100', 'brendan_faces']:
|
||||
#print "SKIPPING"
|
||||
#continue
|
||||
|
||||
print "Testing example: ", example[0]
|
||||
# Generate model
|
||||
|
||||
try:
|
||||
model = example[1]()
|
||||
models = [ example[1](optimize=optimize, plot=plot) ]
|
||||
#If more than one model returned, flatten them
|
||||
models = flatten_nested(models)
|
||||
except Exception as e:
|
||||
failing_models[example[0]] = "Cannot make model: \n{e}".format(e=e)
|
||||
else:
|
||||
print model
|
||||
print models
|
||||
model_checkgrads.description = 'test_checkgrads_%s' % example[0]
|
||||
try:
|
||||
if not model_checkgrads(model):
|
||||
failing_models[model_checkgrads.description] = False
|
||||
for model in models:
|
||||
if not model_checkgrads(model):
|
||||
failing_models[model_checkgrads.description] = False
|
||||
except Exception as e:
|
||||
failing_models[model_checkgrads.description] = e
|
||||
|
||||
model_instance.description = 'test_instance_%s' % example[0]
|
||||
try:
|
||||
if not model_instance(model):
|
||||
failing_models[model_instance.description] = False
|
||||
for model in models:
|
||||
if not model_instance(model):
|
||||
failing_models[model_instance.description] = False
|
||||
except Exception as e:
|
||||
failing_models[model_instance.description] = e
|
||||
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ def simulation_BGPLVM():
|
|||
Y = np.array(mat_data['Y'], dtype=float)
|
||||
S = np.array(mat_data['initS'], dtype=float)
|
||||
mu = np.array(mat_data['initMu'], dtype=float)
|
||||
return data_details_return({'S': S, 'Y': Y, 'mu': mu}, data_set)
|
||||
#return data_details_return({'S': S, 'Y': Y, 'mu': mu}, data_set)
|
||||
return {'Y': Y, 'S': S,
|
||||
'mu' : mu,
|
||||
'info': "Simulated test dataset generated in MATLAB to compare BGPLVM between python and MATLAB"}
|
||||
|
|
@ -594,11 +594,11 @@ def olympic_sprints(data_set='rogers_girolami_data'):
|
|||
'Y': Y,
|
||||
'info': "Olympics sprint event winning for men and women to 2008. Data is from Rogers and Girolami's First Course in Machine Learning.",
|
||||
'output_info': {
|
||||
0:'100m Men',
|
||||
1:'100m Women',
|
||||
2:'200m Men',
|
||||
3:'200m Women',
|
||||
4:'400m Men',
|
||||
0:'100m Men',
|
||||
1:'100m Women',
|
||||
2:'200m Men',
|
||||
3:'200m Women',
|
||||
4:'400m Men',
|
||||
5:'400m Women'}
|
||||
}, data_set)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue