Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Tue Nov 17 14:38:26 2015
- @author: erik
- """
- from random import shuffle
- from collections import Counter
- liststim = []
- colors, firstfigures = ['Black', 'Blue'], ['Rect', 'Triangle', 'X', 'Circle']
- secondfigures = firstfigures
- for col in colors:
- for figure in firstfigures:
- for figure2 in secondfigures:
- liststim.append(col + '-' + figure + '_' + figure2)
- def randShift(listostim, ntrials):
- '''
- Will randomize 50 % of shifting trials
- based on that each filename (of the images) starts with Black or Blue-.
- listostim is a list of trials
- ntrials is an integer indicating number of trials
- '''
- nEachstim = ntrials/len(liststim) #Number of each stim is going to be even
- stimList = listostim
- trialTypes = []
- stims = []
- countOfStim = dict((el,0) for el in stimList)
- count = {'ns':0,'s':0}
- for i in range(ntrials):
- shuffle(stimList)
- for idx in range(len(stimList)):
- if not stims:
- countOfStim[stimList[idx]] +=1
- stims.append(stimList[idx])
- count['ns'] +=1
- trialTypes.append("No-Shifting")
- elif stims:
- if count['s'] <= ntrials/2:
- if countOfStim[stimList[idx]] <= nEachstim-1:
- if stimList[idx][:5] != stims[i-1][:5]:
- count['s'] +=1
- countOfStim[stimList[idx]] +=1
- stims.append(stimList[idx])
- trialTypes.append("Shifting")
- else:
- count['ns'] +=1
- countOfStim[stimList[idx]] +=1
- stims.append(stimList[idx])
- trialTypes.append("No-Shifting")
- elif count['s'] > ntrials/2:
- if countOfStim[stimList[idx]] <= nEachstim-1:
- if stimList[idx][:5] == stims[i-1][:5]:
- count['ns'] +=1
- countOfStim[stimList[idx]] +=1
- stims.append(stimList[idx])
- trialTypes.append("No-Shifting")
- #Frequency of the trialtypes
- freq = Counter(trialTypes).values()
- if freq[0] == freq[1] and sum(freq) == ntrials:
- return stims
- #We need to run again if the constrains we need is not satisfied
- elif freq[0] != ntrials/2 and freq[1] !=ntrials/2 or sum(freq) !=ntrials:
- return randShift(stimList, ntrials)
- randomized = randShift(liststim, 96)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement