Loading EMRI_DET/nn/model_train_test.py +9 −9 Original line number Diff line number Diff line Loading @@ -11,13 +11,13 @@ def model_train_test(data, model, device, n_epochs, n_batches, loss_function, le name = model.name path = get_script_path() np.save(path+'/../models/'+name+'_xdata_mean_std.npy',np.array([xtrain.mean(axis=0), xtrain.std(axis=0)])) np.save(path+'/../models/'+name+'_ydata_mean_std.npy',np.array([ytrain.mean(), ytrain.std()])) np.save(path+'/../models/'+name+'/xdata_mean_std.npy',np.array([xtrain.mean(axis=0), xtrain.std(axis=0)])) np.save(path+'/../models/'+name+'/ydata_mean_std.npy',np.array([ytrain.mean(), ytrain.std()])) xtest = torch.from_numpy(norm_inputs(xtest, xtrain)).to(device).float() ytest = torch.from_numpy(norm(ytest, ytrain)).to(device).float() xtrain = torch.from_numpy(norm_inputs(xtrain, xtrain)).to(device).float() ytrain = torch.from_numpy(norm(ytrain, ytrain)).to(device).float() xtest = torch.from_numpy(norm_inputs(xtest, ref_dataframe=xtrain)).to(device).float() ytest = torch.from_numpy(norm(ytest, ref_dataframe=ytrain)).to(device).float() xtrain = torch.from_numpy(norm_inputs(xtrain, ref_dataframe=xtrain)).to(device).float() ytrain = torch.from_numpy(norm(ytrain, ref_dataframe=ytrain)).to(device).float() ytrainsize = len(ytrain) ytestsize = len(ytest) Loading Loading @@ -89,7 +89,7 @@ def model_train_test(data, model, device, n_epochs, n_batches, loss_function, le if verbose: print('\nTraining complete - saving.') torch.save(model.state_dict(),path+'/'+name+'_model.pth') torch.save(model.state_dict(),path+'/'+name+'/model.pth') epochs = np.arange(n_epochs) plt.semilogy(epochs, train_losses, label='Train') Loading @@ -98,11 +98,11 @@ def model_train_test(data, model, device, n_epochs, n_batches, loss_function, le plt.xlabel('Epochs') plt.ylabel('Loss') plt.title('Train and Test Loss Across Train Epochs') plt.savefig(path+'/../models/'+name+'_losses.png') plt.savefig(path+'/../models/'+name+'/losses.png') #plt.show() plt.close() out = (model,) if return_losses: out += (train_losses, test_losses,) return model return out EMRI_DET/validate.py +2 −2 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ def run_on_dataset(model, test_data, n_batches=1, device=None, y_transform_fn=No ymeanstd = np.load(get_script_path() + f'/../models/{model.name}_ydata_mean_std.npy') test_input = torch.Tensor(xdata) normed_input = norm_inputs(test_input, xmeanstd[0], xmeanstd[1]).float().to(device) normed_input = norm_inputs(test_input, ref_mean=xmeanstd[0], ref_std=xmeanstd[1]).float().to(device) if runtime: st = time.perf_counter() Loading @@ -56,7 +56,7 @@ def run_on_dataset(model, test_data, n_batches=1, device=None, y_transform_fn=No per_point = (et - st) / ydata.size output = np.concatenate(out) out_unnorm = unnorm(output, ymeanstd[0], ymeanstd[1]).flatten() out_unnorm = unnorm(output, ref_mean=ymeanstd[0], ref_std=ymeanstd[1]).flatten() if y_transform_fn is not None: out_unnorm = y_transform_fn(out_unnorm) Loading mock_data/2d_function/models/model1/function.pickle (48.4 KiB) File changed.No diff preview for this file type. View original file View changed file mock_data/2d_function/models/model1_xdata_mean_std.npy→mock_data/2d_function/models/model1/xdata_mean_std.npy (160 B) File changed and moved.No diff preview for this file type. View original file View changed file mock_data/2d_function/models/model1_ydata_mean_std.npy→mock_data/2d_function/models/model1/ydata_mean_std.npy (144 B) File changed and moved.No diff preview for this file type. View original file View changed file Loading
EMRI_DET/nn/model_train_test.py +9 −9 Original line number Diff line number Diff line Loading @@ -11,13 +11,13 @@ def model_train_test(data, model, device, n_epochs, n_batches, loss_function, le name = model.name path = get_script_path() np.save(path+'/../models/'+name+'_xdata_mean_std.npy',np.array([xtrain.mean(axis=0), xtrain.std(axis=0)])) np.save(path+'/../models/'+name+'_ydata_mean_std.npy',np.array([ytrain.mean(), ytrain.std()])) np.save(path+'/../models/'+name+'/xdata_mean_std.npy',np.array([xtrain.mean(axis=0), xtrain.std(axis=0)])) np.save(path+'/../models/'+name+'/ydata_mean_std.npy',np.array([ytrain.mean(), ytrain.std()])) xtest = torch.from_numpy(norm_inputs(xtest, xtrain)).to(device).float() ytest = torch.from_numpy(norm(ytest, ytrain)).to(device).float() xtrain = torch.from_numpy(norm_inputs(xtrain, xtrain)).to(device).float() ytrain = torch.from_numpy(norm(ytrain, ytrain)).to(device).float() xtest = torch.from_numpy(norm_inputs(xtest, ref_dataframe=xtrain)).to(device).float() ytest = torch.from_numpy(norm(ytest, ref_dataframe=ytrain)).to(device).float() xtrain = torch.from_numpy(norm_inputs(xtrain, ref_dataframe=xtrain)).to(device).float() ytrain = torch.from_numpy(norm(ytrain, ref_dataframe=ytrain)).to(device).float() ytrainsize = len(ytrain) ytestsize = len(ytest) Loading Loading @@ -89,7 +89,7 @@ def model_train_test(data, model, device, n_epochs, n_batches, loss_function, le if verbose: print('\nTraining complete - saving.') torch.save(model.state_dict(),path+'/'+name+'_model.pth') torch.save(model.state_dict(),path+'/'+name+'/model.pth') epochs = np.arange(n_epochs) plt.semilogy(epochs, train_losses, label='Train') Loading @@ -98,11 +98,11 @@ def model_train_test(data, model, device, n_epochs, n_batches, loss_function, le plt.xlabel('Epochs') plt.ylabel('Loss') plt.title('Train and Test Loss Across Train Epochs') plt.savefig(path+'/../models/'+name+'_losses.png') plt.savefig(path+'/../models/'+name+'/losses.png') #plt.show() plt.close() out = (model,) if return_losses: out += (train_losses, test_losses,) return model return out
EMRI_DET/validate.py +2 −2 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ def run_on_dataset(model, test_data, n_batches=1, device=None, y_transform_fn=No ymeanstd = np.load(get_script_path() + f'/../models/{model.name}_ydata_mean_std.npy') test_input = torch.Tensor(xdata) normed_input = norm_inputs(test_input, xmeanstd[0], xmeanstd[1]).float().to(device) normed_input = norm_inputs(test_input, ref_mean=xmeanstd[0], ref_std=xmeanstd[1]).float().to(device) if runtime: st = time.perf_counter() Loading @@ -56,7 +56,7 @@ def run_on_dataset(model, test_data, n_batches=1, device=None, y_transform_fn=No per_point = (et - st) / ydata.size output = np.concatenate(out) out_unnorm = unnorm(output, ymeanstd[0], ymeanstd[1]).flatten() out_unnorm = unnorm(output, ref_mean=ymeanstd[0], ref_std=ymeanstd[1]).flatten() if y_transform_fn is not None: out_unnorm = y_transform_fn(out_unnorm) Loading
mock_data/2d_function/models/model1/function.pickle (48.4 KiB) File changed.No diff preview for this file type. View original file View changed file
mock_data/2d_function/models/model1_xdata_mean_std.npy→mock_data/2d_function/models/model1/xdata_mean_std.npy (160 B) File changed and moved.No diff preview for this file type. View original file View changed file
mock_data/2d_function/models/model1_ydata_mean_std.npy→mock_data/2d_function/models/model1/ydata_mean_std.npy (144 B) File changed and moved.No diff preview for this file type. View original file View changed file