Example #1
0
    def test_from_dict(self):
        test_cases = (GPModel, Serializable)
        for cls in test_cases:
            with self.subTest(name=cls.__name__):
                kernel = Covariance(RBF(1) * RBF(1) + RationalQuadratic(1))
                gp_model = GPModel(kernel)
                actual = cls.from_dict(gp_model.to_dict())

                self.assertIsInstance(actual, GPModel)
                self.assertEqual(gp_model.likelihood, actual.likelihood)
                self.assertEqual(gp_model.covariance.infix, actual.covariance.infix)
Example #2
0
    def test_to_dict(self):
        test_cases = (
            (None, 'None score'),
            (10., 'Positive score')
        )
        for score, description in test_cases:
            with self.subTest(description=description):
                kernel = Covariance(RBF(1) * RBF(1) + RationalQuadratic(1))
                gp_model = GPModel(kernel)
                gp_model.score = score

                actual = gp_model.to_dict()

                self.assertIsInstance(actual, dict)

                self.assertIn('likelihood', actual)
                self.assertIn('covariance', actual)
                self.assertIn('score', actual)

                self.assertEqual(None, actual['likelihood'])
                self.assertEqual(gp_model.covariance.to_dict(), actual['covariance'])
                self.assertEqual(gp_model.score, actual['score'])