Howdy, Stranger!

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

Supported by

shuffle related rows

Hi,
I'm very new on Opensesame and therefore I might have a problem that is very easy to solve. But somehow I could not find a solution yet, so maybe someone could help me with this.
I need to randomize some items in a column, so every subject gets another sequence of items. The problem I have is, that this item should always be presented with another item.
I have a screenshot of the loop table:

I want to randomize the CS_closed, so that CS_closed for every subject is presented with another US_rating (US_rating consists of different images). CS_closed 1 (here: CS_Kanji1.bmp) should always be presented with the same US_rating for the respective subject. Plus, US_rating cannot be randomized because it is depending on the column valence and correct_response. I hope you can understand what I mean. Thanks!

Caro

Comments

  • Edit: You can see that I tried to do it blockwise, but I need a full randomization, so this is not what I was looking for.

  • Edit: Also tried it with coding:


    But unfortunately Python always crashes.

  • Hello,

    So if I understood you want to random one column while keeping the other constant?
    If so a stategy could be:

    • first you enter your initial matrix in a loop at the very beginning of your scrip (just to load it);
    • then you extract these values, just random the first column in a new datamatrix, then copy this new randomized datamatrix in the subsequant loop.

    Like this:

    With the inline for randomizing and preparing the subsequant loop as:

    from datamatrix import DataMatrix
    import random
    
    # create a list to stock the element from the column of the datamatrix (ie Load_Item_Loop)
    # to randomize
    
    list_column1_to_randomize = list()
    
    # fill this list
    for row in items['Load_Item_Loop'].dm.column1_name:
        list_column1_to_randomize.append(row)
    
    # randomize the list
    random.shuffle(list_column1_to_randomize)
    
    # then create a new datamatrix that will be used for the subsequent loop where
    # column1_name is randomized but the other column not randomized
    # create the new datamatrix
    
    new_dm = DataMatrix(length=len(list_column1_to_randomize))
    # fill the first column with the randomized list
    new_dm.column1_name = list_column1_to_randomize
    # initialize and fill the two other columns
    new_dm.column2_name = ''
    new_dm.column3_name = ''
    
    for i, row in enumerate(new_dm.column2_name):
        new_dm.column2_name[i] = items['Load_Item_Loop'].dm.column2_name[i]
        new_dm.column3_name[i] = items['Load_Item_Loop'].dm.column3_name[i]
    
    # now copy the new_dm in new_loop (it will become the new values of this loop)
    items['new_loop'].dm = new_dm
    

    Find the script too maybe it will be more explicit.
    Just be sure you change the two loop as sequential (I do not think it matters a lot but up to you)

    Best,

    Sylvain

  • Hello Sylvain,

    thank you for replying. I started the experiment you added and the first column is randomized, that's exactly what I want! But column 2 and 3 are presented sequentially (even if I change 'order' to 'random'). This should not be the case. Plus, the biggest problem I have is that the items in column 1 are presented two times, so they should be randomized but like this:
    column 1, row 1 to 8 is randomized (e.g. 6, 4, 7, 3, 2, 1, 8, 5) and this order is attached to the items in column 2. Row 9 to 16 in column 1 and 2 should contain the same pairing as row 1 to 8. Does this make any sense? ':D

    Caro

  • And maybe you could tell me what is wrong with the code mentioned above? Because I do not understand why Python always crashes.

  • I do not really know why it crashes otherwise if I understood what you want you could try that:

    from datamatrix import DataMatrix, operations
    import random
    
    # create a list to stock the element from the column of the datamatrix (ie Load_Item_Loop)
    # to randomize
    
    list_column1_to_randomize = list()
    
    # fill this list
    for row in items['Load_Item_Loop'].dm.column1_name:
        list_column1_to_randomize.append(row)
    
    # randomize the list
    random.shuffle(list_column1_to_randomize)
    
    # then create a new datamatrix that will be used for the subsequent loop where
    # column1_name is randomized but the other column not randomized
    # create the new datamatrix
    
    new_dm = DataMatrix(length=len(list_column1_to_randomize))
    # fill the first column with the randomized list
    new_dm.column1_name = list_column1_to_randomize
    # initialize and fill the two other columns
    new_dm.column2_name = ''
    new_dm.column3_name = ''
    
    for i, row in enumerate(new_dm.column2_name):
        new_dm.column2_name[i] = items['Load_Item_Loop'].dm.column2_name[i]
        new_dm.column3_name[i] = items['Load_Item_Loop'].dm.column3_name[i]
    
    print(new_dm)
    
    # now shuffle everything but keep row associated
    
    final_dm = operations.shuffle(new_dm)
    
    # repeat it n times and concatenate
    
    repeat = 1
    for r in range(repeat):
        dm_repeat = operations.shuffle(new_dm)
        final_dm = final_dm << dm_repeat
    
    
    
    print(final_dm)
    
    
    # now copy the new_dm in new_loop (it will become the new values of this loop)
    items['new_loop'].dm = final_dm
    
    

    Datamatrix function are on this page:
    http://datamatrix.cogsci.nl/

    And find the modified script.

    Hope it will work this time.

  • Hello Sylvain,

    wow, thanks alot! This looks like it could be a very nice solution for my problem. So far I got it going by this code:

    But I think your code looks much nicer and as if it could be used in a more general way. I will try it this way as well Thank you so much for your time and this nice piece of code!

    Caro

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