Example #1
0
                assert len(choice[trial_start:trial_end]) == len(ses_data)
                assert np.array_equal(choice[trial_start:trial_end],ses_data['choices'].to_numpy(),equal_nan=True)==True

                ses_data.loc[ses_data['choices']]
                if trial_end<0:
                    filling_length_end = abs(trial_end)
                else:
                    filling_length_end = len(choice)-trial_end
                filling_length_start = trial_start
                end_filler=np.empty(filling_length_end)
                end_filler[:] = np.nan
                start_filler=np.empty(filling_length_start)
                start_filler[:] = np.nan
                assert (np.isnan(np.nanmean(ses_data['Qwater'].to_numpy()))==False) & (np.isnan(np.nanmean(ses_data['Qlaser'].to_numpy()))==False) 
                assert (np.isnan(np.nanmean(ses_data['QRstay'].to_numpy()))==False) & (np.isnan(np.nanmean(ses_data['QLstay'].to_numpy()))==False) 
                np.save(alf+'/'+prefix+'_choice_prediction.npy', np.concatenate([start_filler,ses_data['predicted_choice'].to_numpy(),end_filler]))
                np.save(alf+'/'+prefix+'_water.npy', np.concatenate([start_filler,ses_data['Qwater'].to_numpy(),end_filler]))
                np.save(alf+'/'+prefix+'_laser.npy', np.concatenate([start_filler,ses_data['Qlaser'].to_numpy(),end_filler]))
                np.save(alf+'/'+prefix+'_QLstay.npy', np.concatenate([start_filler,ses_data['QLstay'].to_numpy(),end_filler]))
                np.save(alf+'/'+prefix+'_QRstay.npy', np.concatenate([start_filler,ses_data['QRstay'].to_numpy(),end_filler]))


ROOT_FOLDER = '/Volumes/witten/Alex/Data/Subjects'
psy=mc.load_data(trial_start=0,trial_end=-150)
standata = mc.make_stan_data(psy)
reinforce_params = pd.read_csv('/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/REINFORCE_laserdecaywin_mixedstay/output/summary.csv')
reinforce_data = pd.DataFrame()
reinforce_data = mc.reinforce_model_alphalaserdecay_mixed_perseveration(standata,saved_params=reinforce_params)
assert len(psy) == len(reinforce_data)
prefix='REINFORCE_mixedstay_alphalaserdecay'
save_q_values(ROOT_FOLDER,psy,reinforce_data,prefix, trial_start=0,trial_end=-150)
                    ses_bias_data['first_opto_block']=['L']
                else:
                    ses_bias_data['first_opto_block']=['R']
                bias_data = pd.concat([bias_data,ses_bias_data])
    sns.barplot(data=bias_data,x='first_opto_block', y='bias', ci=68,palette='gray')
    sns.swarmplot(data=bias_data,x='first_opto_block', y='bias', color='k')
    plt.ylabel('Bias Coefficient')
    plt.show()
    sns.barplot(data=bias_data,x='first_opto_block', y='right_choices', ci=68, palette='gray')
    sns.swarmplot(data=bias_data,x='first_opto_block', y='right_choices', color='k')
    plt.ylabel('Fraction of right choices')
    plt.show()
    return bias_data


psy=load_data()
standata = make_stan_data(psy)
model_standard_75 = pd.read_csv('/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/investigation_laserdecay/standard_75/output/summary.csv')
model_standard_75150 = pd.read_csv('/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/investigation_laserdecay/standard_75150/output/summary.csv')
model_standard_rest = pd.read_csv('/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/investigation_laserdecay/standard_rest/output/summary.csv')
model_reinforce_75 = pd.read_csv('/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/investigation_laserdecay/reinforce_75/output/summary.csv')
model_reinforce_75150 = pd.read_csv('/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/investigation_laserdecay/reinforce_75150/output/summary.csv')
model_reinforce_rest = pd.read_csv('/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/investigation_laserdecay/reinforce_rest/output/summary.csv')

compare_params_3(model_standard_75,model_standard_75150,model_standard_rest,standata)

compare_params_2(model_reinforce_75,model_reinforce_rest,standata)

saved_params1=model_standard_75
saved_params2=model_standard_75150
saved_params3=model_standard_rest
Example #3
0
                ses_data.loc[ses_data['choices']]
                filler=np.empty(150)
                filler[:] = np.nan
                assert (np.isnan(np.nanmean(ses_data['QL'].to_numpy()))==False) & (np.isnan(np.nanmean(ses_data['QR'].to_numpy()))==False) 
                assert (np.isnan(np.nanmean(ses_data['Qwater'].to_numpy()))==False) & (np.isnan(np.nanmean(ses_data['Qlaser'].to_numpy()))==False) 
                assert (np.isnan(np.nanmean(ses_data['QRstay'].to_numpy()))==False) & (np.isnan(np.nanmean(ses_data['QLstay'].to_numpy()))==False) 
                assert (np.isnan(np.nanmean(ses_data['QRreward'].to_numpy()))==False) & (np.isnan(np.nanmean(ses_data['QLreward'].to_numpy()))==False) 
                assert (np.isnan(np.nanmean(ses_data['QRlaser'].to_numpy()))==False) & (np.isnan(np.nanmean(ses_data['QLlaser'].to_numpy()))==False) 
                np.save(alf+'/'+prefix+'_choice_prediction.npy', np.concatenate([ses_data['predicted_choice'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_water.npy', np.concatenate([ses_data['Qwater'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_laser.npy', np.concatenate([ses_data['Qlaser'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_QLstay.npy', np.concatenate([ses_data['QLstay'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_QRstay.npy', np.concatenate([ses_data['QRstay'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_QLreward.npy', np.concatenate([ses_data['QLreward'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_QRreward.npy', np.concatenate([ses_data['QRreward'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_QLlaser.npy', np.concatenate([ses_data['QLlaser'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_QRlaser.npy', np.concatenate([ses_data['QRlaser'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_QL.npy', np.concatenate([ses_data['QL'].to_numpy(),filler]))
                np.save(alf+'/'+prefix+'_QR.npy', np.concatenate([ses_data['QR'].to_numpy(),filler]))
                print(alf)

ROOT_FOLDER = '/Volumes/witten/Alex/Data/Subjects'
psy=mc.load_data()
standata = mc.make_stan_data(psy)
qlearning_params = pd.read_csv('/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/standard_alphalaserdecay/output/summary.csv')
qlearning_data = pd.DataFrame()
qlearning_data = mc.q_learning_model_alphalaserdecay(standata,saved_params=qlearning_params)
assert len(psy) == len(qlearning_data)
prefix='QLearning_alphalaserdecay'
save_q_values(ROOT_FOLDER,psy,qlearning_data,prefix)
Example #4
0
                       axis=0)))
     WAIC_laserdecay_mixedperseveration = -2 * (
         np.sum(np.log(REINFORCE_laserdecaywinloss_mixedstay.mean(axis=0)))
         - np.sum(
             np.var(np.log(REINFORCE_laserdecaywinloss_mixedstay), axis=0)))
     WAIC_laserdecay_mixedperseveration_noloss = -2 * (np.sum(
         np.log(REINFORCE_laserdecaywinloss_mixedstay_noloss.mean(axis=0))
     ) - np.sum(
         np.var(np.log(REINFORCE_laserdecaywinloss_mixedstay_noloss),
                axis=0)))
     WAIC_standard_laserdecay = -2 * (
         np.sum(np.log(standard_laserdecay.mean(axis=0))) -
         np.sum(np.var(np.log(standard_laserdecay), axis=0)))
 except:
     # 1
     standata = mc.make_stan_data(mc.load_data(trial_end=-1))
     path = '/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/standard_reduced_stay'
     model = mc.q_learning_model_reduced_stay
     WAIC_reducedstay = lppd_from_chain(path,
                                        model,
                                        standata,
                                        save=True,
                                        save_name='qreducedstay')
     # 2
     path = '/Volumes/witten/Alex/Data/ephys_bandit/stan_fits/standard_reduced'
     model = mc.q_learning_model_reduced
     WAIC_reduced = lppd_from_chain(path,
                                    model,
                                    standata,
                                    save=True,
                                    save_name='qreduced')