def printSimResults(results): stopCurve, goRTs, ssrts = utils.stop_curve(results) print "Stop Curve:" print stopCurve print "GO RT: %0.3f " % (goRTs)
def simulate(theta, mean, std, ntrials=20000, timebound=.650, learn=False, acc=None, ssv_decay=False, sim=False): ######################################################### # TESTING LEARN FX # ######################################################### """ Notes for learning: *set learn=True *if you want the accumulated evidence vectors set return_all=True *IMPORTANT: theta needs to contain parameters 'cor_lr': learning rate following correct trials 'err_lr': learning rate following error trials *IMPORTANT: acc is a binary vector containing the accuracy for each trial * when you're fitting (using fitre.fit_reactive_data()) then it will use the subject's actual accuracy data * if you're just simulating with this function then you need to provide this vector I'd reccomend pulling an example from the subject dataframe when you're in preliminary testing stages (df = your subject dataframe) To do this get your accuracy vector from some subject (e.g. subject 12) example_acc=df[df['idx']==12]['acc'].values ntrials=len(example_acc) theta={'pGo':.5, 'a':0.4, 'z':.19, 'v':1.1, 't':0.235, 'ssv':-1, 'cor_lr':.09, err_lr:-.11} Then set fitre.simulate(theta, ntrials=ntrials, acc=example_acc, learn=True, return_all=True) The output will be a pandas dataframe. The df will have a column 'v' containing the drift-rate for that trial, you can use this column to bin drift-rates and look at the accuracy, rt info for each *once you have good estimates for cor_lr and err_lr, try optimizing to set of behavioral data using fitre.fit_reactive_data() """ acc = [] columns = ['rt', 'choice', 'response', 'acc', 'trial_type', 'ssd', 'v', 'probe'] #pGo mfx= fitfx_learn.radd_fitfx if learn: learnfrom={'previous':0, 'time_dif' : 0, 'prev_response': 0} else: learnfrom=None df = pd.DataFrame(columns=columns, index=np.arange(0,ntrials)) for i in xrange(ntrials): (ttype,ssd,is_probe) = utils.generate_trial(mean,std) theta['ssd'] = ssd if learn and i == 0: sim_out = mfx(theta, timebound=timebound, ttype=ttype, learnfrom=None) else: sim_out = mfx(theta, timebound=timebound, ttype=ttype, learnfrom=learnfrom) sim_out['probe'] = is_probe df.loc[i]=pd.Series({c:sim_out[c] for c in df.columns}) acc.append(sim_out['acc']) if learn: learnfrom['prev_outcome'] = int(sim_out['acc']) learnfrom['time_dif'] = 0.500 - sim_out['rt'] learnfrom['prev_response'] = sim_out['response'] df[['rt', 'acc', 'response','v']] = df[['rt', 'acc', 'response', 'v']].astype(float) if sim: return df else: #get mean vectors sacc,rt,sem =utils.stop_curve(df) go_rt=utils.get_rtcor(df, tb=timebound)*10 return sacc, go_rt