[solved] Randomly present 2 stimuli from 2 lists
Hello,
I am attempting to build an experiment where I will present two picture stimuli at once side by side (either on a sketchpad or as image buttons) in a random order and on random sides of the screen. One of the stimuli will be a 'real' while the other will be a 'foil'. Participants merely have to select one of the two stim.
Randomizing presentation on different sides of the screen for 'real' and 'foil' should be easily taken care of by a loop's built in randomization function (just divide trials in half for different sides). The real trick is determining how to draw from the file pool a random image that 1) has not been displayed before, and 2) is from a specified sub-pool (i.e., real or foil). Real and foil picture stim are matched, so there is an even amount.
I'm sure this is doable with some python coding, but it appears to be a bit beyond my coding prowess. Any help you can offer directing me in the right direction would be greatly appreciated!
Thanks,
Dan
Comments
Hi Dan,
One way to go about this would be to insert an inline_script item, where you create two lists of all the images (e.g.: real_images = ['image1.png', 'image2.png', 'image2.png'])
Every trial, you'd pick a random item from each list; there's a command that picks one and removes that item from the list as well, so you cannot pick it a second time: real_pick = real_images.pop(0) 'pops' the first element from the list. All you need to do now is shuffle the list before you pop: random.shuffle(real_images). Before you can use this command you need to insert 'import random' at the top of the inline script.
Of course you also need to determine the random side the two pictures will appear on - e.g.: foil_side = random.pick('left', 'right'), and also:
So, you'll end up with a bunch of variables that together contain all the information you need for a trial. Now you just need to make them available outside the inline_script as well (so you can call them e.g. in a sketchpad). you can do this by inserting exp.set('foil_side', foil_side), exp.set('real_pick', real_pick) et cetera.
Let me know how it goes!
Cheers,
Josh
Hi Josh.
Thanks for your reply! I think that this will satisfy my experimental requirements. Two quick follow up questions, as I am still having a bit of trouble getting the experiment to run. First, I replaced
random.pickwithrandom.choice, as the former was not recognized when I attempted to run it.Second, I keep getting the error 'An empty string was passed to experiment.get_file(). Please specify a valid filename" when I attempt to run the experiment. Any ideas as to what may be causing this error? I apologize if it is a simple or easy fix, but I can't seem to shake the error on my own.
I've reproduced my inline_script code and the full experiment code (http://pastebin.com/jan3Py1S) if you want to reference it. Thanks again for helping out!
Hi Josh.
Some follow up: I seem to have figured out my issue with some trial and error. However, it doesn't appear that the images are being removed from the list after they are presented once. I'm thinking that this is an issue of where the inline_script is placed within the experiment. Before I had it outside of the trial loop, but this caused only one image to be shown. Moving it inside the loop allowed for the desired effect, but the images are being repeated now.
A final follow up in case anyone else has the same issue: After a a few hours of fiddling around with the code and the order of the experimental parameters, it appears that you have to make the list in an inline_script outside of your trial loop, then call on the list inside your trial loop (i.e.,
image.pop()). Again, thanks to Josh for helping me work through this!