AuG_type = 'leaky_AuG' print('Leaky-AuGMEnT') else: AuG_type = 'AuGMEnT' print('Standard AuGMEnT') folder = 'DATA' Q_m = np.zeros((N_sim, N_train * (d + 1), A)) RPE_v = np.zeros((N_sim, N_train)) resp_v = np.zeros((N_sim, N_train * (d + 1))) for n in np.arange(N_sim): print('SIMULATION ', n + 1) model = AuGMEnT(S, R, M, A, alpha, beta, discount, eps, g, leak, rew, dic_stim, dic_resp) conv_ep[n], Q_m[n, :, :], RPE_v[n, :], _ = model.training_seq_pred_2( S_train, O_train, dic_stim, dic_resp, verb) print(np.mean(conv_ep)) str_conv = folder + '/' + AuG_type + '_' + task + '_ALL_CONV_2.txt' np.savetxt(str_conv, conv_ep) str_Q = folder + '/' + AuG_type + '_' + task + '_ALL_Q_2.txt' np.savetxt(str_Q, np.reshape(Q_m, (N_train * (d + 1) * N_sim, A))) str_RPE = folder + '/' + AuG_type + '_' + task + '_ALL_RPE_2.txt' np.savetxt(str_RPE, RPE_v)
stop = True criterion = 'strong' verb = 0 do_test = True perc_expl = np.zeros((N_sim)) perc_no_expl = np.zeros((N_sim)) perc_soft = np.zeros((N_sim)) for n in np.arange(N_sim): print('SIMULATION ', n + 1) model = AuGMEnT(S, R, M, A, alpha, beta, discount, eps, g, leak, rew, dic_stim, dic_resp, prop) E[n, :], conv_ep[n], REW[n, :] = model.training_12AX( N_trial, p_target, criterion, stop, verb, policy, stoc, t_weighted, e_weighted) print('\t CONVERGED AT TRIAL ', conv_ep[n]) if do_test: N_test = 1000 perc_expl[n], perc_no_expl[n], perc_soft[n] = model.test( N_test, p_target) print('Percentage of correct trials during test (exploration): ', perc_expl[n], '%') print('Percentage of correct trials during test (no exploration): ', perc_no_expl[n], '%')
print('Length = ', d + 2) dic_stim, dic_resp = get_dictionary(d) ## CONSTRUCTION OF THE AuGMEnT NETWORK S = d + 2 # dimension of the input = number of possible stimuli R = 3 # dimension of the regular units M = 4 # dimension of the memory units A = 2 # dimension of the activity units = number of possible responses for n in np.arange(N_vec[d_cont]): print('SIMULATION ', n + 1) model = AuGMEnT(S, R, M, A, alpha, beta, discount, eps, g, leak, rew, dic_stim, dic_resp) E[n, :], conv_ep[n] = model.training_seq_pred(N_train, d, stop, verb) #print('\t CONVERGED AT TRIAL ', conv_ep[n]) if N_test != 0: perc[n] = model.test_seq_pred(N_test, d, verb) print('Percentage of correct responses during test: ', perc, '%') conv_ep_reduced = np.delete(conv_ep, np.where(conv_ep == 0)) AVG_CONV[d_cont] = np.mean(conv_ep_reduced) SD_CONV[d_cont] = np.std(conv_ep_reduced) print('Average convergence time for trials with length ', d + 2, ':\t', AVG_CONV[d_cont], ' (', SD_CONV[d_cont], ')') d_cont += 1
N_sim = 1 E = np.zeros((N_sim, N_trial)) conv_ep = np.zeros((N_sim)) perc = np.zeros((N_sim)) do_weight_plots = True S_tot = np.shape(S_train)[0] Q_m = np.zeros((N_sim, S_tot, A)) RPE_v = np.zeros((N_sim, S_tot - 1)) for n in np.arange(N_sim): print('SIMULATION ', n + 1) model = AuGMEnT(S, R, M, A, alpha, beta, discount, eps, g, leak, rew, dic_stim, dic_resp, prop) conv_ep[n], Q_m[n, :], RPE_v[n, :] = model.training_12AX_2( S_train, O_train) print('\t CONVERGED AT TRIAL ', conv_ep[n]) cues_vec = [] values_vec = list(dic_stim.values()) for l in values_vec: cues_vec.append(l + '+') for l in values_vec: cues_vec.append(l + '-') mem_vec = [] for i in range(M): mem_vec.append('M' + str(i + 1))
N_sim = 10 E = np.zeros((N_sim, N_trial)) conv_ep = np.zeros((N_sim)) perc = np.zeros((N_sim)) stop = True criterion = 'strong' do_test = True for n in np.arange(N_sim): print('SIMULATION ', n + 1) model = AuGMEnT(S, R, M, A, alpha, beta, discount, eps, g, leak, rew, dic_stim, dic_resp, prop) E[n, :], conv_ep[n] = model.training_12AX(N_trial, p_target, criterion, stop) print('\t CONVERGED AT TRIAL ', conv_ep[n]) if do_test: N_test = 1000 perc[n] = model.test(N_test, p_target) print('Percentage of correct trials during test: ', perc, '%') folder = 'DATA' str_conv = folder + '/AuGMEnT_' + task + '_conv.txt' np.savetxt(str_conv, conv_ep) E_mean = np.mean(np.reshape(E, (-1, 50)), axis=1)
AuG_type = 'AuGMEnT' print('Standard AuGMEnT') # reward settings rew = 'RL' prop = 'std' N_sim = 1 E = np.zeros((N_sim,N_trial)) conv_ep = np.zeros((N_sim)) stop = True verb = 1 for n in np.arange(N_sim): print('SIMULATION ', n+1) model = AuGMEnT(S,R,M,A,alpha,beta,discount,eps,g,leak,rew,dic_stim,dic_resp,prop) E[n,:],conv_ep[n] = model.training_tXOR(N_trial,stop,verb) print('\t CONVERGED AT TRIAL ', conv_ep[n]) folder = 'DATA' str_conv = folder+'/'+AuG_type+'_'+task+'_conv.txt' np.savetxt(str_conv,conv_ep) E_mean = np.mean(np.reshape(E,(-1,50)),axis=1) str_err = folder+'/'+AuG_type+'_'+task+'_error.txt' np.savetxt(str_err,E_mean)
E_fix = np.zeros((N_sim, N_trial)) E_go = np.zeros((N_sim, N_trial)) conv_ep = np.zeros((N_sim)) perc_go = np.zeros((N_sim)) perc_fix = np.zeros((N_sim)) stop = True S_tr, O_tr, _, _, dic_stim, dic_resp = data_construction(N=1, perc_training=1) for n in np.arange(N_sim): print('SIMULATION ', n + 1) S_tr, O_tr, _, _, _, _ = data_construction(N=N_trial, perc_training=1) model = AuGMEnT(S, R, M, A, alpha, beta, discount, eps, g, leak, rew, dic_stim, dic_resp, prop) _, E_go[n, :], conv_ep[n] = model.training_saccade(N_trial, S_tr, O_tr, reset_cond, verb, shape_fac, stop) print('\t CONVERGED AT TRIAL ', conv_ep[n]) if do_test == True: S_test, O_test, _, _, _, _ = data_construction(N=100, perc_training=1) perc_fix[n], perc_go[n] = model.test_saccade(S_test, O_test, reset_cond) print('Percentage of correct FIX responses during test: ', perc_fix, '%') print('Percentage of correct GO responses during test: ', perc_go, '%')