import(random)
targets = range(2)
distractors = range(10)
locations = range(4)
for each trial, you can then do:
curTargets = random.sample(targets,1)
curDistractors = random.sample(distractors,3)
now you have a random sample (without replacement) of 1 target and 3 distractors
If you want to distribute them randomly to the locations, shuffle the
locations like so:
random.shuffle(locations)
See Exercises 3 and 4 here:
http://sapir.psych.wisc.edu/wiki/index.php/Psych711
-----------------------------------------------------
Gary Lupyan - lup...@wisc.edu
Assistant Professor of Psychology
University of Wisconsin, Madison
http://sapir.psych.wisc.edu
-----------------------------------------------------
> --
> You received this message because you are subscribed to the Google Groups "psychopy-users" group.
> To post to this group, send email to psychop...@googlegroups.com.
> To unsubscribe from this group, send email to psychopy-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/psychopy-users?hl=en.
>
AAAABBBB is as random as ABBABAAB to the pseudorandom numbers
generator so you might like to QA random sequences regarding
present undesired trial-orders and simply choose the one which is ok for
your purposes. You might also like to look into
http://neuro.debian.net/pkgs/debruijn.html and alike for perfect counter
balancing
Cheers
> > import(random)
> > > Thanks!
--
=------------------------------------------------------------------=
Keep in touch www.onerussian.com
Yaroslav Halchenko www.ohloh.net/accounts/yarikoptic
If all you want to do is generate a display of 4 stimuli, which are always filling the same 4 "slots" on the screen, all you need to do is select 4 stimuli and set their positions appropriately. This can be done with two lists. The function you should be looking into is random.shuffle(). It will shuffle a list in place (which means that you don't create a new, shuffled version of the list, you just literally shuffle the list). For the sake of example, let's assume you have all of your stimuli in a directory called STIMULI and you can safely load them all at the same time:
import os
stimDir = 'path/to/STIMULI'
fileList = [os.path.join(stimDir,file) for file in os.listdir(stimDir)]
stimList = [visual.PatchStim(win=win,tex=file) for file in fileList] # Google "List Comprehension Python" to help understand these two lines
posList = [(400,400),(-400,400),(400,-400),(-400,-400)]
numberOfTrials = 12
for trial in range(numberOfTrials):
random.shuffle(stimList):
pick4stimuli = stimList[0:4]
for stim,pos in zip(pick4stimuli,posList):
stim.setPos(pos)
stim.draw()
win.flip()
To handle including your targets, you could just make a list of targets, pick one on each iteration, and insert it into the list display list in a controlled way:
distDir = 'path/to/STIMULI/DISTRACTORS'
targDir = 'path/to/STIMULI/TARGETS'
distFileList = [os.path.join(distDir,file) for file in os.listdir(distDir)]
targFileList = [os.path.join(targDir,file) for file in os.listdir(targDir)]
distList = [visual.PatchStim(win=win,tex=file) for file in distFileList]
targList = [visual.PatchStim(win=win,tex=file) for file in targFileList]
posList = [(400,400),(-400,400),(400,-400),(-400,-400)]
targPos = range(4) * 3
random.shuffle(targPos)
numberOfTrials = 12
for trial in range(numberOfTrials):
random.shuffle(stimList):
stimToDisplay = distList[0:3]
stimToDisplay.insert(targPos[trial],targList[trial])
for stim,pos in zip(stimToDisplay,posList):
stim.setPos(pos)
stim.draw()
win.flip()
I'm also sticking the second block of code on pastebin, so it's a little easier to read. There might be some things here that don't make sense, but try to work through this code, and feel free to shoot me questions to clarify. Also, I hope there aren't typos, because I didn't test this code...
Chris