Randomizing image transitions with varying time inbetween

Hi,

I am currently building my first experiment and am in need of some help.
My idea is to present one of two stimuli1 (randomly) in the very beginning. This is followed by fixation cross with varying duration. Afterwards, participants will be presented another one of two stimuli2. Here, I would like to specify the transition probabilities. That is, Stimuli1.1 is followed by Stimuli 2.1 in 80% of the cases and followed by Stimuli 2.2 in 20% of the cases. Likewise, stimuli 1.2. is followed by Stimuli 2.1 in 20% of the cases and by Stimuli2.2 in 2.1 in 80% of the cases.
I would like there to be an equal distribution of the randomly occurring stimuli-couplings.
I have tried to work with files containing the images and using custom code to read in the images and specify p as the transition probability. Nothing seems to work. At this point, it would be great to get some guidance on how I should set this up and where I should specify the probabilities, randomization.

Many thanks

You said you tried custom code but it didn’t work. Please could you show what you tried?

Something like

if random() > .5:
     T1 = 1
else:
     T1 = 2
If random() >.8:
     T2 = 1
else:
     T2 = 2

Hi,

Of course, this is what I tried most recently:

p_14to1 = 0.8
p_14to2 = 1.0 - p_14to1 

p_15to1 = 0.2
p_15to2 = 1.0 - p_15to1

p = random()

if startle == "startles/pattern_14.png":
    if p < p_14to1:
        stimuli = "stimuli/stim1.png"
    else:
        stimuli = "stimuli/stim2.png"
elif startle == "startles/pattern_15.png":
    if p < p_15to1:
        stimuli = "stimuli/stim1.png"
    else:
        stimuli = "stimuli/stim2.png"

Wheras, the patterns are the startle stimuli and stimuli are the target stimuli following a specific startle.

That looks fine. How is startle set?

In what way is that code not working?

This is what my flow looks like. For the startles and stimuli I have an Excel file each, which I uploaded in in the loop. For the startles I defined the rows as $np.random.choice(2, size = 1, replace = False) and for the stimuli trials I have code (the one above) before the image in the “begin routine” column. The experiment doesn’t crash but sometimes I am shown both stimuli following one startle and other times only one.

I just now changed the probabilities to 1 and 0 and this seems to work.

_14to1 = 0
p_14to2 = 1.0 - p_14to1 

p_15to1 = 1.0
p_15to2 = 1.0 - p_15to1

p = random()

if startles == "startles/pattern_14.png":
    if p < p_14to1:
        stimuli = "stimuli/stim1.png"
    else:
        stimuli = "stimuli/stim2.png"
elif startles == "startles/pattern_15.png":
    if p < p_15to1:
        stimuli = "stimuli/stim1.png"
    else:
        stimuli = "stimuli/stim2.png"

but if I change it back to

p_14to1 = 0.8
p_14to2 = 1.0 - p_14to1 

p_15to1 = 0.2
p_15to2 = 1.0 - p_15to1

p = random()

if startles == "startles/pattern_14.png":
    if p < p_14to1:
        stimuli = "stimuli/stim1.png"
    else:
        stimuli = "stimuli/stim2.png"
elif startles == "startles/pattern_15.png":
    if p < p_15to1:
        stimuli = "stimuli/stim1.png"
    else:
        stimuli = "stimuli/stim2.png"

I get two stimuli in a row (following only one startle) again.