def init_rois(self, n_components=100, show=False): Ain, Cin, center = greedyROI2d(self.Y, nr=n_components, gSig=[2, 2], gSiz=[7, 7], use_median=False) Cn = np.mean(self.Y, axis=-1) if show: pl1 = pl.imshow(Cn, interpolation='none') pl.colorbar() pl.scatter(x=center[:, 1], y=center[:, 0], c='m', s=40) pl.axis((-0.5, self.Y.shape[1] - 0.5, -0.5, self.Y.shape[0] - 0.5)) pl.gca().invert_yaxis() active_pixels = np.squeeze(np.nonzero(np.sum(Ain, axis=1))) Yr = np.reshape(self.Y, (self.Y.shape[0] * self.Y.shape[1], self.Y.shape[2]), order='F') P = arpfit(Yr, p=2, pixels=active_pixels) Y_res = Yr - np.dot(Ain, Cin) model = ProjectedGradientNMF(n_components=1, init='random', random_state=0) model.fit(np.maximum(Y_res, 0)) fin = model.components_.squeeze() self.Yr, self.Cin, self.fin, self.Ain, self.P, self.Cn = Yr, Cin, fin, Ain, P, Cn
def init_rois(self, n_components=100, show=False): Ain,Cin,center = greedyROI2d(self.Y, nr=n_components, gSig=[2,2], gSiz=[7,7], use_median=False) Cn = np.mean(self.Y, axis=-1) if show: pl1 = pl.imshow(Cn,interpolation='none') pl.colorbar() pl.scatter(x=center[:,1], y=center[:,0], c='m', s=40) pl.axis((-0.5,self.Y.shape[1]-0.5,-0.5,self.Y.shape[0]-0.5)) pl.gca().invert_yaxis() active_pixels = np.squeeze(np.nonzero(np.sum(Ain,axis=1))) Yr = np.reshape(self.Y,(self.Y.shape[0]*self.Y.shape[1],self.Y.shape[2]),order='F') P = arpfit(Yr, p=2, pixels=active_pixels) Y_res = Yr - np.dot(Ain,Cin) model = ProjectedGradientNMF(n_components=1, init='random', random_state=0) model.fit(np.maximum(Y_res,0)) fin = model.components_.squeeze() self.Yr,self.Cin,self.fin,self.Ain,self.P,self.Cn = Yr,Cin,fin,Ain,P,Cn
Y=[] for idx,y in enumerate(Yp): Y.append(np.rot90(y,k=-1)) Y=np.transpose(np.array(Y),(1,2,0)) #%% #Ymat = sio.loadmat('Y.mat') Y1 = Ymat['Y']*1. #%% d1,d2,T = np.shape(Y) #%% greedy initialization nr = 30 t1 = time() Ain,Cin,center = greedyROI2d(Y, nr = nr, gSig = [4,4], gSiz = [9,9]) t_elGREEDY = time()-t1 #%% arpfit active_pixels = np.squeeze(np.nonzero(np.sum(Ain,axis=1))) Yr = np.reshape(Y,(d1*d2,T),order='F') p = 2; P = arpfit(Yr,p=2,pixels = active_pixels) #%% nmf Y_res = Yr - np.dot(Ain,Cin) model = ProjectedGradientNMF(n_components=1, init='random', random_state=0) model.fit(np.maximum(Y_res,0))
#%% #Y=np.load('M_FLUO_mc.npz')['mov'] #Y=Y[:,5:-5,5:-5] #%% Y=np.asarray(m) Y = np.transpose(Y,(1,2,0)) #Ymat = sio.loadmat('Y.mat') #Y = Ymat['Y']*1. d1,d2,T = np.shape(Y) #%% nr = 20 # neuron numbers t1 = time() Ain,Cin,center = greedyROI2d(Y, nr = nr, gSig = [4,4], gSiz = [9,9], use_median = False) t_elGREEDY = time()-t1 #%% plot centers Cn = local_correlations(Y) plt1 = plt.imshow(Cn,interpolation='none') plt.colorbar() plt.scatter(x=center[:,1], y=center[:,0], c='m', s=40) plt.axis((-0.5,d2-0.5,-0.5,d1-0.5)) plt.gca().invert_yaxis() #%% crd = plot_contours(coo_matrix(Ain[:,::-1]),Cn,thr=0.9) #%% active_pixels = np.squeeze(np.nonzero(np.sum(Ain,axis=1))) Yr = np.reshape(Y,(d1*d2,T),order='F')
Y = [] for idx, y in enumerate(Yp): Y.append(np.rot90(y, k=-1)) Y = np.transpose(np.array(Y), (1, 2, 0)) #%% #Ymat = sio.loadmat('Y.mat') Y1 = Ymat['Y'] * 1. #%% d1, d2, T = np.shape(Y) #%% greedy initialization nr = 30 t1 = time() Ain, Cin, center = greedyROI2d(Y, nr=nr, gSig=[4, 4], gSiz=[9, 9]) t_elGREEDY = time() - t1 #%% arpfit active_pixels = np.squeeze(np.nonzero(np.sum(Ain, axis=1))) Yr = np.reshape(Y, (d1 * d2, T), order='F') p = 2 P = arpfit(Yr, p=2, pixels=active_pixels) #%% nmf Y_res = Yr - np.dot(Ain, Cin) model = ProjectedGradientNMF(n_components=1, init='random', random_state=0) model.fit(np.maximum(Y_res, 0))