[solved] Inline script and Python code give different results
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
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_scriptitem 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
Check out SigmundAI.eu for our OpenSesame AI assistant!
I am not sure how that can be? The list is there, and there are no repeats in it.
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.
There must be something wrong, but I do not know what.
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).
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_scriptthat is executed before a block of trials, and thenpop()(=select last and remove from list) an item from the list in aninline_scriptthat 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?Check out SigmundAI.eu for our OpenSesame AI assistant!
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
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
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
picListin a random order. First, before the block loop (called Initial_List in your experiment), create a randomly ordered list of pictures, with a simpleinline_script.Then, in a different
inline_scriptat the start of the trial sequence (called sequence in your experiment), retrieve one item frompicList. Thepop()function, which returns the last item from a list and removes it from the list, is convenient here.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
Check out SigmundAI.eu for our OpenSesame AI assistant!
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
script 2
script 3
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
:)