anneal['anneal_prior'] = False output_path = create_output_path(basename = job_name) model = BSC_ET(D, H, Hprime, gamma, to_learn=['W','sigma','pi','mu']) data = {'y':patches} out_fname = output_path + "/data.h5" #setting up logging/output print_list = ('T', 'Q', 'pi', 'sigma', 'N', 'MAE', 'L') dlog.set_handler(print_list, TextPrinter) h5store_list = ('W', 'pi', 'sigma', 'y', 'MAE', 'N','L','Q','mu') dlog.set_handler(h5store_list, StoreToH5, output_path +'/result.h5') ###### Initialize model ####### # Initialize (Random) model parameters model_params = model.standard_init(data) #model_params['mu'] = np.mean(data['y'],axis=0) # Create and start EM annealing em = EM(model=model, anneal=anneal) em.data = data em.lparams = model_params em.run()
if not channel_splitted: # Take care of not channel splitted case size = data_file.root.patches.shape[1] / 2 my_y = my_y[:, 0:size, :] - my_y[:, size:, :] # We flatten everything here in the D dimension my_y = my_y.reshape(my_N, -1) my_y_rc = my_y_rc.reshape(my_N, -1) _, D = my_y.shape #========================= Configure DataLogger =============================== print_list = ('T', 'pi', 'sigma', 'N', 'N_use') store_list = ('*') dlog.set_handler(print_list, StoreToTxt, output_path + '/terminal.txt') dlog.set_handler(store_list, StoreToH5, result_path) #========================= Enable tracing? ===================================== if enable_tracing: dlog.progress("Tracing enabled") tracing.set_tracefile(output_path + "/trace-%04d.txt") #=========== Create annealing schedule if not done in param file =============== if 'anneal' not in dir(): anneal = LinearAnnealing(anneal_steps) anneal['T'] = [(anneal_start, temp_start), (anneal_end, temp_end)] anneal['Ncut_factor'] = [(cut_start, 0.), (cut_end, 1.)] anneal['anneal_prior'] = anneal_prior anneal['W_noise'] = [(noise_decrease, W_noise), (noise_end, 0.)] anneal['pi_noise'] = [(noise_decrease, pi_noise), (noise_end, 0.)]
# ============================================================================ # Main if __name__ == "__main__": comm = MPI.COMM_WORLD pprint("=" * 78) pprint(" Running %d parallel processes" % comm.size) pprint("=" * 78) # Configure DataLogger # use('GTKAgg') dlog.start_gui(GUI) # dlog.set_handler('freeEnergy', YTPlotter) dlog.set_handler(("T", "Qmean", "pi", "sigma", "Wmin", "Wmean", "Wmax"), TextPrinter) dlog.set_handler("W", RFViewer, rf_shape=(D2, D2), symmetric=0, global_maximum=0) # dlog.set_handler('y', RFViewer, rf_shape=(D2, D2)) # Choose annealing schedule anneal = LinearAnnealing(Tsteps) anneal["T"] = [(10, Tstart), (-10, Tend)] anneal["Ncut_factor"] = [(2 / 3, 0.0), (-10, 1.0)] anneal["W_noise"] = [(-10, 0.01), (-1, 0.0)] # Prepare ground-truth GFs (bars) W_gt = np.zeros((H, D2, D2)) for i in xrange(D2): W_gt[i, i, :] = 10.0 W_gt[D2 + i, :, i] = 10.0 W_gt = W_gt.reshape((H, D))
#============================================================================ # Main if __name__ == "__main__": comm = MPI.COMM_WORLD pprint("="*78) pprint(" Running %d parallel processes" % comm.size) pprint("="*78) #Configure DataLogger #use('GTKAgg') dlog.start_gui(GUI) #dlog.set_handler('freeEnergy', YTPlotter) dlog.set_handler(('T', 'Qmean', 'pi', 'sigma', 'Wmin', 'Wmean', 'Wmax'), TextPrinter) dlog.set_handler('W', RFViewer, rf_shape=(D2, D2), symmetric=1, global_maximum=1) dlog.set_handler('y', RFViewer, rf_shape=(D2, D2)) dlog.set_handler(['pi'], YTPlotter) dlog.set_handler(['sigma'], YTPlotter) # Choose annealing schedule anneal = LinearAnnealing(Tsteps) anneal['T'] = [(10, Tstart) , (-20, Tend)] anneal['Ncut_factor'] = [(0, 0.), (2./3, 1.2)] anneal['W_noise'] = [(-10, 0.01), (-1, 0.01)] # Prepare ground-truth GFs (bars) W_gt = np.zeros( (H, D2, D2) ) for i in xrange(D2): W_gt[ i, i, :] = -10.
pprint("Pi learned, but not noisified.") if ("sigma" in to_learn) and (sigma_noise_intensity == 0): pprint("Sigma learned, but not noisified.") if (not gamma <= Hprime) or (not Hprime <= H): pprint("gamma < Hprime < H has to be fullfilled. Aborting.") run_algorithm = False pprint("============================= ........ =============================\n") # if not run_algorithm: # exit(1) # ------------------------------ Controls end --------------------------------- # Configure DataLogger dlog.start_gui(GUI) print_list = ("Done", "T", "Q", "pi", "sigma", "N", "MAE") dlog.set_handler(print_list, TextPrinter) # dlog.set_handler(print_list, StoreToTxt, output_path +'terminal.txt') # dlog.set_handler('Q', YTPlotter) dlog.set_handler("W", RFViewer, rf_shape=(D2, D2)) dlog.set_handler(("W", "pi", "sigma", "mu", "y", "MAE", "N"), StoreToH5, output_path + "result.h5") # dlog.set_handler(('W', 'pi', 'sigma', 'mu', 'y', 'MAE', 'N'), StoreToH5, output_path +'test_set.h5') dlog.set_handler(["pi"], YTPlotter) dlog.set_handler(["sigma"], YTPlotter) dlog.set_handler("y", RFViewer, rf_shape=(D2, D2)) # Prepare ground-truth GFs (bars) W_gt = np.zeros((H, D2, D2)) for i in xrange(D2): W_gt[i, i, :] = bar_value W_gt[D2 + i, :, i] = bar_value if neg_bars > 0.0:
sys.path.insert(0, "..") from time import sleep import numpy as np from pulp.utils.parallel import pprint from pulp.utils.datalog import dlog, StoreToH5, TextPrinter from pulp.visualize.gui import GUI, RFViewer, YTPlotter # Parameters rf_shape = (26, 26) H = 16 # Configure Data-Logger dlog.start_gui(GUI) dlog.set_handler('W', RFViewer, rf_shape=rf_shape) dlog.set_handler('S', YTPlotter) dlog.set_handler('C', YTPlotter) dlog.set_handler(('T', 'S', 'C'), TextPrinter) # And GO! D = rf_shape[0] * rf_shape[1] Wshape = (H, D) i = 0 for T in np.linspace(0., 20, 50): i = i + 1 pprint("%i th iteration..." % i) W = np.random.normal(size=Wshape) dlog.append_all({
my_y = my_y[:, 0:size, :] - my_y[:, size:, :] # We flatten everything here in the D dimension my_y = my_y.reshape(my_N, -1) my_y_rc = my_y_rc.reshape(my_N, -1) _, D = my_y.shape #========================= Configure DataLogger =============================== print_list = ('T', 'pi', 'sigma', 'N', 'N_use') store_list = ('*') dlog.set_handler(print_list, StoreToTxt, output_path+'/terminal.txt') dlog.set_handler(store_list, StoreToH5, result_path) #========================= Enable tracing? ===================================== if enable_tracing: dlog.progress("Tracing enabled") tracing.set_tracefile(output_path+"/trace-%04d.txt") #=========== Create annealing schedule if not done in param file =============== if 'anneal' not in dir(): anneal = LinearAnnealing(anneal_steps) anneal['T'] = [(anneal_start, temp_start), (anneal_end, temp_end)] anneal['Ncut_factor'] = [(cut_start, 0.),(cut_end, 1.)] anneal['anneal_prior'] = anneal_prior anneal['W_noise'] = [(noise_decrease, W_noise), (noise_end, 0.)] anneal['pi_noise'] = [(noise_decrease, pi_noise), (noise_end, 0.)]
sys.path.insert(0, "..") from time import sleep import numpy as np from pulp.utils.parallel import pprint from pulp.utils.datalog import dlog, StoreToH5, TextPrinter from pulp.visualize.gui import GUI, RFViewer, YTPlotter # Parameters rf_shape = (26, 26) H = 16 # Configure Data-Logger dlog.start_gui(GUI) dlog.set_handler('W', RFViewer, rf_shape=rf_shape) dlog.set_handler('S', YTPlotter) dlog.set_handler('C', YTPlotter) dlog.set_handler(('T', 'S', 'C'), TextPrinter) # And GO! D = rf_shape[0] * rf_shape[1] Wshape = (H,D) i = 0 for T in np.linspace(0., 20, 50): i = i + 1 pprint( "%i th iteration..." % i) W = np.random.normal(size=Wshape) dlog.append_all( {
pprint("Sigma learned, but not noisified.") if (not gamma <= Hprime) or (not Hprime <= H): pprint("gamma < Hprime < H has to be fullfilled. Aborting.") run_algorithm = False pprint( "============================= ........ =============================\n" ) #if not run_algorithm: # exit(1) # ------------------------------ Controls end --------------------------------- # Configure DataLogger dlog.start_gui(GUI) print_list = ('Done', 'T', 'Q', 'pi', 'sigma', 'N', 'MAE') dlog.set_handler(print_list, TextPrinter) #dlog.set_handler(print_list, StoreToTxt, output_path +'terminal.txt') #dlog.set_handler('Q', YTPlotter) dlog.set_handler('W', RFViewer, rf_shape=(D2, D2)) dlog.set_handler(('W', 'pi', 'sigma', 'mu', 'y', 'MAE', 'N'), StoreToH5, output_path + 'result.h5') #dlog.set_handler(('W', 'pi', 'sigma', 'mu', 'y', 'MAE', 'N'), StoreToH5, output_path +'test_set.h5') dlog.set_handler(['pi'], YTPlotter) dlog.set_handler(['sigma'], YTPlotter) dlog.set_handler('y', RFViewer, rf_shape=(D2, D2)) # Prepare ground-truth GFs (bars) W_gt = np.zeros((H, D2, D2)) for i in xrange(D2): W_gt[i, i, :] = bar_value W_gt[D2 + i, :, i] = bar_value
#============================================================================ # Main if __name__ == "__main__": comm = MPI.COMM_WORLD pprint("=" * 78) pprint(" Running %d parallel processes" % comm.size) pprint("=" * 78) #Configure DataLogger #use('GTKAgg') dlog.start_gui(GUI) #dlog.set_handler('freeEnergy', YTPlotter) dlog.set_handler(('T', 'Qmean', 'pi', 'sigma', 'Wmin', 'Wmean', 'Wmax'), TextPrinter) dlog.set_handler('W', RFViewer, rf_shape=(D2, D2), symmetric=1, global_maximum=1) dlog.set_handler('y', RFViewer, rf_shape=(D2, D2)) dlog.set_handler(['pi'], YTPlotter) dlog.set_handler(['sigma'], YTPlotter) # Choose annealing schedule anneal = LinearAnnealing(Tsteps) anneal['T'] = [(10, Tstart), (-20, Tend)] anneal['Ncut_factor'] = [(0, 0.), (2. / 3, 1.2)] anneal['W_noise'] = [(-10, 0.01), (-1, 0.01)]