Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Pseudorandomize with constraint: Each stimulus separated by unequal number of fillers

Dear all,

I have a question with setting up pseudorandomization constraint in Opensesame. I have 24 word stimuli and 72 fillers and need to present all items to the participants in the following way: each word stimulus should be separated by filler (fillers). That means no more than one word stimulus appear in succession. However, there is no requirement about how many fillers to appear in succession.

Is this achievable by adding a few scrip in the loop script? I'm quite green in python coding, so I'll be grateful for your help here! Thank you!

Sandra

Comments

  • Hi Sandra,

    Try that here:

    import random
    
    #i'll implement it with letters for times sake
    stimuli = ['S']*24 # 24 Ss as targets
    fillers = ['F']*72 # 72 Fs as fillers
    combined = stimuli + fillers
    random.shuffle(combined) # randomize
    all_stimuli = combined[0] # initialize a list with the first item of the combined list
    
    while len(stimuli) != 0 or len(fillers)!= 0: 
        stim = combined[0]
        if all_stimuli[-1] in stimuli and stim in stimuli:
            random.shuffle(combined)
        else:
             all_stimuli.append(combined.pop(0))
    

    Does that work for you?

    Eduard

    Buy Me A Coffee

  • Hi Eduard,

    Many thanks for providing the script.

    I initiated a new experiment and tried your script independently. But I'm not sure if I did the sketchpad with the right variable name. So which variable should I use when I present the stimuli in the sketchpad: all_stimuli, stim, combined? I tried all of them in the sketchpad, but opensesame warns that the variable "all_stimuli" (or "stim" or "combined") does not exist.

    Here's what I did: I added a new sequence under the new experiment, and under the sequence, I first put an in-line script with the code above and after that comes the sketchpad, on which I cite the [all_stimuli] (or [stim] or [combined]).

    I also tried putting inline scrip before the sequence, but the same error occurred. Did I do it in the right way? Thanks!

    Sandra
    @eduard

  • Hi Sandra,

    First of all,

    So which variable should I use when I present the stimuli in the sketchpad

    all_stimuli, because it has the stimuli in the right order in it. To better understand what the code does, you can also run it line by line

    To be able to use a variable in a sketchpad you have to store it as part of var. So, if you, in the end of the inline_script, do this: var.all_stimuli = all_stimuli you would not get the error message that the variable does not exist.

    However, the variable var.all_stimuli contains all the stimuli you want to show in a block, right? So all targets and fillers. So, when you try to present var.all_stimuli in a sketchpad it will still fail, just because you draw all the stimuli on a single sketchpad. Even though you probably want to draw each stimulus in a separate one, right?

    So, the general procedure is as follows

    1) Create the list of all stimuli (before the block loop)
    2) In the block loop, first pick the current stimulus from the stimulus list in an inline_script (you need to count the current trial number to do so)
    3) present that stimulus in the sketchpad

    I attach a template for an experiment that does so, from there on you can start working, I hope.

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.