Hi guys,
I am programming a learning experiment in which children need to learn like ‘a new alphabet’.
In every trial they hear a sound and see two new symbols (left or right on the screen). Then they have to indicate which symbol they think that corresponds to the sound they heard.
The first block consists of 4 different sounds they need to learn (so also 4 symbols that corresponds to a sound). This means that every sound can be combined with its corresponding symbol or 3 other incorrect symbols, which means that there are 12 different alternatives (4 sounds with itself ánd 3 incorrect symbols, as we present 2 symbols each trial).
I want to have 72 trials in the first block, which means that each sound will be repeated 18 times. For now I used a code with a while loop (while next stimulus is same as current, randomize symbol_order) which shuffles the sounds as long as two consecutive sounds are the same. This works great when using less trials, but takes soooo long for randomizing 72 (didn’t even come to the point where it found a good order and I waited for already 10 minutes so not an option).
Which alternatives can you suggest?
maybe important to know, each sound corresponds to the 2 symbols, so these rows need to be randomized together (that’s why I used symbol_order):
[code below]
if block == 0:
num_items = 72
stimuluslist1 = {'setA/A1.wav': 'setA/A1.png', 'setA/A2.wav':'setA/A2.png', 'setA/A3.wav':'setA/A3.png','setA/A4.wav':'setA/A4.png'}
#input file
in_file = 'block1.xlsx'
inbook = xlrd.open_workbook(in_file)
insheet = inbook.sheet_by_index(0)
sound = []
symbol1 = []
symbol2 = []
#loop through rows in stimulus file
for rowx in range(1, num_items+1):
row = insheet.row_values(rowx)
sound.append(row[0])
symbol1.append(row[1])
symbol2.append(row[2])
#print(sound)
#print(symbol1)
#print(symbol2)
#randomize symbols
for rowx in range(0, num_items):
if random.random() > .5:
TEMP_B = symbol2[rowx]
symbol2[rowx] = symbol1[rowx]
symbol1[rowx] = TEMP_B
#print(symbol1)
#print(symbol2)
#create order list
symbol_order = []
for i in range(num_items):
symbol_order.append(i)
#randomly shuffle sound_order
random.shuffle(symbol_order)
print(symbol_order)
double_stim = False
list_ok = False
while list_ok == False:
for i in range(len(symbol_order)-1):
#check for consecutive stimuli
if sound[symbol_order[i]] == sound[symbol_order[i+1]]:
double_stim = True
break
if double_stim == True:
random.shuffle(symbol_order) #try new order
double_stim = False
else:
list_ok = True
#arrays for final stimuli
sound_list = []
symbol1_list = []
symbol2_list = []
#create final lists
for i in range(num_items):
sound_list.append(sound[symbol_order[i]])
symbol1_list.append(symbol1[symbol_order[i]])
symbol2_list.append(symbol2[symbol_order[i]])
#print(sound_list)
#print(symbol1_list)
#print(symbol2_list)
corr_ans = []
#set correct answer
for i in range(num_items):
if symbol1_list[i] == stimuluslist1[sound_list[i]]:
corr_ans.append('left')
else:
corr_ans.append('right')
#print(corr_ans)