Howdy, Stranger!

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

Supported by

Equal frequency of sequences of block items

Hi, I hope this is the right forum.

I am new to Opensesame (and Python in general), so maybe there already exists a solution for my problem: I have one column for the direction of a triangle (up and down) and I need to get a sequence where, on the one hand the list is randomized, but on the other hand repetition and switching of these items should occur with equal frequency, such that up -> up; down -> down; up -> down and down -> up occur equally often. Would this be implementable?

Thanks in advance

Tobi

Comments

  • Hi Tobi,

    Yes, that is possible, but requires direct Python coding and is quite tricky to efficiently and robustly script. Something like this could work:

    import random
    n_trials = 21
    n_transitions = 20
    n_stim = 2
    n_transtypes = 4
    
    
    while True:
      stim1_trans = ['rep','swi']*(n_transitions/4)
      stim2_trans = ['rep','swi']*(n_transitions/4)
      random.shuffle(stim1_trans)
      random.shuffle(stim2_trans)
      trans_list = [stim1_trans,stim2_trans]
      try:
        seq = [random.choice([0,1])]
        for i in range(n_transitions):
            prev = seq[-1]
            cur = trans_list[prev].pop()
            if cur == 'rep':
                seq.append(prev)
            else:
                seq.append(prev^1)
      except:
          continue
      else:
         break
    

    Only problem is that the code is not robust enough to produce a sequence that has the certain length without crashing. Therefore, I wrapped it into a while loop to keep on running until it happened to work. That is of course a weird and slightly ugly solution, but does produce valid sequences (I think).

    Good luck,

    Eduard

Sign In or Register to comment.