mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-10 20:42:39 +02:00
hard-merging in the examples and testing dirs from master.
This is probably a dumb way to do it, but I don;t know better.
This commit is contained in:
parent
8022de2a86
commit
375e2f6225
16 changed files with 1747 additions and 758 deletions
|
|
@ -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):
|
||||
|
|
@ -18,29 +19,27 @@ class ExamplesTests(unittest.TestCase):
|
|||
def _model_instance(self, Model):
|
||||
self.assertTrue(isinstance(Model, GPy.models))
|
||||
|
||||
"""
|
||||
def model_instance_generator(model):
|
||||
def check_model_returned(self):
|
||||
self._model_instance(model)
|
||||
return check_model_returned
|
||||
|
||||
def checkgrads_generator(model):
|
||||
def model_checkgrads(self):
|
||||
self._checkgrad(model)
|
||||
return model_checkgrads
|
||||
"""
|
||||
|
||||
def model_checkgrads(model):
|
||||
model.randomize()
|
||||
#assert model.checkgrad()
|
||||
return model.checkgrad()
|
||||
#NOTE: Step as 1e-4, this should be acceptable for more peaky models
|
||||
return model.checkgrad(step=1e-4)
|
||||
|
||||
def model_instance(model):
|
||||
#assert isinstance(model, GPy.core.model)
|
||||
return isinstance(model, GPy.core.model)
|
||||
return isinstance(model, GPy.core.model.Model)
|
||||
|
||||
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 +53,36 @@ def test_models():
|
|||
print "After"
|
||||
print functions
|
||||
for example in functions:
|
||||
if example[0] in ['oil', 'silhouette', 'GPLVM_oil_100']:
|
||||
print "SKIPPING"
|
||||
continue
|
||||
if example[0] in ['epomeo_gpx']:
|
||||
#These are the edge cases that we might want to handle specially
|
||||
if example[0] == 'epomeo_gpx' and not GPy.util.datasets.gpxpy_available:
|
||||
print "Skipping as gpxpy is not available to parse GPS"
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue