Howdy, Stranger!

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

Supported by

[solved] Inline script and Python code give different results

edited July 2014 in OpenSesame

Shuffle seem so work differently in OpenSesame inline script than in python.

In python (PyCharm) the following code shuffles the list with no repeats, so that when I slice the list there are no duplicates.

import random

picList = ["achievement.jpg", "admired.jpg", "alert.jpg", "cope.jpg", "energy.jpg", 
"friendships.jpg","good_decision.jpg", "good_news.jpg", "good_times.jpg", "healthy.jpg", 
"hope.jpg", "liked.jpg", "praised.jpg", "problem_solve.jpg", "success.jpg"]


random.shuffle(picList)

list2 = picList[5:]

In my Opensesame the same code gives repeats on the shuffle. Any ideas? What am I doing wrong?

Comments

  • edited 5:23AM

    Hi,

    There's no difference between (the same version of) Python in and outside of OpenSesame. Essentially, OpenSesame itself is simply a Python library, and an inline_script item uses the official Python interpreter to execute its script.

    But, as you say, random.shuffle() doesn't give repeats. Unless, of course, there were repeats in the list to begin with. Could that be it?

    Cheers,
    Sebastiaan

  • edited 5:23AM

    I am not sure how that can be? The list is there, and there are no repeats in it.

  • edited July 2014

    This is the whole code, part of a loop sequence (30 repeats) and followed in the sequence by a sketchpad set to draw "[pic]" , and a logger.

    import random
    
    
    picList = ["achievement.jpg", "admired.jpg", "alert.jpg", "cope.jpg", "energy.jpg", 
    "friendships.jpg","good_decision.jpg", "good_news.jpg", "good_times.jpg", "healthy.jpg", 
    "hope.jpg", "liked.jpg", "praised.jpg", "problem_solve.jpg", "success.jpg"]
    
    
    random.shuffle(picList) #shuffle picList
    
    list2 = picList[5:] #list2 from picList element 5 up (10 items)
    
    
    list3= list2[:5] #list3 from list2, first 5 elements
    
    list4 = list2[5:] #list4 from list2 second five elements
    
    cue = (list3 *5) + list4 #cue list3 repeated 5 times (25 elements) + list 4 (5 elements) 
    
    pic= cue[0]
    
    exp.set("pic", pic)
    

    There must be something wrong, but I do not know what.

  • edited July 2014

    Hoping to get a final cue list of thirty elements 5 x 5 + 5 x1 but getting various results
    seen here. (I have sorted them to make checking easier).

    achievement.jpg
    achievement.jpg
    admired.jpg
    alert.jpg
    cope.jpg
    cope.jpg
    friendships.jpg
    friendships.jpg
    friendships.jpg
    good_decision.jpg
    good_news.jpg
    good_news.jpg
    good_news.jpg
    good_times.jpg
    healthy.jpg
    healthy.jpg
    healthy.jpg
    healthy.jpg
    healthy.jpg
    hope.jpg
    hope.jpg
    hope.jpg
    liked.jpg
    liked.jpg
    praised.jpg
    praised.jpg
    praised.jpg
    praised.jpg
    problem_solve.jpg
    problem_solve.jpg
    
  • edited 5:23AM

    It's difficult to say without seeing the rest of the experiment, but what may be going on here is that you are reshuffling the list on every trial, instead of only shuffling once and then walking through the shuffled one item at a time.

    Basically, if you reshuffle your list in a separate inline_script that is executed before a block of trials, and then pop() (=select last and remove from list) an item from the list in an inline_script that is part of the trial, you will not encounter any repeats. However, if you reshuffle the list also on every trial, you will sometimes get repeats. And this appears to be what you're doing, because you're reshuffling and selecting in the same script, which I assume is executed on every trial. Does that make sense?

  • edited 5:23AM

    I am sure you are right Sebastiaan, but I am not sure how to correct it. I have provided a link to the experiment, I would be so grateful if you could take a look and confirm your theory.

    I will keep trying to figure it out.

    https://www.dropbox.com/s/xjttoewxkush7eb/mentalsimulation.opensesame.tar.gz

  • edited 5:23AM

    this is a cut down version with just the loop :), that I use to test

    https://www.dropbox.com/s/nql4yubsek0p7eo/mentalsimulation2.opensesame.tar.gz

  • edited 5:23AM

    Hi,

    Yes, so it's basically what I suspected: You're creating a new shuffled list on every trial, instead of once at the start of the block.

    Let's just focus on the simple case, in which you want to loop through picList in a random order. First, before the block loop (called Initial_List in your experiment), create a randomly ordered list of pictures, with a simple inline_script.

    import random
    # Create a list of pictures ...
    picList = ["achievement.jpg", "admired.jpg", "alert.jpg", "cope.jpg",
        "energy.jpg", "friendships.jpg","good_decision.jpg", "good_news.jpg",
        "good_times.jpg", "healthy.jpg", "hope.jpg", "liked.jpg", "praised.jpg",
        "problem_solve.jpg", "success.jpg"]
    # ... and shuffle the order
    random.shuffle(picList)
    

    Then, in a different inline_script at the start of the trial sequence (called sequence in your experiment), retrieve one item from picList. The pop() function, which returns the last item from a list and removes it from the list, is convenient here.

    # Take the last picture from the list ...
    pic = picList.pop()
    # .. and set it as the experiment variable `pic`.
    exp.set("pic", pic)
    

    So that's basically it. It appears that you have something more complicated in mind, because you are using multiple lists that contain different slices of the picList. But this at least shows how you can avoid reshuffling your list again on every trial.

    Cheers!
    Sebastiaan

  • edited July 2014

    Thank you so much, and sorry for being a pain. You have put me on the right track. and now I have been able to sort it. The practice run and the main run need 3 scripts each, two before the loop and one during the sequence

    script 1

    import random
    
    
    picList = ["achievement.jpg", "admired.jpg", "alert.jpg", "cope.jpg", "energy.jpg", 
    "friendships.jpg","good_decision.jpg", "good_news.jpg", "good_times.jpg", "healthy.jpg", 
    "hope.jpg", "liked.jpg", "praised.jpg", "problem_solve.jpg", "success.jpg"]
    
    
    random.shuffle(picList)
    

    script 2

    list2 = picList[5:]
    
    
    list3= list2[:5]
    
    list4 = list2[5:]
    
    cue = (list3 *5) + list4
    
    picList = cue
    
    random.shuffle(picList)
    

    script 3

    pic = picList.pop()
    
    exp.set("pic", pic)
    

    The scripts need to be named differently and have different variable names for the practice run, because the list was much shorter (5 images).

    Thank you once again :):)

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