# plt.show()

#% INITIAL CONDITIONS

# mySession.loc[0,'waitingTime'] = np.random.choice(np.arange(tbf.shape[1]), 1, p=pnorm((tbf.T @ W).values[:,mySession.iperc[0]])).item()
#
# mySession.loc[0,'feedbackTime'] = truncExp(1.5, .5, 8)

#%
# hf[ipair], ha[ipair] = plt.subplots(1, 3, figsize=(10, 3))

# %%
#
for iTrial in range(nTrials):
    ## S
    mySession.loc[iTrial, 'feedbackTime'] = truncExp(1.5, .5, 8)

    ## A
    mySession.loc[iTrial, 'waitingTime'] = K.loc[mySession.iperc[iTrial]]
    # waitingTime[iTrial + 1] = np.random.choice(np.arange(tbf.shape[1]), 1, p=pnorm(np.dot(kernel.T, tbf))).item()

    ## R
    mySession.loc[iTrial, 'isRewarded'] = mySession.loc[
        iTrial, 'isCorrect'] and not mySession.loc[
            iTrial, 'isCatch'] and mySession.loc[
                iTrial, 'waitingTime'] > mySession.loc[iTrial, 'feedbackTime']
    if iTrial % 500 == 0:
        print(iTrial)
        # sns.regplot(x='stim', y='isChoiceLeft', data=mySession, logistic=True, ci=None, ax=ha[0])
        #
        # sns.regplot(x='abs_stim', y='waitingTime', ax=ha[1],
示例#2
0
np.random.seed(42)

nTrials = 100000
pCatch = 0.1
stim_pairs = [[5,95],[30,70],[45,55]]
stims = np.sort(np.array(stim_pairs).ravel())
stim_noise = 15

m = np.random.choice(stims, nTrials)
mprime = m+np.random.randn(nTrials) * stim_noise

mySession = pd.DataFrame({'stim':m,'perc':mprime,'isChoiceLeft': mprime > 50})
mySession.loc[:,'isCorrect'] = (m > 50) == mySession.isChoiceLeft
mySession.loc[:,'waitingTime'] = abs((m+np.random.randn(nTrials) * stim_noise) - 50)/8#truncExp(1.5,0.5,8,nTrials)
mySession.loc[:,'feedbackTime'] = truncExp(1.5,0.5,8,nTrials)
mySession.loc[:,'isCatch'] = np.random.rand(nTrials) < pCatch
mySession.loc[:,'isRewarded'] = np.logical_and(mySession.loc[:,'isCorrect'],
                                               mySession.loc[:,'waitingTime']>mySession.loc[:,'feedbackTime'])
mySession.loc[:,'isRewarded'] = np.logical_and(mySession.loc[:,'isRewarded'],
                                               np.logical_not(mySession.isCatch))
mySession.loc[:,'trialDur'] = mySession.loc[:,'waitingTime']
mySession.loc[mySession.loc[:,'isRewarded'],'trialDur'] = mySession.loc[mySession.loc[:,'isRewarded'],'feedbackTime']
rho = mySession.isRewarded.sum()/mySession.trialDur.sum()
mySession.loc[:,'Return'] = mySession.isRewarded - rho*mySession.trialDur
mySession.loc[:,'abs_stim'] = abs(50 - mySession.loc[:,'stim'])

X = [mySession.loc[:,var].values.astype(float) for var in ['perc','isChoiceLeft','waitingTime']]

#%% CRITIC
ndx = mySession.isChoiceLeft==mySession.isChoiceLeft
示例#3
0
cols = [
    'stim', 'perc', 'z', 'isChoiceLeft', 'isCorrect', 'rho', 'boundary',
    'slope'
]

mySession = pd.DataFrame(index=np.arange(nTrials), columns=cols)

mySession.loc[:, 'stim'] = np.random.choice(stim_set, nTrials)
mySession.loc[:, 'perc'] = mySession.loc[:, 'stim'] + np.random.randn(
    nTrials) * stim_noise

# isCorrect = np.random.rand(nTrials) < pCorrect
mySession.loc[:, 'p_rew'] = np.nan
mySession.loc[:, 'waitingTime'] = np.nan
mySession.loc[:, 'feedbackTime'] = truncExp(Beta, 0., 18.,
                                            nTrials).astype(float)
mySession.loc[:, 'isCatch'] = np.random.rand(nTrials) < pCatch
mySession.loc[:, 'isRewarded'] = np.nan
mySession.loc[:, 'rho'] = np.nan
mySession.loc[:, 'beta'] = Beta

# X = [mySession.loc[:,var].values.astype(float) for var in ['perc','isChoiceLeft','waitingTime']]

#%
# rho = pd.Series(index=np.arange(nTrials))#,columns=np.sort(mySession.istim.drop_duplicates()))
# rho.loc[0] = 0
#%%
for iTrial in range(nTrials):
    # S
    # mySession.loc[iTrial, 'feedbackTime'] = truncExp(Beta, .5, 8)
    # A