示例#1
0
    n,D = x.shape
    ## DEFINE parameterized covariance function
    P = D # The dimension of the input
    N = 5
    covfunc = [ ['kernels.covSum'], [[ ['kernels.covProd'], P*[[ ['kernels.covSum'], N*[['kernels.covSpectralSingle']] ]] ], ['kernels.covNoise'] ] ]

    ## DEFINE parameterized mean function
    meanfunc = [ ['means.meanZero'] ]      

    ## DEFINE parameterized inference and liklihood functions
    inffunc = ['inferences.infExact']
    likfunc = ['likelihoods.likGauss']

    ## SET (hyper)parameters
    hyp = hyperParameters()

    ## SET (hyper)parameters for covariance and mean 
    hyp.cov = np.log(np.random.random(4*N*P+1))
    # Now replace the values of hyp.cov that correspond to the indices for P
    for ii in range(P):
        for jj in range(N):
            ind = ii*N*4 + jj*4 + 4
            hyp.cov[ind-1] =  ii

    hyp.mean = np.array([])

    sn = 0.1
    hyp.lik = np.array([np.log(sn)])

    ##----------------------------------------------------------##
示例#2
0
    ys = np.reshape(data[-N:, -1], (N, 1))
    ys = (ys - np.mean(ys)) / (np.std(ys) + 1.e-16)
    N, D = x.shape
    ## DEFINE parameterized covariance function
    covfunc = [['kernels.covSum'], [['kernels.covSEiso'],
                                    ['kernels.covNoise']]]

    ## DEFINE parameterized mean function
    meanfunc = [['means.meanZero']]

    ## DEFINE parameterized inference and liklihood functions
    inffunc = ['inferences.infExact']
    likfunc = ['likelihoods.likGauss']

    ## SET (hyper)parameters
    hyp = hyperParameters()

    ## SET (hyper)parameters for covariance and mean
    hyp.cov = np.random.normal(0., 1., (3, ))
    hyp.mean = np.array([])

    hyp.lik = np.array([np.log(0.1)])

    print 'Initial mean = ', hyp.mean
    print 'Initial covariance = ', hyp.cov
    print 'Initial liklihood = ', hyp.lik

    [nlml, post] = gp(hyp, inffunc, meanfunc, covfunc, likfunc, x, y, None,
                      None, False)
    print 'Initial negative log marginal likelihood = ', nlml
示例#3
0
     plt.axis([-1.9,1.9,-0.9,3.9])
     plt.grid()
     plt.xlabel('input x')
     plt.ylabel('output y')
     plt.show()         
 
 ## DEFINE parameterized mean and covariance functions
 covfunc  = [['kernels.covMatern']]
 meanfunc = [ ['means.meanSum'], [ ['means.meanLinear'] , ['means.meanConst'] ] ]
 ## DEFINE likelihood function used
 likfunc  = ['likelihoods.likGauss']
 ## SPECIFY inference method
 inffunc  = ['inferences.infExact']
 
 ## SET (hyper)parameters
 hyp = hyperParameters()
 hyp.cov = np.array([np.log(0.25),np.log(1.0),3.0])
 hyp.mean = np.array([0.5,1.0])
 hyp.lik = np.array([np.log(0.1)])
 
 ##----------------------------------------------------------##
 ## STANDARD GP (example 1)                                  ##
 ##----------------------------------------------------------##
 print '...example 1: prediction...'
 ## PREDICTION
 t0 = clock()
 vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,xstar)
 t1 = clock()
 ym = vargout[0]; ys2 = vargout[1]; m  = vargout[2]; s2 = vargout[3]
 
 print 'Time for prediction =',t1-t0
示例#4
0
        plt.axis([-1.9, 1.9, -0.9, 3.9])
        plt.grid()
        plt.xlabel('input x')
        plt.ylabel('output y')
        plt.show()

    ## DEFINE parameterized mean and covariance functions
    covfunc = [['kernels.covMatern']]
    meanfunc = [['means.meanSum'], [['means.meanLinear'], ['means.meanConst']]]
    ## DEFINE likelihood function used
    likfunc = ['likelihoods.likGauss']
    ## SPECIFY inference method
    inffunc = ['inferences.infExact']

    ## SET (hyper)parameters
    hyp = hyperParameters()
    hyp.cov = np.array([np.log(0.25), np.log(1.0), 3.0])
    hyp.mean = np.array([0.5, 1.0])
    hyp.lik = np.array([np.log(0.1)])

    ##----------------------------------------------------------##
    ## STANDARD GP (example 1)                                  ##
    ##----------------------------------------------------------##
    print '...example 1: prediction...'
    ## PREDICTION
    t0 = clock()
    vargout = gp(hyp, inffunc, meanfunc, covfunc, likfunc, x, y, xstar)
    t1 = clock()
    ym = vargout[0]
    ys2 = vargout[1]
    m = vargout[2]