def run_preliminary(args, device): """ Function executes preliminary experiments :param args: command line arguments :param device: device to be used """ subs_train = [ 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 15000, 20000, 30000, 40000, 50000, 60000 ] subs_test = [1000, 1500, 2000, 3000, 4000, 5000, 7000, 8000, 9000, 10000] epochs = [2, 5, 10, 15, 17, 20, 22, 25, 27, 30] train_loader, test_loader = nnvis.data_load() model = prep.get_net(device, train_loader, test_loader, args.epochs) model.load_state_dict(torch.load(nnvis.init_state)) nnvis.pre_train_subset(model, device, subs_train, args.epochs, test_loader) nnvis.pre_test_subset(model, device, subs_test) nnvis.pre_epochs(model, device, epochs) nnvis.plot_impact(subs_train, nnvis.train_subs_loss, nnvis.train_subs_acc, xlabel="Size of training dataset") nnvis.plot_impact(epochs, nnvis.epochs_loss, nnvis.epochs_acc, annotate=False, xlabel="Number of epochs") nnvis.plot_box(subs_test, show=False, xlabel="Size of test subset")
def run_rand_dirs(args): use_cuda = not args.no_cuda and torch.cuda.is_available() device = torch.device("cuda" if use_cuda else "cpu") train_loader, test_loader = nnvis.data_load() model = prep.get_net(device, train_loader, test_loader, args.epochs) dirs = nnvis.get_directions(model, device) nnvis.calc_loss(model, test_loader, dirs, device) nnvis.surface3d_rand_dirs() nnvis.surface_heatmap_rand_dirs()
def run_pca_surface(args, device): """ Runs the visualization of loss surface around trained model. :param args: experiment configuration :param device: device to be used """ train_loader, test_loader = nnvis.data_load() model = prep.get_net(device, train_loader, test_loader, args.epochs) examine = nnvis.Examinator2D(model, device) data = examine.get_loss_grid(test_loader) nnvis.contour_path(data["path_2d"], data["loss_grid"], data["coords"], data["pcvariances"]) nnvis.surface_contour(data["loss_grid"], data["coords"])
def run_layer(args, device): """ Function setups and executes experiment of interpolation of parameters :param args: experiment configuration :param device: device to be used """ alpha = np.linspace(0, 1, args.alpha_steps) train_loader, test_loader = nnvis.data_load() model = prep.get_net(device, train_loader, test_loader, args.epochs) interpolate = nnvis.Linear(model, device, alpha, nnvis.final_state, nnvis.init_state) interpolate.layers_linear(test_loader, args.layer)
def run_complete(args, device): """ Function runs a linear path experiment over all parameters of the model :param args: CLI arguments with experiment configuration :param device: device to be used """ alpha = np.linspace(0, 1, args.alpha_steps) train_loader, test_loader = nnvis.data_load() model = prep.get_net(device, train_loader, test_loader, args.epochs) interpolate = nnvis.Linear(model, device, alpha, nnvis.final_state, nnvis.init_state) interpolate.interpolate_all_linear(test_loader)
def run_individual(args, device): """ Runs quadratic interpolation examination on the level of parameters. :param args: experiment configuration :param device: device to be used """ alpha = np.linspace(args.alpha_start, args.alpha_end, args.alpha_steps) train_loader, test_loader = nnvis.data_load() model = prep.get_net(device, train_loader, test_loader, args.epochs) interpolate = nnvis.Quadratic(model, device, alpha, nnvis.final_state, nnvis.init_state) interpolate.individual_param_quadratic(test_loader, args.layer, args.idxs)
def run_individual(args, device): """ Function executes experiment with individual parameter :param args: command line arguments :param device: device to be used """ alpha = np.linspace(args.alpha_start, args.alpha_end, args.alpha_steps) # setup interpolation coefficient train_loader, test_loader = nnvis.data_load() # setup data loaders model = prep.get_net(device, train_loader, test_loader, args.epochs) # setup model interpolate = nnvis.Linear(model, device, alpha, nnvis.final_state, nnvis.init_state) # get interpolator instance interpolate.individual_param_linear(test_loader, args.layer, args.idxs) # execute the experiment
def run_complete(args, device): """ Runs quadratic interpolation examination over all parameters of the model. :param args: experiment configuration :param device: device to be used """ alpha = np.linspace(0, 1, args.alpha_steps) train_loader, test_loader = nnvis.data_load() model = prep.get_net(device, train_loader, test_loader, args.epochs) interpolate = nnvis.Quadratic(model, device, alpha, nnvis.final_state, nnvis.init_state) interpolate_l = nnvis.Linear(model, device, alpha, nnvis.final_state, nnvis.init_state) interpolate_l.interpolate_all_linear(test_loader) interpolate.interpolate_all_quadratic(test_loader) nnvis.plot_lin_quad_real(alpha)