def disp_deformed_grid_lines(self,level,color=None,lw=1): # return if self.hlines is None or self.vlines is None: raise ValueError hlines,vlines=self.hlines,self.vlines # for lines,c in zip([hlines,vlines],['r','b']): # pts_at_0=np.asarray([lines[:,0,:].flatten(), # lines[:,1,:].flatten()]).T # pts_at_0 = CpuGpuArray(pts_at_0.copy()) # pts_at_T=CpuGpuArray.zeros_like(pts_at_0) # self.calc_T_fwd(pts_src=pts_at_0, # pts_fwd=pts_at_T, # level=level,verbose=0,int_quality=1) # if self.nCols != self.nCols: # raise NotImplementedError # pts_at_T.gpu2cpu() # lines_new_x=pts_at_T.cpu[:,0].reshape(lines[:,0,:].shape).copy() # lines_new_y=pts_at_T.cpu[:,1].reshape(lines[:,0,:].shape).copy() # for line_new_x,line_new_y in zip(lines_new_x,lines_new_y): # # plt.plot(line_new_x,line_new_y,c) if color is None: colors=['r','b'] else: colors=[color,color] s = hlines.shape if s[2]<=1: raise ValueError p = 0 L = 50000 if L >=s[2]: while p < np.ceil(s[2]): hlines=self.hlines[:,:,p:p+L] vlines=self.vlines[:,:,p:p+L] p+=L for lines,c in zip([hlines,vlines],colors): pts_at_0=np.asarray([lines[:,0,:].flatten(), lines[:,1,:].flatten()]).T if pts_at_0.size==0: break pts_at_0 = CpuGpuArray(pts_at_0.copy()) pts_at_T=CpuGpuArray.zeros_like(pts_at_0) self.calc_T_fwd(pts_src=pts_at_0, pts_fwd=pts_at_T, level=level,int_quality=1) if self.nCols != self.nCols: raise NotImplementedError pts_at_T.gpu2cpu() lines_new_x=pts_at_T.cpu[:,0].reshape(lines[:,0,:].shape).copy() lines_new_y=pts_at_T.cpu[:,1].reshape(lines[:,0,:].shape).copy() for line_new_x,line_new_y in zip(lines_new_x,lines_new_y): plt.plot(line_new_x,line_new_y,c,lw=lw) else: raise NotImplementedError
if __name__ == '__main__': from pycuda import autoinit from of.gpu import CpuGpuArray import numpy as np msg=""" The code below is for landmarks, not signals""" raise NotImplementedError(msg) yy,xx = np.mgrid[-2:2:1,-2:2:1] x = np.vstack([xx.ravel(),yy.ravel()]).T del xx,yy x = CpuGpuArray(x.copy().astype(np.float)) print x y = np.random.standard_normal(x.shape) y = CpuGpuArray(y) err = CpuGpuArray.zeros_like(y) nPts = len(err) ll = CpuGpuArray.zeros(nPts) calc_signal_err_per_sample(x.gpu,y.gpu,err.gpu) sigma=1.0 calc_ll_per_sample(ll.gpu,err.gpu,sigma) err.gpu2cpu()
def disp_orig_grid_lines(self,level,color=None,lw=1): # return try: self.hlines self.vlines except AttributeError: raise Exception("You need to call create_grid_lines first") if self.hlines is None: raise ValueError if self.vlines is None: self.vlines = self.hlines hlines,vlines=self.hlines,self.vlines s = hlines.shape if s[2]<=1: raise ValueError p = 0 L = 50000 if color is None: colors=['r','b'] else: colors=[color,color] if L >=s[2]: while p < np.ceil(s[2]): hlines=self.hlines[:,:,p:p+L] vlines=self.vlines[:,:,p:p+L] p+=L-1 for lines,c in zip([hlines,vlines],colors): pts_at_0=np.asarray([lines[:,0,:].flatten(), lines[:,1,:].flatten()]).T if pts_at_0.size==0: break # print _pts_at_0.shape pts_at_0 = CpuGpuArray(pts_at_0.copy()) if self.nCols != self.nCols: raise NotImplementedError pts_at_0.gpu2cpu() lines_new_x=pts_at_0.cpu[:,0].reshape(lines[:,0,:].shape).copy() lines_new_y=pts_at_0.cpu[:,1].reshape(lines[:,0,:].shape).copy() for line_new_x,line_new_y in zip(lines_new_x,lines_new_y): plt.plot(line_new_x,line_new_y,c,lw=lw) else: hlines=self.hlines vlines=self.vlines for lines,c in zip([hlines,vlines],colors): pts_at_0=np.asarray([lines[:,0,:].flatten(), lines[:,1,:].flatten()]).T if pts_at_0.size==0: break # print _pts_at_0.shape pts_at_0 = CpuGpuArray(pts_at_0.copy()) if self.nCols != self.nCols: raise NotImplementedError pts_at_0.gpu2cpu() lines_new_x=pts_at_0.cpu[:,0].reshape(lines[:,0,:].shape).copy() lines_new_y=pts_at_0.cpu[:,1].reshape(lines[:,0,:].shape).copy() for line_new_x,line_new_y in zip(lines_new_x,lines_new_y): plt.plot(line_new_x,line_new_y,c,lw=lw)
def disp_deformed_grid_lines(self, level, color=None, lw=1): # return if self.hlines is None or self.vlines is None: raise ValueError hlines, vlines = self.hlines, self.vlines # for lines,c in zip([hlines,vlines],['r','b']): # pts_at_0=np.asarray([lines[:,0,:].flatten(), # lines[:,1,:].flatten()]).T # pts_at_0 = CpuGpuArray(pts_at_0.copy()) # pts_at_T=CpuGpuArray.zeros_like(pts_at_0) # self.calc_T_fwd(pts_src=pts_at_0, # pts_fwd=pts_at_T, # level=level,verbose=0,int_quality=1) # if self.nCols != self.nCols: # raise NotImplementedError # pts_at_T.gpu2cpu() # lines_new_x=pts_at_T.cpu[:,0].reshape(lines[:,0,:].shape).copy() # lines_new_y=pts_at_T.cpu[:,1].reshape(lines[:,0,:].shape).copy() # for line_new_x,line_new_y in zip(lines_new_x,lines_new_y): # # plt.plot(line_new_x,line_new_y,c) if color is None: colors = ['r', 'b'] else: colors = [color, color] s = hlines.shape if s[2] <= 1: raise ValueError p = 0 L = 50000 if L >= s[2]: while p < np.ceil(s[2]): hlines = self.hlines[:, :, p:p + L] vlines = self.vlines[:, :, p:p + L] p += L for lines, c in zip([hlines, vlines], colors): pts_at_0 = np.asarray( [lines[:, 0, :].flatten(), lines[:, 1, :].flatten()]).T if pts_at_0.size == 0: break pts_at_0 = CpuGpuArray(pts_at_0.copy()) pts_at_T = CpuGpuArray.zeros_like(pts_at_0) self.calc_T_fwd(pts_src=pts_at_0, pts_fwd=pts_at_T, level=level, int_quality=1) if self.nCols != self.nCols: raise NotImplementedError pts_at_T.gpu2cpu() lines_new_x = pts_at_T.cpu[:, 0].reshape( lines[:, 0, :].shape).copy() lines_new_y = pts_at_T.cpu[:, 1].reshape( lines[:, 0, :].shape).copy() for line_new_x, line_new_y in zip(lines_new_x, lines_new_y): plt.plot(line_new_x, line_new_y, c, lw=lw) else: raise NotImplementedError
def disp_orig_grid_lines(self, level, color=None, lw=1): # return try: self.hlines self.vlines except AttributeError: raise Exception("You need to call create_grid_lines first") if self.hlines is None: raise ValueError if self.vlines is None: self.vlines = self.hlines hlines, vlines = self.hlines, self.vlines s = hlines.shape if s[2] <= 1: raise ValueError p = 0 L = 50000 if color is None: colors = ['r', 'b'] else: colors = [color, color] if L >= s[2]: while p < np.ceil(s[2]): hlines = self.hlines[:, :, p:p + L] vlines = self.vlines[:, :, p:p + L] p += L - 1 for lines, c in zip([hlines, vlines], colors): pts_at_0 = np.asarray( [lines[:, 0, :].flatten(), lines[:, 1, :].flatten()]).T if pts_at_0.size == 0: break # print _pts_at_0.shape pts_at_0 = CpuGpuArray(pts_at_0.copy()) if self.nCols != self.nCols: raise NotImplementedError pts_at_0.gpu2cpu() lines_new_x = pts_at_0.cpu[:, 0].reshape( lines[:, 0, :].shape).copy() lines_new_y = pts_at_0.cpu[:, 1].reshape( lines[:, 0, :].shape).copy() for line_new_x, line_new_y in zip(lines_new_x, lines_new_y): plt.plot(line_new_x, line_new_y, c, lw=lw) else: hlines = self.hlines vlines = self.vlines for lines, c in zip([hlines, vlines], colors): pts_at_0 = np.asarray( [lines[:, 0, :].flatten(), lines[:, 1, :].flatten()]).T if pts_at_0.size == 0: break # print _pts_at_0.shape pts_at_0 = CpuGpuArray(pts_at_0.copy()) if self.nCols != self.nCols: raise NotImplementedError pts_at_0.gpu2cpu() lines_new_x = pts_at_0.cpu[:, 0].reshape( lines[:, 0, :].shape).copy() lines_new_y = pts_at_0.cpu[:, 1].reshape( lines[:, 0, :].shape).copy() for line_new_x, line_new_y in zip(lines_new_x, lines_new_y): plt.plot(line_new_x, line_new_y, c, lw=lw)
_calc_ll_per_sample(ll, err, np.float64(sigma)) if __name__ == '__main__': from pycuda import autoinit from of.gpu import CpuGpuArray import numpy as np msg = """ The code below is for landmarks, not signals""" raise NotImplementedError(msg) yy, xx = np.mgrid[-2:2:1, -2:2:1] x = np.vstack([xx.ravel(), yy.ravel()]).T del xx, yy x = CpuGpuArray(x.copy().astype(np.float)) print x y = np.random.standard_normal(x.shape) y = CpuGpuArray(y) err = CpuGpuArray.zeros_like(y) nPts = len(err) ll = CpuGpuArray.zeros(nPts) calc_signal_err_per_sample(x.gpu, y.gpu, err.gpu) sigma = 1.0 calc_ll_per_sample(ll.gpu, err.gpu, sigma) err.gpu2cpu() ll.gpu2cpu()