https://github.com/GPflow/GPflow
Revision 3d31426422309d9e87c9edd986b2e4012e1153ff authored by alexggmatthews on 22 April 2016, 11:39:58 UTC, committed by alexggmatthews on 22 April 2016, 11:39:58 UTC
1 parent 6b21982
Raw File
Tip revision: 3d31426422309d9e87c9edd986b2e4012e1153ff authored by alexggmatthews on 22 April 2016, 11:39:58 UTC
Moving snelson data to a data directory and renaming.
Tip revision: 3d31426
test_priors.py
import unittest
import GPflow
import numpy as np

class PriorModeTests(unittest.TestCase):
    """
    these tests optimize the prior to find the mode numerically. Make sure the
    mode is the same as the known mode.
    """
    def setUp(self):
        class FlatModel(GPflow.model.Model):
            def build_likelihood(self):
                return 0
        self.m = FlatModel()
    
    def testGaussianMode(self):
        self.m.x = GPflow.param.Param(1.0)
        self.m.x.prior = GPflow.priors.Gaussian(3,1)
        self.m.optimize(display=0)

        xmax = self.m.get_free_state()
        self.failUnless(np.allclose(xmax, 3))

    def testGaussianModeMatrix(self):
        self.m.x = GPflow.param.Param(np.random.randn(4,4))
        self.m.x.prior = GPflow.priors.Gaussian(-1,10)
        self.m.optimize(display=0)

        xmax = self.m.get_free_state()
        self.failUnless(np.allclose(xmax, -1))

    def testGammaMode(self):
        self.m.x = GPflow.param.Param(1.0)
        shape, scale = 4., 5.
        self.m.x.prior = GPflow.priors.Gamma(shape, scale)
        self.m.optimize(display=0)

        print self.m.x._array, (shape - 1) * scale
        self.failUnless(np.allclose(self.m.x._array, (shape -1.) * scale, 1e-3))







if __name__ == "__main__":
    unittest.main()

back to top