mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-08 15:05:15 +02:00
format on save
This commit is contained in:
parent
2eb237f656
commit
f48837e01d
1 changed files with 25 additions and 14 deletions
|
|
@ -12,6 +12,7 @@ from nose.tools import nottest
|
|||
import sys
|
||||
import itertools
|
||||
|
||||
|
||||
class ExamplesTests(unittest.TestCase):
|
||||
def _checkgrad(self, Model):
|
||||
self.assertTrue(Model.checkgrad())
|
||||
|
|
@ -19,27 +20,31 @@ class ExamplesTests(unittest.TestCase):
|
|||
def _model_instance(self, Model):
|
||||
self.assertTrue(isinstance(Model, GPy.models))
|
||||
|
||||
|
||||
def model_checkgrads(model):
|
||||
model.randomize()
|
||||
#NOTE: Step as 1e-4, this should be acceptable for more peaky models
|
||||
# NOTE: Step as 1e-4, this should be acceptable for more peaky models
|
||||
return model.checkgrad(step=1e-4)
|
||||
|
||||
|
||||
def model_instance(model):
|
||||
return isinstance(model, GPy.core.model.Model)
|
||||
|
||||
|
||||
def flatten_nested(lst):
|
||||
result = []
|
||||
for element in lst:
|
||||
if hasattr(element, '__iter__'):
|
||||
if hasattr(element, "__iter__"):
|
||||
result.extend(flatten_nested(element))
|
||||
else:
|
||||
result.append(element)
|
||||
return result
|
||||
|
||||
|
||||
@nottest
|
||||
def test_models():
|
||||
optimize=False
|
||||
plot=True
|
||||
optimize = False
|
||||
plot = True
|
||||
examples_path = os.path.dirname(GPy.examples.__file__)
|
||||
# Load modules
|
||||
failing_models = {}
|
||||
|
|
@ -49,13 +54,19 @@ def test_models():
|
|||
print("MODULE", module_examples)
|
||||
print("Before")
|
||||
print(inspect.getmembers(module_examples, predicate=inspect.isfunction))
|
||||
functions = [ func for func in inspect.getmembers(module_examples, predicate=inspect.isfunction) if func[0].startswith('_') is False ][::-1]
|
||||
functions = [
|
||||
func
|
||||
for func in inspect.getmembers(
|
||||
module_examples, predicate=inspect.isfunction
|
||||
)
|
||||
if func[0].startswith("_") is False
|
||||
][::-1]
|
||||
print("After")
|
||||
print(functions)
|
||||
for example in functions:
|
||||
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:
|
||||
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
|
||||
|
||||
|
|
@ -63,14 +74,14 @@ def test_models():
|
|||
# Generate model
|
||||
|
||||
try:
|
||||
models = [ example[1](optimize=optimize, plot=plot) ]
|
||||
#If more than one model returned, flatten them
|
||||
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(models)
|
||||
model_checkgrads.description = 'test_checkgrads_%s' % example[0]
|
||||
model_checkgrads.description = "test_checkgrads_%s" % example[0]
|
||||
try:
|
||||
for model in models:
|
||||
if not model_checkgrads(model):
|
||||
|
|
@ -78,7 +89,7 @@ def test_models():
|
|||
except Exception as e:
|
||||
failing_models[model_checkgrads.description] = e
|
||||
|
||||
model_instance.description = 'test_instance_%s' % example[0]
|
||||
model_instance.description = "test_instance_%s" % example[0]
|
||||
try:
|
||||
for model in models:
|
||||
if not model_instance(model):
|
||||
|
|
@ -86,8 +97,8 @@ def test_models():
|
|||
except Exception as e:
|
||||
failing_models[model_instance.description] = e
|
||||
|
||||
#yield model_checkgrads, model
|
||||
#yield model_instance, model
|
||||
# yield model_checkgrads, model
|
||||
# yield model_instance, model
|
||||
|
||||
print("Finished checking module {m}".format(m=module_name))
|
||||
if len(failing_models.keys()) > 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue