Ejemplo n.º 1
0
    def testFromEmptyGP(self):
        # test a GP that has no data to start
        f = lambda x: float(sin(x * 10) + x)
        kernel = GaussianKernel_iso(array([1.0]))
        GP = GaussianProcess(kernel)

        for x in arange(0., 1., .1):
            GP.addData(array([x]), f(x))

        for x in arange(1., 2., .1):
            GP.addData(array([x]), f(x))

        self.failUnlessEqual(len(GP.X), 20)
Ejemplo n.º 2
0
 def testFromEmptyGP(self):
     # test a GP that has no data to start
     f = lambda x: float(sin(x*10)+x)
     kernel = GaussianKernel_iso(array([1.0]))
     GP = GaussianProcess(kernel)
     
     for x in arange(0., 1., .1):
         GP.addData(array([x]), f(x))
         
     for x in arange(1., 2., .1):
         GP.addData(array([x]), f(x))
     
     self.failUnlessEqual(len(GP.X), 20)
Ejemplo n.º 3
0
    def testTraining(self):

        # test that sequential training gives the same result as batch

        tf = Shekel5()
        X = lhcSample(tf.bounds, 25, seed=1)
        Y = [tf.f(x) for x in X]

        # GP1 adds all data during initialization
        GP1 = GaussianProcess(GaussianKernel_iso([.1]), X, Y, noise=.2)

        # GP2 adds data one at a time
        GP2 = GaussianProcess(GaussianKernel_iso([.1]), noise=.2)

        # GP3 uses addData()
        GP3 = GaussianProcess(GaussianKernel_iso([.1]), noise=.2)

        # GP4 adds using various methods
        GP4 = GaussianProcess(GaussianKernel_iso([.1]),
                              X[:10],
                              Y[:10],
                              noise=.2)

        for x, y in zip(X, Y):
            GP2.addData(x, y)

        for i in xrange(0, 25, 5):
            GP3.addData(X[i:i + 5], Y[i:i + 5])

        GP4.addData(X[10], Y[10])
        GP4.addData(X[11:18], Y[11:18])
        for i in xrange(18, 25):
            GP4.addData(X[i], Y[i])

        self.failUnless(all(GP1.R == GP2.R))
        self.failUnless(all(GP1.R == GP3.R))
        self.failUnless(all(GP1.R == GP4.R))

        testX = lhcSample(tf.bounds, 25, seed=2)
        for x in testX:
            mu1, s1 = GP1.posterior(x)
            mu2, s2 = GP2.posterior(x)
            mu3, s3 = GP3.posterior(x)
            mu4, s4 = GP4.posterior(x)
            self.failUnlessEqual(mu1, mu2)
            self.failUnlessEqual(mu1, mu3)
            self.failUnlessEqual(mu1, mu4)
            self.failUnlessEqual(s1, s2)
            self.failUnlessEqual(s1, s3)
            self.failUnlessEqual(s1, s4)
Ejemplo n.º 4
0
 def testTraining(self):
     
     # test that sequential training gives the same result as batch
     
     tf = Shekel5()
     X = lhcSample(tf.bounds, 25, seed=1)
     Y = [tf.f(x) for x in X]
     
     # GP1 adds all data during initialization
     GP1 = GaussianProcess(GaussianKernel_iso([.1]), X, Y, noise=.2)
     
     # GP2 adds data one at a time
     GP2 = GaussianProcess(GaussianKernel_iso([.1]), noise=.2)
     
     # GP3 uses addData()
     GP3 = GaussianProcess(GaussianKernel_iso([.1]), noise=.2)
     
     # GP4 adds using various methods
     GP4 = GaussianProcess(GaussianKernel_iso([.1]), X[:10], Y[:10], noise=.2)
     
     for x, y in zip(X, Y):
         GP2.addData(x, y)
         
     for i in xrange(0, 25, 5):
         GP3.addData(X[i:i+5], Y[i:i+5])
     
     GP4.addData(X[10], Y[10])
     GP4.addData(X[11:18], Y[11:18])
     for i in xrange(18, 25):
         GP4.addData(X[i], Y[i])
     
     
     self.failUnless(all(GP1.R==GP2.R))
     self.failUnless(all(GP1.R==GP3.R))
     self.failUnless(all(GP1.R==GP4.R))
     
     testX = lhcSample(tf.bounds, 25, seed=2)
     for x in testX:
         mu1, s1 = GP1.posterior(x)
         mu2, s2 = GP2.posterior(x)
         mu3, s3 = GP3.posterior(x)
         mu4, s4 = GP4.posterior(x)
         self.failUnlessEqual(mu1, mu2)
         self.failUnlessEqual(mu1, mu3)
         self.failUnlessEqual(mu1, mu4)
         self.failUnlessEqual(s1, s2)
         self.failUnlessEqual(s1, s3)
         self.failUnlessEqual(s1, s4)