Dear discourse community,
I am having problems creating a working memory paradigm using words and wondered if anyone could provide some advice.
Description of paradigm:
1-back working memory word paradigm. Using a list of 600 words from 60 categories (10 words from each category). Participants will be required to press a key when a word is semantically related to the word previously presented and another key if the word is semantically unrelated to the word presented before.
Currently my code will randomly choose a category from an array (e.g; ugly, I know):
categories = [1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,
10,10,10,10,10,10,10,10,10,10]
This is used to create an index:
indx = random.choice(range(0,len(categories)))
From this indx is then used to draw a word from a text file, set out like:
diamond
ruby
opal
etcâŚ
and loaded in using:
def load_words(words):
print "Loading word list from fileâŚ"
wordlist = list()
with open(words) as f:
for line in f:
wordlist.append(line.rstrip(â\nâ))
print " ",len(wordlist), "words loaded."
print â\nâ.join(wordlist)
return wordlist
wordlist = load_words(âtest_word_list.txtâ)
the categories variable (the array of 1,1,1,1,1,etcâŚ) defines the category that the words belong to (i.e. the first ten 1âs refer to precious stones).
A for loop then selects a word based on indx to display.
However, Given the amount of different words, it is unlikely that the presentation of the second word will be semantically related to the first (i.e. from the same category). Therefore I have tried to create a way of increasing the probability of the loop drawing from the same category.
I have done this via:
numCats = len(set(categories)) #number of unique categories
rangeCats = range(0,numCats)
myProb = 0.25
nReps = round(((numCats-1)/(1-myProb))-(numCats-1)) - 1 #(numCats - 1)/(1-myProb) is to get the 75% chance of picking out of the number of categories
nReps = int(nReps)
following the selection of the word based on the indx the word will be presented and then the selection of that category number
will be re-added back into the categories array
for i in range(0,20):
myFix.draw()
myWin.flip()
core.wait(1.5)
indx = random.choice(range(0,len(categories)))
#indx = 1
word_presentation = visual.TextStim(myWin, pos=[0,0],text=wordlist[indx])
if categories[indx] == 1:
print "precious stone"
x = 1
elif categories[indx] == 2:
print "time"
x = 2
elif categories[indx] == 3:
print "relative"
x = 3
elif categories[indx] == 4:
print "unit of distance"
x = 4
elif categories[indx] == 5:
print "metal"
x = 5
elif categories[indx] == 6:
print "reading"
x = 6
elif categories[indx] == 7:
print "military"
x = 7
elif categories[indx] == 8:
print "animal"
x = 8
elif categories[indx] == 9:
print "fabric"
x = 9
elif categories[indx] == 10:
print "colour"
x = 10
else:
print categories[indx]
if x == previous:
print âfoobarâ
categories.extend([x]*nReps)
categories = sorted(categories)
word_presentation.draw()
myWin.flip() #send eeg trigger after this
if x == previous:
y =-1
previous = x
core.wait(.5)
y = event.getKeys(keyList='space', timeStamped=False)
print y
However this is where the problems start to arise. I have found that the indx no longer matches the word list
as the categories array start to get additional numbers added to it. Furthermore I donât think this method will
work as it will continually add more numbers to categories list. After a couple of loops through the for loop the it crashes with the following
error:
word_presentation = visual.TextStim(myWin, pos=[0,0],text=wordlist[indx])
IndexError: list index out of range
So, my problem is:
- How can I increase the probability of a word being drawn from the same category?
- Is there a better way of matching my list of words to their categories?
- I also believe that the âspaceâ key is only being sent after the entire for loop and therefore
may not accurately record when the space key has actually been sent; any ideas on this?
Thank you in advance for any help or ideas!
Mark