Howdy, Stranger!

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

Supported by

[solved] Equal number of trials when randomising

edited December 2013 in OpenSesame

Hi all,

I'm running a simple experiment that requires people to read words off the screen. The aim is to test perception thresholds for different font colours. I have 255 words and 15 different font colours and I want each word to be displayed in a randomly chosen colour. Therefore, for each colour I would like to have 17 words randomly picked from the list.

To do so, I created a block with a list of words (255) that runs a sequence with 15 sketchpads, each using different font colour. Before the sketchpads there is a short script I wrote to create a variable [n] that has value of a random integer (1,15). If [n] = number of sketchpad, the sketchpad gets run.

Unfortunately, this method results in different frequencies of calling each sketchpad, so I'm not getting a nice 17 words per each sketchpad.

I bet there is a better solution to this, but I'm not very fluent with OS.

I would really appreciate your help!

Thanks,

Jarek

Comments

  • edited December 2013

    Hi Jarek,

    To make sure that every sketchpad is ran exactly 17 times, you could use the built-in Python function pop(), which draws one item from a list without replacement. This way, you can keep popping sketchpad numbers until the list is empty (i.e. until every sketchpad is ran 17 times).

    To achieve this, firstly append an inline_script item to the beginning of your block sequence where you define a list containing the sketchpad numbers for all trials in a given block (i.e., seventeen 1's, seventeen 2's, etc., until 15):

    # import the module random:
    import random
    
    # create the list:
    l = range(1,16)*17
    
    # Shuffle the list:
    random.shuffle(l)
    

    Next, change the code in the inline_script in your trial_sequence where you define the value of the variable n:

    # Draw one item from the list:
    n = l.pop()
    
    # Set the variable for future use in the GUI:
    exp.set('n', n)
    

    Does this help?

    Best,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 4:38AM

    Hi Lotje,

    This looks great and works great too, thank you very much!

    Just to make sure I understand what's going on:
    does this little bit

    l = range(1,16)*17

    create 17 lists of 15 elements? If so, in case I would like to run 3 blocks of 255, could I just change it to

    l = range(1,16)*51

    Would this be also correct?

    Best,

    Jarek

  • edited December 2013

    Hi Jarek,

    Good to hear that it works.

    Does this bit (..) create 17 lists of 15 elements?

    No, it creates one list containing 255 items. Seventeen 1's, seventeen 2's, etc.

    Actually, the corresponding piece of code might be easier to understand when it is rewritten to:

    # Create list containing the integer 1 to (but not including) 16:
    # See also:
    #http://docs.python.org/2/library/functions.html#range">http://docs.python.org/2/library/functions.html#range
    l = range(1,16)
    
    # Print the list to the debug window:
    print l
    

    This will return

    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    

    in the debug window.

    # Make the list seventeen times as long, such that every item occurs seventeen times instead of once:
    l  = l * 17
    
    # And again, print the resulting list to the debug window:
    print l
    

    This will return:

    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    

    And

    print len(l)
    

    will print '

    255
    

    i.e. the length of the list.

    As you see, printing information to the debug window can be really helpful when using Python inline coding.

    image

    If so, in case I would like to run 3 blocks of 255, could I just change it to l = range(1,16)*51?

    Yes, that would work. But note that after randomising the resulting list, you will not be sure that every sketchpad occurs equally often within a given block (but only that it occurs equally often across the 3 blocks). That's why I advised to (re)set the list at the beginning of every block sequence (in which case all sketchpads do occur equally often within a given block).

    Does this make sense? Please let us know if you have any further questions.

    Cheers,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 4:38AM

    HI Lotje,

    Yes, that makes perfect sense. In my case I want to have equal numbers across all trials, so I can go for one big list.

    Thanks again for helping me,

    Jarek

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