def compare_kernels_experiment():
    kernel1 = fk.Carls_Mauna_kernel()
    kernel2  = ( fk.SqExpKernel(-0.7, -1.3) + fk.SqExpKernel(4.8, 2.3) ) * \
               ( fk.SqExpKernel(3.0, 0.5) + fk.SqExpPeriodicKernel(0.4, -0.0, -0.9) )
    #kernel2 = ( SqExp(ell=-0.8, sf=-1.4) + Periodic(ell=0.5, p=-0.3, sf=-1.1) + RQ(ell=1.9, sf=1.6, a=0.2) + ( SqExp(ell=4.5, sf=1.0) x Periodic(ell=0.6, p=-0.0, sf=0.1) )  )

    X, y = load_mauna_original()
    N_orig = X.shape[0]  # subsample data.
    X = X[:N_orig // 5, :]
    y = y[:N_orig // 5, :]

    print "Carl's kernel"
    print kernel1.pretty_print()
    kernel_hypers1, nll1 = gpml.optimize_params(kernel1.gpml_kernel_expression(), kernel1.param_vector(), \
                                                X, y, noise=np.log(0.19), iters=100 )
    k1_opt = kernel1.family().from_param_vector(kernel_hypers1)
    print k1_opt.pretty_print()
    print "Carl's NLL =", nll1

    print "Our kernel"
    print kernel2.pretty_print()
    kernel_hypers2, nll2 = gpml.optimize_params(kernel2.gpml_kernel_expression(), kernel2.param_vector(), \
                                                X, y, noise=np.log(0.19), iters=100)
    k2_opt = kernel2.family().from_param_vector(kernel_hypers2)
    print k2_opt.pretty_print()

    print "Our NLL =", nll2
Beispiel #2
0
def compare_kernels_experiment():
    kernel1 = fk.Carls_Mauna_kernel()
    kernel2  = ( fk.SqExpKernel(-0.7, -1.3) + fk.SqExpKernel(4.8, 2.3) ) * \
               ( fk.SqExpKernel(3.0, 0.5) + fk.SqExpPeriodicKernel(0.4, -0.0, -0.9) )
    #kernel2 = ( SqExp(ell=-0.8, sf=-1.4) + Periodic(ell=0.5, p=-0.3, sf=-1.1) + RQ(ell=1.9, sf=1.6, a=0.2) + ( SqExp(ell=4.5, sf=1.0) x Periodic(ell=0.6, p=-0.0, sf=0.1) )  )  
             
    X, y = load_mauna_original()
    N_orig = X.shape[0]  # subsample data.
    X = X[:N_orig//5, :]
    y = y[:N_orig//5, :]     
     
    print "Carl's kernel"
    print kernel1.pretty_print()
    kernel_hypers1, nll1 = gpml.optimize_params(kernel1.gpml_kernel_expression(), kernel1.param_vector(), \
                                                X, y, noise=np.log(0.19), iters=100 )
    k1_opt = kernel1.family().from_param_vector(kernel_hypers1)
    print k1_opt.pretty_print()   
    print "Carl's NLL =", nll1 
    
    print "Our kernel"
    print kernel2.pretty_print()
    kernel_hypers2, nll2 = gpml.optimize_params(kernel2.gpml_kernel_expression(), kernel2.param_vector(), \
                                                X, y, noise=np.log(0.19), iters=100)
    k2_opt = kernel2.family().from_param_vector(kernel_hypers2)
    print k2_opt.pretty_print()            

    print "Our NLL =", nll2
Beispiel #3
0
def not_tet_num_params():
    '''The number of hyper-parameters passed in to gpml should be the same as the number returned.'''
    k = fk.SqExpKernel(0, 0)
    init_params = k.param_vector()
    X, y = load_mauna()
    optimized_hypers, _ = gpml.optimize_params(k.gpml_kernel_expression(), init_params, X, y)
    assert optimized_hypers.size == init_params.size
def not_tet_num_params():
    '''The number of hyper-parameters passed in to gpml should be the same as the number returned.'''
    k = fk.SqExpKernel(0, 0)
    init_params = k.param_vector()
    X, y = load_mauna()
    optimized_hypers, _ = gpml.optimize_params(k.gpml_kernel_expression(),
                                               init_params, X, y)
    assert optimized_hypers.size == init_params.size
def call_gpml_test():

    np.random.seed(0)

    k = fk.SumKernel([fk.SqExpKernel(0, 0), fk.SqExpKernel(0, 0)])
    print k.gpml_kernel_expression()
    print k.pretty_print()
    print '[%s]' % k.param_vector()

    X, y = load_mauna()

    N_orig = X.shape[0]
    X = X[:N_orig // 3, :]
    y = y[:N_orig // 3, :]

    results = []

    pylab.figure()
    for i in range(15):
        init_params = np.random.normal(size=k.param_vector().size)
        #kernel_hypers, nll, nlls = gpml.optimize_params(k.gpml_kernel_expression(), k.param_vector(), X, y, return_all=True)
        kernel_hypers, nll, nlls = gpml.optimize_params(
            k.gpml_kernel_expression(), init_params, X, y, return_all=True)

        print "kernel_hypers =", kernel_hypers
        print "nll =", nll

        k_opt = k.family().from_param_vector(kernel_hypers)
        print k_opt.gpml_kernel_expression()
        print k_opt.pretty_print()
        print '[%s]' % k_opt.param_vector()

        pylab.semilogx(range(1, nlls.size + 1), nlls)

        results.append((kernel_hypers, nll))

        pylab.draw()

    print
    print
    results = sorted(results, key=lambda p: p[1])
    for kernel_hypers, nll in results:
        print nll, kernel_hypers

    print "done"
Beispiel #6
0
def call_gpml_test():
    
    np.random.seed(0)
    
    k = fk.SumKernel([fk.SqExpKernel(0, 0), fk.SqExpKernel(0, 0)])
    print k.gpml_kernel_expression()
    print k.pretty_print()
    print '[%s]' % k.param_vector()

    X, y = load_mauna()
    
    N_orig = X.shape[0]
    X = X[:N_orig//3, :]
    y = y[:N_orig//3, :]

    results = []

    pylab.figure()
    for i in range(15):
        init_params = np.random.normal(size=k.param_vector().size)
        #kernel_hypers, nll, nlls = gpml.optimize_params(k.gpml_kernel_expression(), k.param_vector(), X, y, return_all=True)
        kernel_hypers, nll, nlls = gpml.optimize_params(k.gpml_kernel_expression(), init_params, X, y, return_all=True)
    
        print "kernel_hypers =", kernel_hypers
        print "nll =", nll
        
        k_opt = k.family().from_param_vector(kernel_hypers)
        print k_opt.gpml_kernel_expression()
        print k_opt.pretty_print()
        print '[%s]' % k_opt.param_vector()
        
        pylab.semilogx(range(1, nlls.size+1), nlls)
        
        results.append((kernel_hypers, nll))
        
        pylab.draw()
    
    print
    print
    results = sorted(results, key=lambda p: p[1])
    for kernel_hypers, nll in results:
        print nll, kernel_hypers
        
    print "done"