Howdy, Stranger!

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

Supported by

[solved] pseudo-randomisation

edited October 2015 in OpenSesame

Hi everyone,

I am a novice in using OpenSesame and python. I would like to be able to program a pseudo randomisation of my durations.

In my protocol, I have 2 variables:

1/ Facial expression: neutral, sad, happy, angry, fear

2/ Duration: 400 ms, 600ms, 800ms, 1000ms ,1200ms, 1400ms ,1600ms

For a trial, I show a facial expression (e.g sad) for a certain duration ( e.g 400ms).

In my experience I have 35 combinations = 5 (facial expression) x 7 durations
For each combination I must have 8 trials

However, it is necessary that in the first seven trials I show all my durations.
The same thing for trial 8 at 14, trial 15 at 21 etc……

image

Could you, please, help me?

Thank you very much! Agnès

Comments

  • edited 10:35AM

    Hi Agnès,

    Normally you would have a loop item running a (trial-)sequence item, with all conditions appearing at random, meaning you'd have no guarantee of having all durations appear every 7 trials. To take control over this, you could place another loop item within your loop item item, and make sure the trial sequence is contained by the second loop item rather than the first one. (So in total you'd have a loop containing a loop containing a sequence).
    Next: in the second loop item, you create the variable duration, and let it have 7 cycles containing the values 400 to 1600. Each cycle should be run 1 time. If I'm correct, all durations occur 40 times (8 times with each of the 5 faces). So the first loop should run the second loop 40 times.
    We now need to make sure that all duration/face combinations occur evenly. To do that, you need 7 lists, that each contain each emotion 8 times. Place an inline_script at the top of your experiment, and create 7 lists by means of

      dur_400 = []
      dur_600 = []
      dur_800 = []      # et cetera.
    

    Then you want to add emotions to them. Either you could insert the 40 emotions to each list by means of adding them manually (e.g. change [] into ['sad','sad'...], or by creating a for loop:

      emotions = ['sad','happy','angry','afraid','neutral']
    
      for i in range(0,8):
            for j in range(0,5):
                   dur_400.append(emotions[j])
                   dur_600.append(emotions[j])
                   dur_800.append(emotions[j])  # et cetera.
    

    You then want to give these lists a shuffle:

      import random
      random.shuffle(dur_400)   # as well as the other lists
    

    Finally, in the (trial-)sequence item you can insert another inline_script, and here we will create the variable that sets the emotion for that specific trial:

      duration = exp.get('duration')
      if duration == 400:
            emotion = dur_400.pop(0)  # takes first element from list.
      elif duration == 600:
            emotion = dur_600.pop(0)  # and so forth.
    

    If you're using a sketchpad in the sequence to display your stimuli, make sure you 'set' the emotion variable so it becomes available outside of the inline script:

      exp.set('emotion', emotion)
    

    In the sketchpad, the duration can be set to [duration], and the image will be [emotion].jpg (of course that is if you actually named your pictures happy.jpg and such).

    Good luck!

    Josh

  • edited 10:35AM

    Solved problem
    Thanks a lot for the solution

    Agnès

Sign In or Register to comment.