train_loader = torch.utils.data.DataLoader(dataset, batch_size=args.batches, shuffle=True, drop_last=True) test_loader = torch.utils.data.DataLoader(datasets.MNIST( './DATA/MNIST_data', train=False, transform=transforms.Compose([transforms.ToTensor()])), batch_size=args.batches) ############################# elif args.model == 'ising': # For the Ising Model data set model_size = args.ising_size * args.ising_size image_size = args.ising_size train_loader = torch.utils.data.DataLoader(rbm_pytorch.CSV_Ising_dataset( args.training_data, size=model_size), shuffle=True, batch_size=args.batches, drop_last=True) # Read the model, example rbm = rbm_pytorch.RBM(k=args.kCD, n_vis=model_size, n_hid=hidden_layers) # load the model, if the file is present if args.ckpoint is not None: print("Loading saved network state from file", args.ckpoint) rbm.load_state_dict(torch.load(args.ckpoint)) ############################## # Training parameters
image_size = 28 if parameters['initialize_with_training']: print("Loading MNIST training set...") train_loader = datasets.MNIST('./DATA/MNIST_data', train=True, download=True, transform=transforms.Compose( [transforms.ToTensor()])) ############################# elif parameters['model'] == 'ising': # For the Ising Model data set image_size = parameters['ising']['size'] model_size = image_size * image_size if parameters['initialize_with_training']: print("Loading Ising training set...") train_loader = rbm_pytorch.CSV_Ising_dataset( parameters['ising']['train_data'], size=model_size, skiprows=1) # Compute magnetization and susceptibility train_mag = [] for i in xrange(len(train_loader)): data = train_loader[i][0].view(-1, model_size) train_mag.append( ising_magnetization(get_ising_variables(data.numpy()))) tr_magarray = np.asarray(train_mag) ising_averages(tr_magarray, model_size, "training_set") # Read the model, example rbm = rbm_pytorch.RBM(n_vis=model_size, n_hid=hidden_layers) # load the model, if the file is present try:
print(args) pprint(parameters) model_size = parameters['ising']['size'] * parameters['ising']['size'] rbm = rbm_pytorch.RBM(n_vis=model_size, n_hid=parameters['hidden_layers']) if parameters['do_convergence_analysis']: ################################################################### #### Convergence analysis: observables/loglikelihood vs epochs #### ################################################################### print("Convergence analysis L=" + str(parameters['ising']['size'])) print("Loading Ising training set...") train_loader = torch.utils.data.DataLoader(rbm_pytorch.CSV_Ising_dataset(parameters['ising']['train_data'], size=model_size), shuffle=True, batch_size=parameters['batch_size'], drop_last=True) analysis_file = open(parameters['output_dir'] + "analysis_" + str(parameters['temperature']) + "_L" + str(parameters['ising']['size']) + "/data.dat", 'w') analysis_file.write("trained rbms from " + str(parameters['checkpoint'])+ "\n") pbar = tqdm(range(parameters['start_epoch'], parameters['final_epoch'])) n = 0 print ("Range of epochs: ", parameters['start_epoch'], " to ", parameters['final_epoch']) npoints = int((parameters['final_epoch']-parameters['start_epoch'])/parameters['step']) print("npoints",npoints) epochs = np.zeros(npoints) mag = np.zeros(npoints)
transform=transforms.Compose([ transforms.ToTensor() ])) train_loader = torch.utils.data.DataLoader(dataset, batch_size=args.batches, shuffle=True, drop_last=True) test_loader = torch.utils.data.DataLoader( datasets.MNIST('./DATA/MNIST_data', train=False, transform=transforms.Compose([ transforms.ToTensor() ])), batch_size=args.batches) ############################# elif args.model == 'ising': # For the Ising Model data set model_size = args.ising_size * args.ising_size image_size = args.ising_size train_loader = torch.utils.data.DataLoader(rbm_pytorch.CSV_Ising_dataset(args.training_data, size=args.ising_size), shuffle=True, batch_size=args.batches, drop_last=True) # Read the model, example rbm = rbm_pytorch.RBM(k=args.kCD, n_vis=model_size, n_hid=hidden_layers) # load the model, if the file is present if args.ckpoint is not None: print("Loading saved network state from file", args.ckpoint) rbm.load_state_dict(torch.load(args.ckpoint)) ############################## # Training parameters learning_rate = 0.01 # Mnist 0.3 mom = 0.0 # momentum
shuffle=True, drop_last=True) test_loader = torch.utils.data.DataLoader( datasets.MNIST('./DATA/MNIST_data', train=False, transform=transforms.Compose([transforms.ToTensor()])), batch_size=parameters['batch_size']) ############################# elif parameters['model'] == 'ising': # For the Ising Model data set model_size = parameters[ 'ising_size'] # note that you have to give the full dimension LxL if you are in 2 dim image_size = parameters['ising_size'] train_loader = torch.utils.data.DataLoader( rbm_pytorch.CSV_Ising_dataset(parameters['training_data'], size=model_size), shuffle=True, batch_size=parameters['batch_size'], drop_last=True) # Read the model, example rbm = rbm_pytorch.RBM(k=parameters['kCD'], n_vis=model_size, n_hid=hidden_layers) # load the model, if the file is present if parameters['ckpoint'] is not None: print("Loading saved network state from file", parameters['ckpoint']) rbm.load_state_dict(torch.load(parameters['ckpoint'])) ##############################
model_size = MNIST_SIZE image_size = 28 if parameters['initialize_with_training']: print("Loading MNIST training set...") train_loader = datasets.MNIST('./DATA/MNIST_data', train=True, download=True, transform=transforms.Compose([ transforms.ToTensor() ])) ############################# elif parameters['model'] == 'ising': # For the Ising Model data set image_size = parameters['ising']['size'] model_size = image_size * image_size if parameters['initialize_with_training']: print("Loading Ising training set...") train_loader = rbm_pytorch.CSV_Ising_dataset( parameters['ising']['train_data'], size=image_size) # Read the model, example rbm = rbm_pytorch.RBM(n_vis=model_size, n_hid=hidden_layers) # load the model, if the file is present try: print("Loading saved RBM network state from file", parameters['checkpoint']) rbm.load_state_dict(torch.load(parameters['checkpoint'])) except IOError as e: print("I/O error({0}): {1}".format(e.errno, e.strerror)) except: print("Unexpected error:", sys.exc_info()[0]) raise