def vary_weight_loss(i): root_dir = '/Users/peterwang/Desktop/PYTHON/Neural_head_direction/experiments/vary_weight_loss' stationary_opts = config.stationary_model_config() stationary_opts.save_path = os.path.join(root_dir, 'files', str(i).zfill(2), 'stationary') stationary_opts.rnn_size = 60 stationary_opts.load_checkpoint = False stationary_opts.epoch = 700 stationary_opts.time_steps = 25 stationary_opts.time_loss_start = 5 stationary_opts.time_loss_end = 25 stationary_opts.activity_alpha = .1 moving_opts = config.non_stationary_model_config() moving_opts.save_path = os.path.join(root_dir, 'files', str(i).zfill(2), 'moving') moving_opts.load_checkpoint = False moving_opts.dir_weights = os.path.join(stationary_opts.save_path, 'weight.pkl') moving_opts.initialize_W_ab_diagonal = False moving_opts.initialize_W_ba_diagonal = False moving_opts.epoch = 700 moving_opts.velocity_use = 2 moving_opts.velocity_max = 2 moving_opts.weight_alpha = 1 moving_opts.activity_alpha = .1 hp_ranges = OrderedDict() hp_ranges['weight_alpha'] = [0, 1] argWhich = 0 return stationary_opts, moving_opts, hp_ranges, argWhich
def stationary_curriculum(): st_model_opts = config.stationary_model_config() st_model_opts.weight_alpha = .5 st_model_opts.activity_alpha = .1 st_model_opts.losses = 'full' st_model_opts.activation_fn = 'relu' st_model_opts.mask = True
def vary_batch(i): opts = config.stationary_model_config() opts.save_path = '/Users/peterwang/Desktop/PYTHON/Neural_head_direction/experiments' \ '/vary_batch/files/' + str(i).zfill(2) opts.rnn_size = 60 opts.load_checkpoint = False opts.epoch = 300 opts.time_steps = 25 opts.time_loss_start = 5 opts.time_loss_end = 25 hp_ranges = OrderedDict() hp_ranges['batch_size'] = [5, 10, 20, 25, 40, 50, 100] return opts, hp_ranges
'[*] Epoch %d total_loss=%.2f xe_loss=%.2f a_loss=%.2f, w_loss=%.2f' % (ep, cur_loss, xe_loss, activity_loss, weight_loss)) #save latest model.save() utils.save_parameters(opts, os.path.join(save_path, opts.parameter_name)) model.save_weights() save_activity(model, next_element[0], next_element[1]) with open(os.path.join(save_path, opts.log_name + '.pkl'), 'wb') as f: pkl.dump(logger, f) if __name__ == '__main__': st_model_opts = config.stationary_model_config() opts = st_model_opts opts.save_path = './test/stationary' opts.epoch = 300 opts.load_checkpoint = True train(opts) non_st_model_opts = config.non_stationary_model_config() opts = non_st_model_opts opts.save_path = './test/non_stationary' opts.load_checkpoint = True opts.load_weights = False opts.dir_weights = './test/stationary/weight.pkl' opts.epoch = 500 opts.velocity_use = 2 opts.velocity_max = 2
def curriculum(params): # quick settings def fast_hd_trig(opts): opts.input_mode = 'trig' opts.output_mode = 'trig' opts.grid_input = False opts.linear_track = False return opts def fast_hd_bump(opts): opts.input_mode = 'bump' opts.output_mode = 'bump' opts.grid_input = False opts.linear_track = False return opts def fast_grid(opts): opts.input_mode = 'bump' opts.output_mode = 'bump' opts.grid_input = True opts.linear_track = True return opts rnn_size, state_size = params parser = arg_parser() opts = parser.parse_args() opts.rnn_size = rnn_size linear_track = False if linear_track: track = 'linear' else: track = 'circular' loss = 'error' # ['error', 'activity', 'weights', 'full'] # loss = 'activity' # ['error', 'activity', 'weights', 'full'] # loss = 'full' # ['error', 'activity', 'weights', 'full'] fn = 'relu' # [relu, tanh] st_model_opts = config.stationary_model_config() # st_model_opts.output_mode = output_mode st_model_opts.weight_alpha = .5 st_model_opts.activity_alpha = .1 st_model_opts.rnn_size = rnn_size st_model_opts.state_size = state_size st_model_opts.linear_track = linear_track st_model_opts.losses = loss st_model_opts.activation_fn = fn st_model_opts.mask = True velocity_min = 1 velocity_max = 3 nonst_model_opts = config.non_stationary_model_config() # nonst_model_opts.output_mode = output_mode # nonst_model_opts.input_mode = input_mode nonst_model_opts.linear_track = linear_track nonst_model_opts.velocity_max = 3 nonst_model_opts.weight_alpha = .5 nonst_model_opts.activity_alpha = .1 nonst_model_opts.rnn_size = rnn_size nonst_model_opts.state_size = state_size nonst_model_opts.losses = loss nonst_model_opts.activation_fn = fn nonst_model_opts.mask = True nonst_model_opts.boundary_velocity = False nonst_model_opts.correlated_path = False # get all present dirs modeldir = os.path.join(os.getcwd(), 'training') exp = re.compile('model([0-9]+)') used_ix = [] with os.scandir(modeldir) as models: for m in models: rg = exp.match(m.name) if rg: used_ix.append(int(rg.group(1))) max_ix = np.amax(used_ix) full_ix = np.arange(max_ix + 2) # include the next index above the highest free_ix = [a for a in full_ix if a not in used_ix] new_ix = np.amin(free_ix) nonst_model_opts.save_path = os.path.join(os.getcwd(), 'training', f'model{str(new_ix).zfill(3)}') nonst_model_opts.dir_weights = os.path.join( nonst_model_opts.save_path, nonst_model_opts.model_name + '.pkl') # first = copy.deepcopy(st_model_opts) # # first.epoch = int(201) # first.epoch = int(1) # first.load_checkpoint = False # # first_more = copy.deepcopy(st_model_opts) # # first_more.epoch = int(101) # first_more.epoch = int(201) # first_more.learning_rate = 1e-4 # first_more.load_checkpoint = True second = copy.deepcopy(nonst_model_opts) second.epoch = int(300) # second.epoch = int(1) second.load_checkpoint = False second.load_weights = False second.time_steps = 50 second.time_loss_start = 5 second.time_loss_end = second.time_steps second.velocity_step = 1 second.velocity_min = velocity_min second.velocity_max = velocity_max second.dir_weights = os.path.join(st_model_opts.save_path, st_model_opts.weight_name + '.pkl') second.learning_rate = .001 # second.debug_weights = True # n_env = 10 # second.subtrack = False # second.rescale_env = True # second.n_env = n_env # second.bump_in_network = False # second.grid_input = False second.dropout = False second.dropout_rate = .4 second.noise = False second.noise_intensity = .1 second.noise_density = .5 second.nonneg_input = True second.EI_in = False second.EI_h = False second.EI_out = False second.prop_ex = .8 #### ASSIGN TRAINING PARADIGM #### second = fast_hd_trig(second) # second = fast_hd_bump(second) # second = fast_grid(second) # c = [first] # c = [first_more] # c = [first, first_more] c = [second] # c = [second_more] # c = [second, second_more] # c = [second_last] # c = [moving_static, second_more] return c