Пример #1
0
def expand_test2():
    k1 = fk.MaskKernel(2, 0, fk.SqExpKernel(1, 1))
    k2 = fk.MaskKernel(2, 1, fk.SqExpPeriodicKernel(2, 2, 2))
    e = fk.SumKernel([k1, k2])

    g = grammar.MultiDGrammar(2)

    print ''
    for f in grammar.expand(e, g):
        print f.pretty_print()
        print grammar.canonical(f).pretty_print()
        print

    print '   ***** duplicates removed  *****'
    print

    kernels = grammar.expand(e, g)
    for f in grammar.remove_duplicates(kernels):
        print f.pretty_print()
        print

    print '%d originally, %d without duplicates' % (
        len(kernels), len(grammar.remove_duplicates(kernels)))

    print 'expand_test complete'
Пример #2
0
def expand_test():  
    k1 = fk.SqExpKernel(1, 1)
    k2 = fk.SqExpPeriodicKernel(2, 2, 2)
    e = fk.SumKernel([k1, k2])
    
    g = grammar.OneDGrammar()
    
    print ''
    for f in grammar.expand(e, g):
        #print f
        print f.pretty_print()
        print grammar.canonical(f).pretty_print()
        print
        
    print '   ***** duplicates removed  *****'
    print
    
    kernels = grammar.expand(e, g)
    for f in grammar.remove_duplicates(kernels):
        print f.pretty_print()
        print
        
    print '%d originally, %d without duplicates' % (len(kernels), len(grammar.remove_duplicates(kernels)))
        
    print 'expand_test complete'
Пример #3
0
 def expand(self, base_kernels='SE'):
     """
     Expand this kernel using grammar defined in grammar.py.
     :returns: list of GPCKernel resulting from the expansion
     """
     ndim = self.data.getDim()
     g = grammar.MultiDGrammar(ndim, base_kernels=base_kernels, rules=None)
     kernels = grammar.expand(self.kernel, g)
     kernels = [k.canonical() for k in kernels]
     kernels = ff.remove_duplicates(kernels)
     for k in kernels:
         k.initialise_params(data_shape=self.data.getDataShape())
     kernels = [k.simplified() for k in kernels]
     kernels = ff.remove_duplicates(kernels)
     kernels = [k for k in kernels if not isinstance(k, ff.NoneKernel)]
     kernels = [GPCKernel(k, self.data, depth=self.depth+1, parent=self) for k in kernels]
     return kernels
Пример #4
0
def fear_expand_kernels(D, seed_kernels, verbose=False):
    '''
    Just expands
    '''

    g = grammar.MultiDGrammar(D)
    print 'Seed kernels :'
    for k in seed_kernels:
        print k.pretty_print()
    kernels = []
    for k in seed_kernels:
        kernels = kernels + grammar.expand(k, g)
    kernels = grammar.remove_duplicates(kernels)
    print 'Expanded kernels :'
    for k in kernels:
        print k.pretty_print()

    return (kernels)
Пример #5
0
def fear_expand_kernels(D, seed_kernels, verbose=False):    
    '''
    Just expands
    '''
       
    g = grammar.MultiDGrammar(D)
    print 'Seed kernels :'
    for k in seed_kernels:
        print k.pretty_print()
    kernels = []
    for k in seed_kernels:
        kernels = kernels + grammar.expand(k, g)
    kernels = grammar.remove_duplicates(kernels)
    print 'Expanded kernels :'
    for k in kernels:
        print k.pretty_print()
            
    return (kernels)
Пример #6
0
 def expand(self, base_kernels='SE'):
     """
     Expand this kernel using grammar defined in grammar.py.
     :returns: list of GPCKernel resulting from the expansion
     """
     ndim = self.data.getDim()
     g = grammar.MultiDGrammar(ndim, base_kernels=base_kernels, rules=None)
     kernels = grammar.expand(self.kernel, g)
     kernels = [k.canonical() for k in kernels]
     kernels = ff.remove_duplicates(kernels)
     for k in kernels:
         k.initialise_params(data_shape=self.data.getDataShape())
     kernels = [k.simplified() for k in kernels]
     kernels = ff.remove_duplicates(kernels)
     kernels = [k for k in kernels if not isinstance(k, ff.NoneKernel)]
     kernels = [
         GPCKernel(k, self.data, depth=self.depth + 1, parent=self)
         for k in kernels
     ]
     return kernels