コード例 #1
0
    def test5DPreferences(self):
        def foo(x):
            return sum(x)

        X = [
            array([.1, .2, .3, .4]),
            array([.7, .2, .3, .4]),
            array([.5, .5, .5, .5]),
            array([.5, .5, .5, .5]),
            array([.5, .8, .5, .5]),
            array([.5, .9, .9, .1]),
            array([.2, .6, .1, .5])
        ]

        GP = PrefGaussianProcess(GaussianKernel_iso(array([.1])))
        for i in xrange(len(X)):
            for j in xrange(i):
                if foo(X[i]) == foo(X[j]):
                    continue
                elif foo(X[i]) > foo(X[j]):
                    p = [X[i], X[j], 0]
                else:
                    p = [X[j], X[i], 0]
                GP.addPreferences([p])

        for i in xrange(len(GP.X)):
            for j in xrange(i):
                # print 'foo = %.1f, GP = %.3f vs foo = %.1f, GP = %.3f' % (foo(GP.X[i]), GP.Y[i], foo(GP.X[j]), GP.Y[j])
                if foo(GP.X[i]) > foo(GP.X[j]):
                    self.failUnless(GP.mu(GP.X[i]) > GP.mu(GP.X[j]))
                else:
                    self.failUnless(GP.mu(GP.X[j]) > GP.mu(GP.X[i]))
コード例 #2
0
ファイル: unittest_GP.py プロジェクト: johnchia/IBO
 def test5DPreferences(self):
     
     def foo(x):
         return sum(x)
         
     X = [array([.1, .2, .3, .4]),
          array([.7, .2, .3, .4]),
          array([.5, .5, .5, .5]),
          array([.5, .5, .5, .5]),
          array([.5, .8, .5, .5]),
          array([.5, .9, .9, .1]),
          array([.2, .6, .1, .5])]
     
     GP = PrefGaussianProcess(GaussianKernel_iso(array([.1])))
     for i in xrange(len(X)):
         for j in xrange(i):
             if foo(X[i]) == foo(X[j]):
                 continue
             elif foo(X[i]) > foo(X[j]):
                 p = [X[i], X[j], 0]
             else:
                 p = [X[j], X[i], 0]
             GP.addPreferences([p])
     
     for i in xrange(len(GP.X)):
         for j in xrange(i):
             # print 'foo = %.1f, GP = %.3f vs foo = %.1f, GP = %.3f' % (foo(GP.X[i]), GP.Y[i], foo(GP.X[j]), GP.Y[j])
             if foo(GP.X[i]) > foo(GP.X[j]):
                 self.failUnless(GP.mu(GP.X[i]) > GP.mu(GP.X[j]))
             else:
                 self.failUnless(GP.mu(GP.X[j]) > GP.mu(GP.X[i]))
コード例 #3
0
    def test1DPreferences(self):

        showit = False  # show figures for debugging

        x1 = array([.2])
        x2 = array([.7])
        x3 = array([.4])
        x4 = array([.35])
        x5 = array([.9])
        x6 = array([.1])

        GP = PrefGaussianProcess(GaussianKernel_ard(array([.1])))
        GP.addPreferences([(x1, x2, 0)])
        self.failUnless(GP.mu(x1) > GP.mu(x2))
        # print GP.X

        if showit:
            figure(1)
            clf()
            S = arange(0, 1, .01)
            ax = subplot(1, 3, 1)
            ax.plot(S, [GP.mu(x) for x in S], 'k-')
            ax.plot(GP.X, GP.Y, 'ro')

        GP.addPreferences([(x3, x4, 0)])
        self.failUnless(GP.mu(x1) > GP.mu(x2))
        self.failUnless(GP.mu(x3) > GP.mu(x4))

        if showit:
            ax = subplot(1, 3, 2)
            ax.plot(S, [GP.mu(x) for x in S], 'k-')
            ax.plot(GP.X, GP.Y, 'ro')

        # x5 is greatly preferred to x6 - we should expect f(x5)-f(x6) to have
        # the most pronounced difference
        GP.addPreferences([(x5, x6, 1)])
        self.failUnless(GP.mu(x1) > GP.mu(x2))
        self.failUnless(GP.mu(x3) > GP.mu(x4))
        self.failUnless(GP.mu(x5) > GP.mu(x6))
        self.failUnless(GP.mu(x5) - GP.mu(x6) > GP.mu(x1) - GP.mu(x2))
        self.failUnless(GP.mu(x5) - GP.mu(x6) > GP.mu(x3) - GP.mu(x4))

        if showit:
            ax = subplot(1, 3, 3)
            ax.plot(S, [GP.mu(x) for x in S], 'k-')
            ax.plot(GP.X, GP.Y, 'ro')

            show()
コード例 #4
0
ファイル: unittest_GP.py プロジェクト: johnchia/IBO
    def test1DPreferences(self):
        
        showit = False  # show figures for debugging
        
        x1 = array([.2])
        x2 = array([.7])
        x3 = array([.4])
        x4 = array([.35])
        x5 = array([.9])
        x6 = array([.1])
        
        GP = PrefGaussianProcess(GaussianKernel_ard(array([.1])))
        GP.addPreferences([(x1, x2, 0)])
        self.failUnless(GP.mu(x1) > GP.mu(x2))
        # print GP.X
        
        if showit:
            figure(1)
            clf()
            S = arange(0, 1, .01)
            ax = subplot(1, 3, 1)
            ax.plot(S, [GP.mu(x) for x in S], 'k-')
            ax.plot(GP.X, GP.Y, 'ro')
        
        GP.addPreferences([(x3, x4, 0)])
        self.failUnless(GP.mu(x1) > GP.mu(x2))
        self.failUnless(GP.mu(x3) > GP.mu(x4))

        if showit:
            ax = subplot(1, 3, 2)
            ax.plot(S, [GP.mu(x) for x in S], 'k-')
            ax.plot(GP.X, GP.Y, 'ro')

        # x5 is greatly preferred to x6 - we should expect f(x5)-f(x6) to have 
        # the most pronounced difference
        GP.addPreferences([(x5, x6, 1)])
        self.failUnless(GP.mu(x1) > GP.mu(x2))
        self.failUnless(GP.mu(x3) > GP.mu(x4))
        self.failUnless(GP.mu(x5) > GP.mu(x6))
        self.failUnless(GP.mu(x5)-GP.mu(x6) > GP.mu(x1)-GP.mu(x2))
        self.failUnless(GP.mu(x5)-GP.mu(x6) > GP.mu(x3)-GP.mu(x4))
        
        if showit:
            ax = subplot(1, 3, 3)
            ax.plot(S, [GP.mu(x) for x in S], 'k-')
            ax.plot(GP.X, GP.Y, 'ro')

            show()