From db1a3ae3a77febad50c20f53377cbedf28734f44 Mon Sep 17 00:00:00 2001 From: matus Date: Mon, 7 Sep 2015 17:01:43 +0200 Subject: [PATCH] publication of pursuit tracks chase --- code/Coord.py | 4 +- code/FiguresMoviesTables.py | 58 ++++----- code/Preprocess.py | 199 ----------------------------- code/README.md | 10 +- code/Settings.py | 87 ------------- code/Trajectory.py | 243 +----------------------------------- 6 files changed, 29 insertions(+), 572 deletions(-) diff --git a/code/Coord.py b/code/Coord.py index 4974f36..a4475dc 100644 --- a/code/Coord.py +++ b/code/Coord.py @@ -548,7 +548,6 @@ def plotAgdist(): plt.savefig(figpath+'trackAgdist') def computeTrackInfo(): - ''' ''' def _hlpfun(atraj,gaze,phiold,tphi,ttraj): dchv=np.int32(np.linalg.norm(np.diff(atraj,2,axis=0),axis=1)>0.0001) atraj-=gaze[:atraj.shape[0],:] @@ -745,8 +744,6 @@ def analyze(dat): print ndarray2latextable(np.array(out)) if __name__ == '__main__': - codingComparison() - bla for event in range(0,3)+range(96,100): for vpl in range(1,5): initVP(vpl=vpl,evl=event) @@ -760,3 +757,4 @@ def analyze(dat): computeMeanPF() computeTrackInfo() createIdealObserver() + codingComparison() diff --git a/code/FiguresMoviesTables.py b/code/FiguresMoviesTables.py index 0cec25a..630d6ad 100644 --- a/code/FiguresMoviesTables.py +++ b/code/FiguresMoviesTables.py @@ -934,50 +934,36 @@ def svmComparison(): plt.ylabel('Time to Saccade in Sec.') plt.savefig(figpath+'svmComparison',dpi=DPI,bbox_inches='tight') - - if __name__=='__main__': - #plotScore(999,1,pcs=4,scs=0) - #plotTrack(MOVIE=False) - #plotPCvp(999,1) - #plotBTpc() - #tabLatent(97,pcs=5) - #plotPC1rail() - plotPCvp(999,1) - bla - # to create figures run - plotPC1rail() - plotBehData() - plotPC1rail() - svmComparison() - plotBTpc() - plotTrack(MOVIE=False) - plotVel() - plotPCvp(999,1) + # generation of figure 1 was not automated + plotBehData()# figures 2, 3 + plotBTpc()# figure 4 + plotPC1rail()# figure 5 + svmComparison() # figure 6 + plotTrack(MOVIE=False)# figures 7, 8 + plotVel() # figure 9 + plotPCvp(999,1) # figure 10 - from ReplayData import compareCoding - compareCoding(vp=2,block=18,cids=[0,1,2,4]) - # to create movies run - pcAddition() - plotBTmean() - plotCoeff(97) - plotCoeff(0) - plotCoeff(1) - plotTrack() - svmPlotExtrema() - plotScore(999,1,pcs=4,scs=0) + plotCoeff(97) # movie 3 + pcAddition() # movie 4 + plotCoeff(0)# movie 5 + plotCoeff(1) # movie 6 + svmPlotExtrema() # movie 7 + plotTrack() # movies 8, 9 + plotScore(999,1,pcs=4,scs=0) # movie 11 from ReplayData import replayTrial #note the following trials will be displayed but not saved as movies - replayTrial(vp =1,block=11,trial=7,tlag=0.0,coderid=4)#mov01 - replayTrial(vp =2,block=2,trial=19,tlag=0.0,coderid=4)#mov02 - replayTrial(vp =1,block=10,trial=9,tlag=0.0,coderid=4)#mov10 - replayTrial(vp =3,block=1,trial=12,tlag=0.0,coderid=4)#mov11 - replayTrial(vp =3,block=1,trial=7,tlag=0.0,coderid=4)#mov12 - # to create tables run + replayTrial(vp =1,block=11,trial=7,tlag=0.0,coderid=4)#movie 1 + replayTrial(vp =2,block=2,trial=19,tlag=0.0,coderid=4)#movie 2 + replayTrial(vp =1,block=10,trial=9,tlag=0.0,coderid=4)#movie 10 + replayTrial(vp =3,block=1,trial=12,tlag=0.0,coderid=4)#movie 12 + replayTrial(vp =3,block=1,trial=7,tlag=0.0,coderid=4)#movie 13 + + # to compute values for the tables run si2tex() tabLatent(0,pcs=5) tabLatent(1,pcs=5) diff --git a/code/Preprocess.py b/code/Preprocess.py index 862f697..1c88b76 100644 --- a/code/Preprocess.py +++ b/code/Preprocess.py @@ -175,198 +175,6 @@ def readEyelink(vp,block): data= _discardInvalidTrials(data) return data - -def readSMI(vp,block): - ''' reads SMI text file (.txt) of subject VP and block BLOCK - the file should be at /smiOutput/VPB.asc - requires the corresponding input files on the input path - vp - subject id - block - experiment block - returns ETData instance - NOTE: this code is experimental - TODO blinks?, latency during the transport of messages? - ''' - path = os.getcwd() - path = path.rstrip('code') - f=open(path+'smiOutput/VP%03dB%d Samples.txt'%(vp,block),'r') - Qexp=Settings.load(Q.inputPath+'vp%03d'%vp+Q.delim+'SettingsExp.pkl' ) - ms= Qexp.monitor.getSizePix() - try: - line=f.readline() - data=[] - PHASE= -1 # 0-DCORR, 1-TRIAL, 2-DECISION, 4-CALIB - etdat=[] - t0=[0,0,0] - calib=[] - i=0;fr=0;t=0;ftriggers=[] - while True: - words=f.readline().split() - - #if i%100==0: print i - #if i<200: print i, words - #if i>1300: break - i+=1 - if len(words)>2 and words[2]=='Rate:': - hz=float(words[3]); - if len(words)>2 and words[2]=='Area:': - cent=(float(words[3])/2.0,float(words[4])/2.0) - if len(words)>5 and words[5]=='MONITORDISTANCE': - distance=float(words[6]) - if len(words)==0: break - # todo -## if len(words)>2 and words[2]=='!CAL': -## if len(words)==3: PHASE=4 -## elif words[3]=='VALIDATION' and not (words[5]=='ABORTED'): -## if words[6] == 'RIGHT': -## calib[-1].append([t,float(words[9]),float(words[11]),RIGHTEYE]) -## PHASE= -1 -## else: -## calib.append([]) -## calib[-1].append([t,float(words[9]),float(words[11]),LEFTEYE]) - if len(words)>5 and words[5]=='FRAME': - ftriggers.append([fr,float(words[0])/1000.0,float(words[7])]) - fr=int(words[6])+1 - if len(words)>5 and words[5]=='TRIALID': - eye='BOTH';t=int(words[6]) - PHASE=0;t0[0]=float(words[0])/1000.0 - if len(words)>5 and words[5]=='START': - PHASE=1;t0[1]=float(words[0])/1000.0 - if len(words)>5 and (words[5]=='DETECTION'): - PHASE=2; t0[2]= float(words[0])/1000.0 - #if len(words)>2 and words[2]=='POSTTRIAL': - if len(words)>5 and (words[5]=='POSTTRIAL' or words[5]=='OMISSION'): - etdat = _reformat(etdat,t0[0],Qexp) - ftriggers=np.array(ftriggers) - print ftriggers.shape - if ftriggers.size>0: ftriggers[:,1] -= t0[1] - if etdat.size>0: - et=ETData(etdat,calib,t0, - [vp,block,t,hz,eye],fs=ftriggers) - data.append(et) - - etdat=[];t0=[0,0,0];ftriggers=[];fr=0 - calib=[];PHASE= -1 - #LBLINK=False; RBLINK=False - if PHASE== -1 or PHASE==4: continue - if len(words)>2 and words[1]=='SMP': - # we check whether the data gaze position is on the screen - if words[7]=='.': xleft=np.nan; yleft=np.nan - else: - xleft=float(words[7]); yleft=float(words[8]) - #if xleft>ms[0] or xleft<0 or yleft>ms[1] or yleft<0: - if yleft==0 or xleft==0: - xleft=np.nan; yleft=np.nan; - if words[9]=='.': xright=np.nan; yright=np.nan - else: - xright=float(words[9]); yright=float(words[10]) - #if xright>ms[0] or xright<=0 or yright<=0 or yright>ms[1]: - if xright==0 or yright==0: - xright=np.nan; yright=np.nan; - meas=(float(words[0])/1000.0,xleft,yleft, - float(words[3]),xright,yright,float(words[5])) - etdat.append(meas) - f.close() - except: f.close(); raise - data=_discardInvalidTrials(data) - return data - -def readTobii(vp,block,path,lagged=False,verbose=False): - ''' - reads Tobii controller output of subject VP and block BLOCK - the file should be at /VPB.csv - requires the corresponding input files on the input path - vp - subject id - block - experiment block - path - path to the eyetracking data - lagged - log time stamp when the data was made available - (ca. 30 ms time lag), useful for replay - verbose - print info - returns ETData instance - - Each trial starts with line '[time]\tTrial\t[nr]' - and ends with line '[time]\tOmission' - ''' - from Settings import Qexp - if verbose: print 'Reading Tobii Data' - #path = os.getcwd() - #path = path.rstrip('code') - f=open(path+'VP%03dB%d.csv'%(vp,block),'r') - #Qexp=Settings.load(Q.inputPath+'vp%03d'%vp+Q.delim+'SettingsExp.pkl' ) - - #f=open('tobiiOutput/VP%03dB%d.csv'%(vp,block),'r') - ms= Qexp.monitor.getSizePix() - try: - data=[];trial=[]; theta=[];t=0;msgs=[]; t0=[0,0,0];reward=[] - on=False - while True: - words=f.readline() - if len(words)==0: break - words=words.strip('\n').strip('\r').split('\t') - if len(words)==2: # collect header information - if words[0]=='Recording time:': - recTime=words[1]; t0[0]=0; on=True - if words[0]=='Subject: ':on=False - if words[0]=='Recording refresh rate: ': - hz=float(words[1]) - elif len(words)==4 and words[2]=='Trial': - t0[1]=trial[-1][0] # perturb - elif len(words)==4 and words[2]=='Phase': - phase=int(words[3]) - elif len(words)>=11 and on: # record data - # we check whether the data gaze position is on the screen - xleft=float(words[2]); yleft=float(words[3]) - if xleft>ms[0] or xleft<0 or yleft>ms[1] or yleft<0: - xleft=np.nan; yleft=np.nan; - xright=float(words[5]); yright=float(words[6]) - if xright>ms[0] or xright<0 or yright<0 or yright>ms[1]: - xright=np.nan; yright=np.nan; - if lagged: tm =float(words[0])+float(words[8]);ff=int(words[1]) - else: tm=float(words[0]);ff=int(words[1])-2 - tdata=(tm,xleft,yleft,float(words[9]), - xright,yright,float(words[10]),ff) - trial.append(tdata) - elif len(words)>2 and (words[2]=='Detection' or words[2]=='Omission'): - # we have all data for this trial, transform to deg and append - on=False;t0[2]=trial[-1][0] - trial=np.array(trial) - trial[trial==-1]=np.nan # TODO consider validity instead of coordinates - trial=_reformat(trial,t0[0],Qexp) - #print t0, trial.shape, trial[0,0] - et=ETData(trial[:,:-1],[],t0, - [vp,block,t,hz,'BOTH'],fs=np.array([np.nan,np.nan]),recTime=recTime,msgs=msgs) - fs=trial[et.ts:et.te,[-1,0]] - fs[:,1]-=t0[1] - for fff in range(fs.shape[0]-2,-1,-1): - if fs[fff+1,0]0: - val=(msg[1]-et.fs.shape[0])*75/et.hz+et.fs[-1,2] - msg.append(int(round(val))) - else: msg.append(int(et.fs[int(msg[1]),2])) - #et.extractBasicEvents(trial[:,:-1]); - et.phase=phase;et.reward=reward - data.append(et) - t+=1;trial=[];msgs=[];reward=[] - elif on and len(words)==6: - msgs.append([float(words[0])-t0[1],words[2]+' '+words[5]]) - elif on and len(words)>2: - msgs.append([float(words[0])-t0[1],int(words[1]),words[2]]) - if words[2]=='Reward On': reward=[float(words[0])-t0[1]] - if words[2]=='Reward Off': reward.append(float(words[0])-t0[1]) - except: f.close(); print 'Words: ',words; raise - f.close() - if verbose:print 'Finished Reading Data' - return data ####################################### def saveETinfo(vp=1,coderid=4,suf=''): @@ -484,13 +292,6 @@ def saveETinfo(vp=1,coderid=4,suf=''): if __name__ == '__main__': import sys - saveTrackedAgs(vp=2,coderid=4) - bla vp=int(sys.argv[1]) coder=int(sys.argv[2]) saveETinfo(vp=vp,coderid=coder,suf='coder%d'%coder) - - - #print np.int32(np.isnan(data[0].gaze[:1000,1])) - #data[0].extractBasicEvents() - #for dat in data: dat.extractBasicEvents() diff --git a/code/README.md b/code/README.md index b298bce..2572e07 100644 --- a/code/README.md +++ b/code/README.md @@ -36,9 +36,9 @@ Dependencies * [PyStan](http://pystan.readthedocs.org/en/latest/) for statistical inference -* [Eyelink routines](http://github.com/simkovic/eyetracking/blob/master/Eyelink.py) to run eyetracking experiment +* [Eyelink routines](http://github.com/simkovic/eyetracking/releases/tag/pursuittrackschase) to run eyetracking experiment -* [matustools](https://github.com/simkovic/matustools) to reproduce the figures +* [matustools](http://github.com/simkovic/matustools/releases/tag/pursuittrackschase) to reproduce the figures * [Libsvm](http://www.csie.ntu.edu.tw/~cjlin/libsvm/) @@ -49,8 +49,8 @@ Looking to Reuse Code? The code in this repository is meant as an documentation for the published research. The code has not been developed since the publication and may no longer work with the latest versions of its dependencies (such as Psychopy or PyStan). If you are interested in an maintained and (hopefully) up-to-date version of my code please have a look at the following repositories: -* [goal-directed motion toolkit](https://github.com/simkovic/GoaldirectedMotionPsychoexperiments) to create Stimuli and run Experiments +* [goal-directed motion toolkit](http://github.com/simkovic/GoaldirectedMotionPsychoexperiments) to create Stimuli and run Experiments -* [eyetracker](https://github.com/simkovic/eyetracking) to run Eyetracking experiments with Psychopy +* [eyetracker](http://github.com/simkovic/eyetracking) to run Eyetracking experiments with Psychopy -* [matusplotlib](https://github.com/simkovic/matusplotlib/) to plot figures +* [matusplotlib](http://github.com/simkovic/matusplotlib/) to plot figures diff --git a/code/Settings.py b/code/Settings.py index e5214b5..b2d5f4a 100644 --- a/code/Settings.py +++ b/code/Settings.py @@ -141,29 +141,9 @@ def load(filepath): ########################################################## # monitors, please define your own monitor -dell=monitors.Monitor('dell', width=37.8, distance=60); dell.setSizePix((1280,1024)) sonycrt=monitors.Monitor('sony', width=40, distance=60); sonycrt.setSizePix((1280,1024)) -smidell=monitors.Monitor('smiDell', width=47.5, distance=60);smidell.setSizePix((1680,1024)) -t60=monitors.Monitor('tobii', width=34, distance=50); t60.setSizePix((1280,1024)) eizo=monitors.Monitor('eizo', width=34, distance=40); eizo.setSizePix((1280,1024)) -laptop={'monitor' : dell, - 'refreshRate': 60, # [hz] - 'os': LINUX, # Linux or Windows - 'phiRange': [120,0*2], # in degrees [0-360] - 'agentSize': 1, # in degrees of visial angle - 'initDistCC': [12.0 ,18.0], # in degrees of visial angle - 'pDirChange': [4.8,5.4,4.8], # avg number of direction changes per second - 'bckgCLR': [-1,-1,-1], - 'agentCLR': 1, # [1 -1] - 'mouseoverCLR': 0.5, # [1 -1] - 'selectedCLR': -0.5, # [1 -1] - 'trialDur': 30, # in seconds - 'aSpeed': 14.5, # in degrees of visual angle per second - 'guiPos': (200,400), # in pixels - 'winPos': (0,1), # in pixels - 'fullscr': False} - eyelinklab ={'monitor' :sonycrt, 'refreshRate': 85, # [hz] 'os': WINDOWS, # Linux or Windows @@ -181,73 +161,6 @@ def load(filepath): 'winPos': (0,0), # in pixels 'fullscr': True} -smilab ={'monitor' : smidell, - 'refreshRate': 60, # [hz] - 'os': WINDOWS, # Linux or Windows - 'phiRange': [120,0*2], # in degrees [0-360] - 'agentSize': 1, # in degrees of visial angle - 'initDistCC': [12.0 ,18.0], # in degrees of visial angle - 'pDirChange': [4.8,5.4,4.8], # avg number of direction changes per second - 'bckgCLR': [-0,-0,-0], - 'agentCLR': 1, # [1 -1] - 'mouseoverCLR': 0.5, # [1 -1] - 'selectedCLR': -0.5, # [1 -1] - 'trialDur': 30, # in seconds - 'aSpeed': 14.5, # in degrees of visual angle per second - 'guiPos': (200,400), # in pixels - 'winPos': (0,0), # in pixels - 'fullscr': True} -tobiilab ={'monitor' : t60, - 'refreshRate': 75, # [hz] - 'os': LINUX, #hotfix # Linux or Windows - 'phiRange': [120,0*2], # in degrees [0-360] - 'agentSize': 1, # in degrees of visial angle - 'initDistCC': [12.0 ,18.0], # in degrees of visial angle - 'pDirChange': [4.8,5.4,4], # avg number of direction changes per second - 'bckgCLR': [-0,-0,-0], - 'agentCLR': 1, # [1 -1] - 'mouseoverCLR': 0.5, # [1 -1] - 'selectedCLR': -0.5, # [1 -1] - 'trialDur': 120, # in seconds - 'aSpeed': 9, # in degrees of visual angle per second - 'guiPos': (-800,400), # in pixels - 'winPos': (1280,0), # in pixels - 'fullscr': True} - -gao10e3={'monitor' : t60, - 'refreshRate': 75, # [hz] - 'os': WINDOWS, # Linux or Windows - 'phiRange': [90,90], # in degrees [0-360] - 'agentSize': 1.9, # in degrees of visial angle - 'initDistCC': [4.0 ,4.0], # in degrees of visial angle - 'pDirChange': [3.0,3.0,3.0], # avg number of direction changes per second - 'bckgCLR': [-1,-1,-1], - 'agentCLR': 1, # [1 -1] - 'mouseoverCLR': 0.5, # [1 -1] - 'selectedCLR': -0.5, # [1 -1] - 'trialDur': 17, # in seconds - 'aSpeed': 7.8, # in degrees of visual angle per second - 'guiPos': (-800,400), # in pixels - 'winPos': (1280,0), # in pixels - 'fullscr': True} - -gao10e4={'monitor' : t60, - 'refreshRate': 75, # [hz] - 'os': WINDOWS, # Linux or Windows - 'phiRange': [90,60.0], # in degrees [0-360] - 'agentSize': 1.5, # in degrees of visial angle - 'initDistCC': [4.0 ,4.0], # in degrees of visial angle - 'pDirChange': [3.0,3.0,3.0], # avg number of direction changes per second - 'bckgCLR': [-1,-1,-1], - 'agentCLR': 1, # [1 -1] - 'mouseoverCLR': 0.5, # [1 -1] - 'selectedCLR': -0.5, # [1 -1] - 'trialDur': 8, # in seconds - 'aSpeed': 5.5, # in degrees of visual angle per second - 'guiPos': (-800,400), # in pixels - 'winPos': (1280,0), # in pixels - 'fullscr': True} - matusdesktop ={'monitor' : eizo, 'refreshRate': 60 , # [hz] 'os': LINUX, # Linux or Windows diff --git a/code/Trajectory.py b/code/Trajectory.py index ce54b74..e028d31 100644 --- a/code/Trajectory.py +++ b/code/Trajectory.py @@ -560,251 +560,10 @@ def generateMixedExperiment(vpn,trialstotal,blocks=4,condition=14, os.chdir('..') os.chdir('..') -def generateBabyExperiment(vpn,nrtrials=10,blocks=1,conditions=[6,8],rd=0,pdch=None, - dispSize=29,maze=None): - '''my work in progress, baby experiment''' - #os.chdir('..') - if not pdch is None: Q.setpDirChange(pdch) - os.chdir(Q.inputPath) - mazes=[] - Q.nrframes+= Q.refreshRate *5 - print 'Generating Trajectories' - for vp in vpn: - vpname='vp%03d' % vp - os.mkdir(vpname) - os.chdir(vpname) - r=[] - phase=[0,1,1,2] - for i in range((len(conditions)*nrtrials-len(phase))/2): - if np.random.rand()>0.5: phase.extend([1,2]) - else: phase.extend([2,1]) - print 'phase', phase - for block in range(blocks): - i=0 - for condition in conditions: - for trial in range(nrtrials): - if condition==conditions[0]: - if np.random.rand()>0.5: r.extend([trial, trial+nrtrials]) - else: r.extend([trial+nrtrials,trial]) - trajectories=None - while trajectories ==None: - trajectories=generateTrial(condition, - maze=EmptyMaze((1,1),dispSize=(dispSize,dispSize)),rejectionDistance=rd) - #fn='%str%03dcond%02d'% (vpname,trial,conditions[order[trial]]) - #fn = 'trial%03d' % trial - trajectories=trajectories[(Q.refreshRate*5):] - #print trajectories.shape - fn='%sb%dtrial%03d'% (vpname,block,i) - i+=1 - print fn - np.save(fn,trajectories) - #r=np.random.permutation(nrtrials*len(conditions)) - r=np.array(r) - print r - np.save('order%sb%d'% (vpname,block),r) - np.save('phase%sb%d'% (vpname,block),phase) - Q.save('SettingsTraj.pkl') - os.chdir('..') - os.chdir('..') - -def generateTremouletTrial(phi=0, lam=1): - ''' Reference: Tremoulet, P. D., & Feldman, J. (2000). - Perception of animacy from the motion of a single object. - Perception, 29(8), 943-952. - phi - magnitude of the direction change in degrees - lam - velocity change as vel_after/vel_before - returns ndarray of the same shape as generateTrial() - TODO: use settings from Settings.py - ''' - refreshRate=60 # Hz - speed=3.25/refreshRate - angle=0 - duration=0.75 # in seconds - N=np.int32(duration*refreshRate) # nr of frames - traj = np.zeros((N,1,2)) - traj[0,0,X] = -speed*(N/2-0.5); traj[0,0,Y]=0 - for i in range(1,N): - traj[i,0,X]=np.cos(angle/180.0*np.pi)*speed+traj[i-1,0,X] - traj[i,0,Y]=np.sin(angle/180.0*np.pi)*speed+traj[i-1,0,Y] - if i==((N-1)/2): - speed=speed*lam - angle=angle+phi - return traj - - -def generateGao09e1(vpn): - ''' Experiment 1 from Gao et al. (2009) - Gao, T., Newman, G. E., & Scholl, B. J. (2009). - The psychophysics of chasing: A case study in - the perception of animacy. - Cognitive psychology, 59(2), 154-179. - vpn - tuple of ints, each value gives the subject id - ''' - # gao09e1 settings - # TODO move settings to Settings.py - nrtrials=15 - maze=EmptyMaze((1,1),dispSize=(32,24),lw2cwRatio=0) - chs=[0,60,120,180,240,300] - Q.setTrialDur(10);Q.phiRange=(120,120) - Q.setpDirChange([5.9,5.9,5.9]) - block=0 - #os.chdir('..') - os.chdir('..') - os.chdir('input/') - for vp in vpn: - vpname='vp%03d' % vp - os.mkdir(vpname) - os.chdir(vpname) - i=0 - r=np.zeros((2*6*nrtrials,2)) - r[:,0]=np.random.permutation(2*6*nrtrials) - for cond in range(6): - for trial in range(nrtrials): - Q.phiRange=(Q.phiRange[0],chs[cond]) - trajectories=None - while trajectories ==None: - trajectories=generateTrial(5,maze=maze, - rejectionDistance=5.0) - #target present trial - r[i,1]=cond - fn='gao09e1%sb%dtrial%03d'% (vpname,block,i); - np.save(fn,trajectories[:,:-1,:]);i+=1 - #target absent trial - r[i,1]=cond+6 - fn='gao09e1%sb%dtrial%03d'% (vpname,block,i); - np.save(fn,trajectories[:,1:,:]);i+=1 - - np.save('gao09e1order%sb%d'% (vpname,block),r) - Q.save('SettingsTraj.pkl') - os.chdir('..') - os.chdir('..') - -def generateGao10e4(vpn): - ''' Experiment 4 from Gao et al. (2010) - Gao, T., McCarthy, G., & Scholl, B. J. (2010). - The Wolfpack Effect Perception of Animacy Irresistibly - Influences Interactive Behavior. - Psychological science, 21(12), 1845-1853. - vpn - tuple of ints, each value gives the subject id - ''' - # gao10e4 settings - maze=EmptyMaze((1,1),dispSize=(18,18),lw2cwRatio=0) - Q.setTrialDur(8); nrtrials=90; - Q.setAspeed(5.1) - os.chdir('..');os.chdir('input/') - for vp in vpn: - vpname='vp%03d' % vp;os.mkdir(vpname);os.chdir(vpname) - for trial in range(nrtrials): - if vp>400 and vp<500: continue - trajectories=generateTrial(12,maze=maze, rejectionDistance=0.0) - fn='%strial%03d'% (vpname,trial); - np.save(fn,trajectories[:,2:,:]) - np.save('order%sb0'% (vpname),np.random.permutation(nrtrials)) - np.save('order%sb1'% (vpname),np.random.permutation(nrtrials)) - np.save('order%sb2'% (vpname),np.random.permutation(nrtrials)) - Q.save('SettingsTraj.pkl') - os.chdir('..') - -def generateGao10e3(vpn): - ''' Experiment 3 from Gao et al. (2010) - Gao, T., McCarthy, G., & Scholl, B. J. (2010). - The Wolfpack Effect Perception of Animacy Irresistibly - Influences Interactive Behavior. - Psychological science, 21(12), 1845-1853. - vpn - tuple of ints, each value gives the subject id - ''' - offs=5.875; sz=(2*offs+Q.agentSize,2*offs+Q.agentSize) - quadrants=[EmptyMaze((1,1),dispSize=sz,pos=(offs,offs),lw2cwRatio=0), - EmptyMaze((1,1),dispSize=sz,pos=(-offs,offs),lw2cwRatio=0), - EmptyMaze((1,1),dispSize=sz,pos=(offs,-offs),lw2cwRatio=0), - EmptyMaze((1,1),dispSize=sz,pos=(-offs,-offs),lw2cwRatio=0)] - nrtrials=42; - os.chdir('..');os.chdir('input/') - for vp in vpn: - vpname='vp%03d' % vp;os.mkdir(vpname);os.chdir(vpname) - for trial in range(nrtrials): - if vp>300 and vp<400 and vp!=350: continue - trajectories=[] - for k in range(len(quadrants)): - traj=generateTrial(5,maze=quadrants[k], rejectionDistance=0.0) - trajectories.append(traj[:,2:,:]) - fn='%strial%03d'% (vpname,trial); - np.save(fn,np.concatenate(trajectories,axis=1)) - np.save('order%sb%d'% (vpname,0),np.random.permutation(nrtrials)) - np.save('order%sb%d'% (vpname,1),np.random.permutation(nrtrials)) - np.save('order%sb%d'% (vpname,2),np.random.permutation(nrtrials)) - - Q.save('SettingsTraj.pkl') - os.chdir('..') - -################################################## - -def exportSvmGao09(nrtrials=10000): - ''' exports trajectories from Experiment 1 from Gao et al. (2009) - to a text file that can be used for a classification with a - support vector machine from libsvm - nrtrials - number of trials/samples to generate - ''' - def saveTraj(fout,traj,label): - sample=5 - fout.write('%d '%label) - i=1 - for f in range(traj.shape[0]/sample): - for a in range(2): - fout.write('%d:%f '%(i,traj[f*sample,a,0]));i+=1 - fout.write('%d:%f '%(i,traj[f*sample,a,1]));i+=1 - fout.write('\n') - - maze=EmptyMaze((1,1),dispSize=(32,24)) - chs=[300,240,180,120,60,0] - block=1 - os.chdir('input/') -## fout=open('svmGao2.train','w') -## for trial in range(nrtrials): -## print trial -## for cond in range(6): -## trajectories=generateTrial(5,maze=maze,rejectionDistance=5.0, -## moveSubtlety=(chs[cond],120),trialDur=10) -## trajectories[:,:,0]/= 32.0 -## trajectories[:,:,1]/= 24.0 -## saveTraj(fout,trajectories[:,[0,1],:],1); -## saveTraj(fout,trajectories[:,[4,1],:],-1); -## fout.close() - - nrtrials=10000 - for cond in range(5): - print cond - fout1=open('svmGaoCond%03dT.train'%chs[cond],'w') - fout2=open('svmGaoCond%03dF.train'%chs[cond],'w') - for trial in range(nrtrials): - trajectories=generateTrial(5,maze=maze,rejectionDistance=5.0, - moveSubtlety=(chs[cond],120),trialDur=10) - trajectories[:,:,0]/= 32.0 - trajectories[:,:,1]/= 24.0 - saveTraj(fout1,trajectories[:,[0,1],:],1); - saveTraj(fout2,trajectories[:,[4,1],:],-1); - fout1.close() - fout2.close() - os.chdir('..') - if __name__ == '__main__': - generateGao09e1([2]) - bla - # the following code generates the trajectories for the - # control computation with shuffled and misaligned gaze position - random.seed(4) - from AnalysisBaby import BABYVPN - vpn=BABYVPN - f= lambda x: x+100 - generateBabyExperiment(map(f,vpn[0]),rd=3.0,pdch=[4.8,5.4,4],nrtrials=15) - generateBabyExperiment(map(f,vpn[1]),rd=0.0,pdch=[4,4,4],nrtrials=15) - generateBabyExperiment(map(f,vpn[2]),rd=0.0,pdch=[5.4,5.4,5.4],nrtrials=15) - generateBabyExperiment(map(f,vpn[3]),rd=0.0,pdch=[5.4,5.4,5.4],nrtrials=15) + generateMixedExperiment([1],40,blocks=24,probeTrials=True) - - -