[solved] Randomizing conditions and trials using Python code
Please help me figure out why my randomization script fails. The experiment consists of 3 blocks and each block includes 5 conditions with 12 files in each. I randomize blocks and conditions through open-sesame loop function, and I tried to randomize the files through Python script. It does all the randomization, but it only picks the first file from the list instead of going in order until it exhausts the list and switches to the next block. Please look over the script and tell me how I can patch this up.
Thanks!
This script is inserted at the first sequence with some commentary:
import random
global Conditions
global Blocks
Conditions is a dictionary in which the key is the specific condition and the values are the specifi stimuli pairs used in each trial
Conditions = {
'Far_Large_No': ['10-30', '10-40', '20-40', '20-50', '30-10', '30-50', '30-60', '40-10', '40-20', '40-60', '40-70', '50-20'],
'Far_Small_No' : ['1-3', '1-4', '2-4', '2-5', '3-1', '3-5', '3-6', '4-1', '4-2', '4-6', '4-7', '5-2'],
'Close_Small_No' : ['1-2', '2-1', '2-3', '3-2', '3-4', '4-3', '4-5', '5-4', '5-6', '6-5', '6-7', '7-6'],
'Close_Large_No' :['10-20', '20-10', '20-30', '30-20', '30-40', '40-30', '40-50', '50-40', '50-60', '60-50', '60-70', '70-60'],
'Same_Same_Yes': ['1-1', '2-2', '3-3', '4-4', '5-5', '6-6', '7-7', '8-8', '10-10', '20-20', '30-30', '40-40', '50-50', '60-60', '70-70', '80-80']}
Blocks = ['Numbers', 'Dots', 'Mixed']
shuffle the pairs so they will be randomized during experiment
for cond in Conditions:
random.shuffle(Conditions[cond])
This script is inserted at the trials loop which randomizes conditions and holds the trial sequence:
import string
global Conditions
global Blocks
global Stim
global theTrue
global cond
get information from the variables in the trial loop that indicate what type of trial comes next
print 'conditions', Conditions
distance = self.get('Distance')
size = self.get('Size')
block = self.get('Blocks')
catch = self.get('Catch')
print 'catch', catch
make a string that matches the filenames and store that name in Stim
cond = distance + '_' + size + '_' + catch
ctr1 = 0
ctr2 = 0
ctr3 = 0
ctr4 = 0
ctr5 = 0
Stim = ''
if cond == 'Far_Large_No':
Stim = Conditions[cond][ctr1];
val = Conditions[cond][ctr1];
ctr1 = ctr1 + 1
if cond == 'Far_Small_No':
Stim = Conditions[cond][ctr2]
val = Conditions[cond][ctr2]
ctr2 = ctr2 + 1
if cond == 'Close_Large_No':
Stim = Conditions[cond][ctr3]
val = Conditions[cond][ctr3]
ctr3 = ctr3 + 1
if cond == 'Close_Small_No':
Stim = Conditions[cond][ctr4]
val = Conditions[cond][ctr4]
ctr4 = ctr1 + 1
if cond == 'Same_Same_Yes':
Stim = Conditions[cond][ctr5]
val = Conditions[cond][ctr5]
ctr5 = ctr5 + 1
Stim = block + '_' + cond + '_' + Stim
self.experiment.set('Stim', Stim)
print 'Stim', Stim
In the stimulus sketchpad set the inset image as '[Stim].png'
separate the values of the two numbers presented to decide what is the correct response
ind = val.find('-')
number1 = val[0:ind]
number2 = val[ind+1:]
number1 = int(number1)
number2 = int(number2)
if number1 > number2:
theTrue = 'q'
elif number1 < number2:
theTrue = 'p'
else:
theTrue = 'space'
self.experiment.set('theTrue', theTrue)
Comments
Hi SillyNapalm,
Could it be that you set the ctr[X] variables back to 0 at every trial? As I understand it, you want those to increment, right? So you might want to move the part where you set the ctr[X] variables to 0 to some place at the start of a block/ experiment (where exactly depends on what you want to do, of course).
Hope this helps!
Regards,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!