Howdy, Stranger!

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

Supported by

Monkey-patching for more flexible randomisation in OpenSesame

edited June 2015 in OpenSesame

Hi,

I'm posting this for two contradictory purposes:

  1. In case anyone finds it useful in the future
  2. In case there is a better way to do this, so I don't do it again!

There is a table (Loop object) where the first 32 rows are experimental trials, and the next 96 are filler. We want to initially run 3 filler trials, then an experimental trial, then 2, 3 or 4 fillers before each remaining experimental trial. So if F represents filler and X experimental trial, the sequence will look something like this:

FFFXFFXFFXFFFFXFFFXFFFFX ....

My idea was to replace the run() method in the relevant Loop item, and use this to randomise the trials as we require. This method is an adapted version of the run() in the original code (module libopensesame.loop). My code to perform the replacement was:

https://gist.github.com/anonymous/66b01a1b3deb0db6dfcc
(I will also copy this code into a reply comment on this post, for posterity)

This was placed in the Prepare phase of an inline code item.

I'd be interested to know what other OpenSesame users (and the developers!) think of this.

Regards,

Alisdair

Comments

  • edited 9:53PM
    # Replace run() for loop object with our own methods
    import random
    import openexp
    import types
    
    # Modified copy of original run() method
    def new_MyLoop_run(self):
        self.set_item_onset()
    
        # generate cycle numbers (custom)
        # come up with an order of IDs from the table
        # First 32 are experiment, rest are filler
        # 2*11, 3*10, 4*10 plus 1*3 at start = 32 filler sequences
        n_filler_seq = [2]*11 + [3]*10 + [4]*10
        random.shuffle(n_filler_seq)
        n_filler_seq = [3] + n_filler_seq
        test_ids = range(0,32)
        filler_ids = range(32,128)
        l = []
        for n_filler in n_filler_seq:
            for _ in range(n_filler):
                l.append(filler_ids.pop(random.randrange(len(filler_ids))))
            l.append(test_ids.pop(random.randrange(len(test_ids))))
    
        # Create a keyboard to flush responses between cycles
        self._keyboard = openexp.keyboard.keyboard(self.experiment)
    
        # Make sure the item to run exists
        if self.item not in self.experiment.items:
            raise osexception( \
                u"Could not find item '%s', which is called by loop item '%s'" \
                % (self.item, self.name))
    
        # And run!
        _item = self.experiment.items[self.item]
        while len(l) > 0:
            cycle = l.pop(0)
            self.apply_cycle(cycle)
            self.experiment.set(u'repeat_cycle', 0)
            _item.prepare()
            _item.run()
    
    test_obj = exp.items["MyLoop"]
    test_obj.run = types.MethodType(new_MyLoop_run, test_obj)
    
Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games