Revision 6c35a7a8544dfecfe92ef9b559b90fcb40b364eb authored by Mark van der Wilk on 20 November 2017, 17:43:17 UTC, committed by GitHub on 20 November 2017, 17:43:17 UTC
* Add Features base classes

* Convert SGPR and SVGP models to use InducingFeatures (including backwards compatibility)

* Fix tests

* Added Multiscale feature.
To show the generality of the inter-domain code.

* Fixed py2 metaclass issue, as per John Bradshaw's suggestion.

* Improve docstrings, register Multiscale feature

* Change SGPR models to determine feature length dynamically [but feature.__len__() still needs to be made dynamic as well!]

* Bits and pieces missed in the merge.

* Add features to __init__.

* Fixed incorrect parameter dtype assignment on compile.

* Two bugfixs.
- Static assignment of len(feature)
- Upper bound mixin referred to Z.

* Fixed bugs in multiscale & added features.

* Added tests for `Multiscale` inducing features.

* Updated `RELEASE.md`, and small changes for tests.

* add test for len(feature)

* Deprecation property for `Z`, relative imports, improved test.

* `SGPMC` has inducing features now + better docstrings.

* Fixed `SGPMC`.

* Testing now uses tf1.4.

* `feat` now `feature` + other changes.

* Update _version.py

* change exception
1 parent 0741f86
Raw File
test_config.py
# Copyright 2017 the GPflow authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.from __future__ import print_function


# pylint: disable=W0212

import os
import tensorflow as tf
import gpflow

from gpflow.test_util import GPflowTestCase

CONFIG_TXT = """
[first_section]
a_bool = false
a_float = 1e-3
a_string = hello
a_type = float64

[second_section]
a_bool = true
another_bool = True
yet_another_bool = False
"""

class TestConfigParsing(GPflowTestCase):
    config_filename = None

    @classmethod
    def setUpClass(cls):
        directory = tf.test.get_temp_dir()
        cls.config_filename = os.path.join(directory, 'gpflowrc_test.txt')
        with open(cls.config_filename, 'w') as fd:
            fd.write(CONFIG_TXT)

    @classmethod
    def tearDownClass(cls):
        os.remove(cls.config_filename)
        super().tearDownClass()

    def setUp(self):
        self.conf = gpflow._settings._read_config_file(self.config_filename)
        self.settings = gpflow._settings._namedtuplify(self.conf._sections)

    def test(self):
        self.assertTrue(all([
            self.settings.first_section.a_bool is False,
            self.settings.first_section.a_float == 1e-3,
            self.settings.first_section.a_string == 'hello',
            self.settings.first_section.a_type is tf.float64,
            self.settings.second_section.a_bool is True,
            self.settings.second_section.another_bool is True,
            self.settings.second_section.yet_another_bool is False]))

    def test_config_not_found(self):
        filename = "./config_not_found.txt"
        with self.assertRaises(RuntimeError):
            gpflow._settings._read_config_file(filename)

    def test_parser(self):
        with self.assertRaises(ValueError):
            gpflow._settings._parse(None)

        with self.assertRaises(ValueError):
            gpflow._settings._parse(12)

        with self.assertRaises(ValueError):
            gpflow._settings._parse([])

        self.assertEqual(gpflow._settings._parse('false'), False)
        self.assertEqual(gpflow._settings._parse('False'), False)
        self.assertEqual(gpflow._settings._parse('true'), True)
        self.assertEqual(gpflow._settings._parse('True'), True)
        self.assertEqual(gpflow._settings._parse('int32'), tf.int32)
        self.assertEqual(gpflow._settings._parse('32'), 32)
        self.assertEqual(gpflow._settings._parse('32.'), 32.)
        self.assertEqual(gpflow._settings._parse('int'), 'int')
        self.assertEqual(gpflow._settings._parse('hello'), 'hello')
        self.assertEqual(gpflow._settings._parse('1E2'), 1e2)
        self.assertEqual(gpflow._settings._parse('1e-9'), 1e-9)


class TestSettingsManager(GPflowTestCase):
    def testRaises(self):
        with self.assertRaises(AttributeError):
            gpflow.settings.undefined_setting_to_raise_error

    def testMutability(self):
        orig = gpflow.settings.verbosity.hmc_verb
        gpflow.settings.verbosity.hmc_verb = False
        self.assertEqual(gpflow.settings.verbosity.hmc_verb, False)
        gpflow.settings.verbosity.hmc_verb = True
        self.assertEqual(gpflow.settings.verbosity.hmc_verb, True)
        gpflow.settings.verbosity.hmc_verb = orig

    def testContextManager(self):
        orig = gpflow.settings.verbosity.hmc_verb
        gpflow.settings.verbosity.hmc_verb = True
        config = gpflow.settings.get_settings()
        config.verbosity.hmc_verb = False
        self.assertEqual(gpflow.settings.verbosity.hmc_verb, True)
        with gpflow.settings.temp_settings(config):
            self.assertEqual(gpflow.settings.verbosity.hmc_verb, False)
        self.assertEqual(gpflow.settings.verbosity.hmc_verb, True)
        gpflow.settings.verbosity.hmc_verb = orig


if __name__ == '__main__':
    tf.test.main()
back to top