mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-24 14:15:14 +02:00
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
|
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
|
|
|
import unittest
|
|
import numpy as np
|
|
import GPy
|
|
import inspect
|
|
import pkgutil
|
|
import os
|
|
import random
|
|
from nose.tools import nottest
|
|
import sys
|
|
|
|
class ExamplesTests(unittest.TestCase):
|
|
def _checkgrad(self, Model):
|
|
self.assertTrue(Model.checkgrad())
|
|
|
|
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()
|
|
|
|
|
|
def model_instance(Model):
|
|
assert isinstance(Model, GPy.core.Model)
|
|
|
|
@nottest
|
|
def test_models():
|
|
examples_path = os.path.dirname(GPy.examples.__file__)
|
|
# Load modules
|
|
for loader, module_name, is_pkg in pkgutil.iter_modules([examples_path]):
|
|
# Load examples
|
|
module_examples = loader.find_module(module_name).load_module(module_name)
|
|
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]
|
|
print "After"
|
|
print functions
|
|
for example in functions:
|
|
if example[0] in ['oil', 'silhouette', 'GPLVM_oil_100']:
|
|
print "SKIPPING"
|
|
continue
|
|
|
|
print "Testing example: ", example[0]
|
|
# Generate Model
|
|
Model = example[1]()
|
|
print Model
|
|
|
|
# Create tests for instance check
|
|
"""
|
|
test = model_instance_generator(Model)
|
|
test.__name__ = 'test_instance_%s' % example[0]
|
|
setattr(ExamplesTests, test.__name__, test)
|
|
|
|
#Create tests for checkgrads check
|
|
test = checkgrads_generator(Model)
|
|
test.__name__ = 'test_checkgrads_%s' % example[0]
|
|
setattr(ExamplesTests, test.__name__, test)
|
|
"""
|
|
model_checkgrads.description = 'test_checkgrads_%s' % example[0]
|
|
yield model_checkgrads, Model
|
|
model_instance.description = 'test_instance_%s' % example[0]
|
|
yield model_instance, Model
|
|
|
|
if __name__ == "__main__":
|
|
print "Running unit tests, please be (very) patient..."
|
|
# unittest.main()
|
|
test_models()
|