Пример #1
0
    def testFastGallery(self):

        tf = Hartman3()
        kernel = tf.createKernel(GaussianKernel_ard)
        X = lhcSample(tf.bounds, 10, seed=23)
        Y = [tf.f(x) for x in X]
        prefs = query2prefs(X, tf.f)

        GP = PrefGaussianProcess(kernel)
        GP.addPreferences(prefs)

        gallery = fastUCBGallery(GP, tf.bounds, 4)
        print('gallery returned:')
        for x in gallery:
            print('\t', x)

        GP.addPreferences(query2prefs(gallery, tf.f))

        # make sure we don't return anything out of bounds
        bounds = copy(tf.bounds)
        bounds[0] = [0., 0.]
        gallery = fastUCBGallery(GP, bounds, 4)
        print('gallery returned:')
        for x in gallery:
            print('\t', x)
            for v, b in zip(x, bounds):
                self.failUnless(v >= b[0] and v <= b[1])
Пример #2
0
 def testFastGallery(self):
     
     tf = Hartman3()
     kernel = tf.createKernel(GaussianKernel_ard)
     X = lhcSample(tf.bounds, 10, seed=23)
     Y = [tf.f(x) for x in X]
     prefs = query2prefs(X, tf.f)
     
     GP = PrefGaussianProcess(kernel)
     GP.addPreferences(prefs)
 
     gallery = fastUCBGallery(GP, tf.bounds, 4)
     print 'gallery returned:'
     for x in gallery:
         print '\t', x
         
     GP.addPreferences(query2prefs(gallery, tf.f))
     
     # make sure we don't return anything out of bounds
     bounds = copy(tf.bounds)
     bounds[0] = [0., 0.]
     gallery = fastUCBGallery(GP, bounds, 4)        
     print 'gallery returned:'
     for x in gallery:
         print '\t', x
         for v, b in zip(x, bounds):
             self.failUnless(v>=b[0] and v<=b[1])
Пример #3
0
def demoPrefGallery():
    """
    A simpler demo, showing how to use a preference gallery.  This demo
    is not interactive -- it uses the 6D Hartman test function to generate
    the preferences.
    """

    N = 3  # gallery size

    # use the Hartman6 test function, which has a kernel and bounds predefined
    tf = Hartman6()
    bounds = tf.bounds
    kernel = tf.createKernel(GaussianKernel_ard)

    # set up a Preference Gaussian Process, in which the observations are
    # preferences, rather than scalars
    GP = PrefGaussianProcess(kernel)

    # initial preferences -- since we have no informative prior on the space,
    # the gallery will be a set of points that maximize variance
    gallery = fastUCBGallery(GP, bounds, N)

    # this is a utility function for automtically testing the preferences --
    # given a test functions and some sample points, it will return a list of
    # preferences
    prefs = query2prefs(gallery, tf.f)

    # preferences have the form [r, c, degree], where r is preferred to c.
    # degree is degree of preference.  Just leave degree at 0 for now.
    for r, c, _ in prefs:
        print '%s preferred to %s' % (r, c)

    # add preferences to the model
    GP.addPreferences(prefs)

    # get another gallery, but with the first three dimensions fixed to .5
    nbounds = deepcopy(bounds)
    nbounds[:3] = [[.5, .5]] * 3

    gallery = fastUCBGallery(GP, nbounds, N)
    prefs = query2prefs(gallery, tf.f)
    for r, c, _ in prefs:
        print '%s preferred to %s' % (r, c)

    # get another gallery, but with the *last* three dimensions fixed to .5
    nbounds = deepcopy(bounds)
    nbounds[3:] = [[.5, .5]] * 3

    gallery = fastUCBGallery(GP, nbounds, N)
    prefs = query2prefs(gallery, tf.f)
    for r, c, _ in prefs:
        print '%s preferred to %s' % (r, c)

    # preferences don't have to come from the gallery
    r = array([0, 0, .5, 0, 1, .25])
    c = array([1, 1, .75, 1, 0, .5])
    pref = (r, c, 0)
    GP.addPreferences([pref])
Пример #4
0
def demoPrefGallery():
    """
    A simpler demo, showing how to use a preference gallery.  This demo
    is not interactive -- it uses the 6D Hartman test function to generate
    the preferences.
    """
    
    N = 3   # gallery size
    
    # use the Hartman6 test function, which has a kernel and bounds predefined
    tf = Hartman6()
    bounds = tf.bounds
    kernel = tf.createKernel(GaussianKernel_ard)
    
    # set up a Preference Gaussian Process, in which the observations are
    # preferences, rather than scalars
    GP = PrefGaussianProcess(kernel)
    
    # initial preferences -- since we have no informative prior on the space, 
    # the gallery will be a set of points that maximize variance
    gallery = fastUCBGallery(GP, bounds, N)
    
    # this is a utility function for automtically testing the preferences -- 
    # given a test functions and some sample points, it will return a list of 
    # preferences
    prefs = query2prefs(gallery, tf.f)
    
    # preferences have the form [r, c, degree], where r is preferred to c.  
    # degree is degree of preference.  Just leave degree at 0 for now.
    for r, c, _ in prefs:
        print '%s preferred to %s' % (r, c)
        
    # add preferences to the model
    GP.addPreferences(prefs)
    
    # get another gallery, but with the first three dimensions fixed to .5
    nbounds = deepcopy(bounds)
    nbounds[:3] = [[.5,.5]]*3
    
    gallery = fastUCBGallery(GP, nbounds, N)
    prefs = query2prefs(gallery, tf.f)
    for r, c, _ in prefs:
        print '%s preferred to %s' % (r, c)
    
    # get another gallery, but with the *last* three dimensions fixed to .5
    nbounds = deepcopy(bounds)
    nbounds[3:] = [[.5,.5]]*3

    gallery = fastUCBGallery(GP, nbounds, N)
    prefs = query2prefs(gallery, tf.f)
    for r, c, _ in prefs:
        print '%s preferred to %s' % (r, c)
    
    # preferences don't have to come from the gallery
    r = array([0, 0, .5, 0, 1, .25])
    c = array([1, 1, .75, 1, 0, .5])
    pref = (r, c, 0)
    GP.addPreferences([pref])