def load_factors(): factors = [] for a in range(12, 15): for e in [1]: animal = param.animal_list[a] meta_df, roi_tensor, acti, norm_acti, smoothed_acti = data.load_processed_data_all( animal) days = set(meta_df.loc[meta_df['Experiment Class'] == e, 'Day'].tolist()) for d in days: path = os.path.join( paths.path2Output, animal, 'non_negative_parafac', 'random', '6', 'Day-[{}]_Experiment Class-[{}]'.format(d, e), 'factorsDay-[{}]_Experiment Class-[{}]_00.npy'.format( d, e)) print(path) factor = np.load(path) #Compute norms along columns for each factor matrix norms = [sci.linalg.norm(f, axis=0) for f in factor] # Multiply norms across all modes lam = sci.multiply.reduce(norms)**(1 / 3) # Update factors factor = [f * (lam / fn) for f, fn in zip(factor, norms)] factors.append(factor) return factors
def load_factors(method): """Load factors in order to generate global time factor Returns ------- list List of factors """ factors = [] for a in fixed_selection['Animal']: animal = param.animal_list[a] meta_df, roi_tensor, acti, norm_acti, smoothed_acti = data.load_processed_data_all( animal) for e in fixed_selection['Experiment Class']: days = set(meta_df.loc[meta_df['Experiment Class'] == e, 'Day'].tolist()) print(days) for day in days: current_fixed_selection = { 'Experiment Class': [e], 'Day': [day] } print(current_fixed_selection) name = ''.join([ '_' + k + '-' + str(current_fixed_selection[k]) for k in current_fixed_selection if not current_fixed_selection[k] == None ])[1:] path = os.path.join(paths.path2Output, animal, method, args.init, str(args.rank), name) if os.path.exists(path): factor = np.load( os.path.join(path, 'factors' + name + '_00.npy')) else: os.makedirs(path) _, acti_select, norm_acti_select, smoothed_acti_select = data.select_data( meta_df, acti, norm_acti, smoothed_acti, current_fixed_selection) model = t.TCA(function=method, rank=args.rank, init=args.init, verbose=args.verbose, roi_tensor=roi_tensor) factor = model.fit(torch.tensor(norm_acti_select)) np.save( os.path.join(path, 'factors{}_00.npy'.format(name)), factor) #Compute norms along columns for each factor matrix norms = [sci.linalg.norm(f, axis=0) for f in factor] # Multiply norms across all modes lam = sci.multiply.reduce(norms)**(1 / 3) # Update factors factor = [f * (lam / fn) for f, fn in zip(factor, norms)] factors.append(factor) return factors
name = ''.join([ '_' + k + '-' + str(selection[k]) for k in selection if not selection[k] == None ])[1:] path = os.path.join(paths.path2Output, animal, args.function, args.init, str(args.rank), name) path_fig = os.path.join(paths.path2Figures, animal, args.function, args.init, str(args.rank), name) for p in [path, path_fig]: try: os.makedirs(p) except: FileExistsError meta_df, roi_tensor, acti, norm_acti, smoothed_acti = data.load_processed_data_all( animal) meta_df, acti, norm_acti, smoothed_acti = data.select_data( meta_df, acti, norm_acti, smoothed_acti, selection) if args.similarity: sim = an.kruskal_align(fac1, fac2) if args.verbose: print(sim) if args.TSNE: an.TSNE_trials(acti, meta_df, name, path_fig, dataset=args.TSNE) if args.correlation: for b in ['CR', 'HIT', 'MISS', 'FA']: an.correlation_clustering(acti, meta_df, name, path_fig, be=b) ###¨Put predict