def krig(self): """ Kriging interpolation""" # Break it down into smaller chunks MAXSIZE = 15e6 nchunks = np.ceil(self.grd.npts * self.NNear / MAXSIZE) if nchunks == 1: self.Finterp = kriging(self.XY, self.grd.ravel(), maxdist=self.maxdist, NNear=self.NNear) Z = self.Finterp(self.Zin) else: pt1, pt2 = tile_vector(int(self.grd.npts), int(nchunks)) Z = np.zeros((self.grd.npts, )) XYout = self.grd.ravel() for p1, p2 in zip(pt1, pt2): print 'Interpolating tile %d to %d of %d...' % (p1, p2, self.grd.npts) self.Finterp = kriging(self.XY, XYout[p1:p2, :], maxdist=self.maxdist, NNear=self.NNear) Z[p1:p2] = self.Finterp(self.Zin) self.Z = np.reshape(Z, (self.grd.ny, self.grd.nx))
def lnprob(s, CFG): ''' return the interpolated f here this is interpreted as a log-likelihood \ log-probability input: s - the point in space fr which we estimate the log-likelihood X - a list of locations in space F - a list of corresponding precalculated log-likelihoods C - an augmented covariance matrix M - an artificial bound on the distribution. we insist that if |x| > M (the sup norm) then the likelihood is zero (so the log-likelihood is -infinity) a hyper parameter, see the documentation for aux.cov(...) procedure ''' # M = CFG.M # # we ensure M > |s| in sup norm # # we should also make sure that all observations # # satisfy |X[j]| < M # if (np.linalg.norm(s, np.inf) > M): # return -np.inf # do kriging to estimate the the log likelihood in a new # location, given previous observations mu, sig = kg.kriging(s, CFG) # return the interpolated value only - no use for the std dev return mu
def _krig(self): """ Kriging interpolation""" self.Finterp = kriging(self.XY, self.XYout, maxdist=self.maxdist, NNear=self.NNear)
def krig(self): """ Kriging interpolation""" # Break it down into smaller chunks MAXSIZE = 15e6 nchunks = np.ceil(self.grd.npts*self.NNear/MAXSIZE) if nchunks == 1: self.Finterp = kriging(self.XY,self.grd.ravel(),maxdist=self.maxdist,NNear=self.NNear) Z = self.Finterp(self.Zin) else: pt1,pt2=tile_vector(int(self.grd.npts),int(nchunks)) Z = np.zeros((self.grd.npts,)) XYout = self.grd.ravel() for p1,p2 in zip(pt1,pt2): print 'Interpolating tile %d to %d of %d...'%(p1,p2,self.grd.npts) self.Finterp = kriging(self.XY,XYout[p1:p2,:],maxdist=self.maxdist,NNear=self.NNear) Z[p1:p2] = self.Finterp(self.Zin) self.Z = np.reshape(Z,(self.grd.ny,self.grd.nx))
def chooseSamplePoint( self ): ''' current criterion for evaluating LL is choose position of walker that maximizes likelihood*variance ''' return self.pos[0,:] maxScore = 0 ind = 0 for i in range(self.nwalkers): #ideally, the walker would carry this info krig, sig = kg.kriging( self.pos[i,:] , self.CFG ) # choose walker based on this made up score currScore = sig*krig if currScore > maxScore: ind = i maxScore = currScore return self.pos[ind,:]
def chooseSamplePoint(self): ''' current criterion for evaluating LL is choose position of walker that maximizes likelihood*variance ''' return self.pos[0, :] maxScore = 0 ind = 0 for i in range(self.nwalkers): #ideally, the walker would carry this info krig, sig = kg.kriging(self.pos[i, :], self.CFG) # choose walker based on this made up score currScore = sig * krig if currScore > maxScore: ind = i maxScore = currScore return self.pos[ind, :]
def _krig(self): """ Kriging interpolation""" self.Finterp = kriging(self.XY,self.XYout,maxdist=self.maxdist,NNear=self.NNear)
x2 = np.arange(0) y2 = np.arange(0) z2 = np.arange(0) for xi in x1: for yi in y1: #for zi in z: x2 = np.append(x2, [xi], axis=0) y2 = np.append(y2, [yi], axis=0) #z2=np.append(z2,[zi],axis=0)*0 z2 = x2 * 0 # 2D grid of sampled points proyected over a regular mesh: c1 = vecPointsToMatrix(x, y, values, NMeshPointsX, NMeshPointsY) # interpolation at the points on the regular mesh: krigingInterpolation = kriging(x, y, z, values, x2, y2, z2) # 2D matrix with the interpolated values: c2 = vecPointsToMatrix(x2, y2, krigingInterpolation, NMeshPointsX, NMeshPointsY) # For comparison with the model, # 2D exact value on the interpolated locations of dataModel(x,y): c3 = c2 * 0 print(c3.shape) for i in range(x1.shape[0]): for j in range(y1.shape[0]): c3[i, j] = dataModel(np.array([x1[i]]), np.array([y1[j]]))[0, 0] if True: fig = plt.figure() ax1 = fig.add_subplot(221)
from ga import ga from exp_imp import EGO k = 2 n = 5*2 # sampling plan X = lhs(k, samples=n) y = np.zeros((n, 1)) # find true values for i in range(k): y[i] = true_function(X[i], 1) # create kriging model kr = kriging(k, X, y) # train model kr.train() # plot prediction kr.plot_2d() E = EGO(kr) MinExpImp = 1e14 infill = 0 while abs(MinExpImp) > 1e-3 and infill < 3*n: Xnew, EI = E.next_infill() Ynew = true_function(Xnew, 1) kr.X = np.vstack((kr.X, Xnew))