<sidebar>Psych711</sidebar> The first part of this exercise is inspired by a starting-small story as told in the Think Python book: Linux is an operating system that contains thousands of lines of code, but it started out as a simple program Linus Torvalds used to explore the Intel 80386 chip. According to Larry Greenfield, “One of Linus’s earlier projects was a program that would switch between printing AAAA and BBBB. This later evolved to Linux.” (The Linux Users’ Guide Beta Version 1).
- Write a function called repetition which takes three arguments: letters (a list), numberBeforeSwitch (an integer), and numRepetitions (also an integer). The function should produce a sequences of letters, one per line, such that calls to repetition with various parameters, generate the following outputs. (Note: There are built in functions that can do this. Please do not use them for the exercise).
>>> repetition(['A','B'],1,1) A B
>>> repetition(['A','B'],2,1) A A B B
>>> repetition(['A','B'],2,2) A A B B A A B B
>>> repetition(['A','B','C'],3,1) A A A B B B C C C
The base code (see repetition.py) is just this:
def repetition(letters,numberBeforeSwitch,numRepetitions): pass
Remember, your function should print one letter per line.
2. Generating a simple trial list: Ok, now for something more useful. Suppose we are interested in finding out the efficacy of a particular kind of masking technique and want to examine if it's more effective in the left vs. right visual field. We are going to display an image on either the left or the right side of the screen and measure people's ability to tell which side the image is on on masked vs. nonmasked trials. To do this, we need to generate a list of trials in which some proportion is masked and some is not masked, and within each condition, the image is on the left some proportion of the time, and on the right the remaining times. Your code should generate the trials for this experiment. There should be 2/3 masked trials and 1/3 non-masked trials. Within each masking type half of the targets should be on the left and half on the right. The code you write should output to the terminal output that looks just like this (that first number is the block number).
$ python generateTrials_base.py 1,masked,right 1,masked,left 1,masked,right 1,masked,left 1,nonmasked,right 1,nonmasked,left 2,masked,right 2,masked,left 2,masked,right 2,masked,left 2,nonmasked,right 2,nonmasked,left 3,masked,right 3,masked,left 3,masked,right 3,masked,left 3,nonmasked,right 3,nonmasked,left 4,masked,right 4,masked,left 4,masked,right 4,masked,left 4,nonmasked,right 4,nonmasked,left 5,masked,right 5,masked,left 5,masked,right 5,masked,left 5,nonmasked,right 5,nonmasked,left
Now, check this out:
python generateTrials.py > trialList.txt
Open up the trialList.txt file and have a look.
3. The trial list above has the trial structure you want, but obviously you wouldn't want to show someone trials in this order because it's completely predictable. It's a good idea to have your generateTrials routine do all the randomization ahead of time such that trialList.txt contains the exact trial order that will be seen by a participant. There are two reasons. First, this lets you modularize all the trial handling outside of your main experiment script. Second, it allows you to save individual trial files that show the trial order seen by a given participant. It comes in handy for making sure your trial list is set up as you want it. So: let's go ahead and randomize the trial list before printing.
4. Simply randomizing the list messes up the block structure, so let's randomize the trials *within* each block before printing.
5. Double the number of trials in each block (so that the repetitions are not quite so predictable), and then randomize within each block as in part 4.