Howdy, Stranger!

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

Supported by

[solved] Randomize variable lists

edited October 2014 in OpenSesame

Hi Sebastiaan,
I think I found an answer to my question here (http://www.cogsci.nl/forum/index.php?p=/discussion/389/open-random-order-to-variables-without-returning/p1) but I don't fully understand it.

In my experiment, I try to use a single question:
"If you have [P] probability to win [A] of money...."
where [P] and [A] are two variables in the loop. The former is a list of 45 probabilities, the latter is a list of 45 amounts of money.
If I run the experiment, the first probability is associated with the first amount the second P with the second A and so on.

I have to build an experiment in which there are 45 items with a randomized [P] order for every subject and random ordered [A] not repeated and not in fixed pairs with [P].

I hope to have explained properly my question.

Comments

  • edited 11:46PM

    Hi Andrea,

    Unfortunately, like it was said in the thread you cited, you need to do some scripting in order to design your experiment in the way you want it. However, it is not very hard, so no need to worry. Here you can find the basic structure of how you can solve your problem. I will explain it briefly:

    1. In the first inline_script, called "define_Amount", you have to create the list of the 45 options of how much money each subject can get per trial. You want it to be randomized, so you have to shuffle the list.
    import random
    
    exp.amount_list = [1,2,3,4....45] # or whatever it is in your case
    random.shuffle(exp.amount_list)
    
    1. After having created that list, you can enter the trial loop. Here, you have to add your other variable (i.e. probability) with each of the 45 levels included (just like that ). If you do it this way, the sequence, which is repeated in the loop takes exactly one of the probabilities as "P" variable for a trial. As you might have noticed, at this point the sequencedoesn't "know" yet what the other variable (amount) is, because it isn't included in the variable assistant. So, this is what we have to do in step 3.

    2. In the inline_script "set_amount_as_variable", you have to set the value of the 2nd variable.

    exp.set('amount', exp.amount_list.pop())
    

    That's it. Now the sequence has one value for the probability and one for the amount. Each value is used exactly once and also in a random order for each participant. From this point, you can use them, in the way you described (" If [prob] equals [amount], ...").

    Two small remarks:

    1) Obviously, it doesn't matter which of your variables you define in the variable assistant and which you define yourself. It is totally up to you.

    2) When you define one variable yourself in the very first inline_script, you shouldn't forget to put "exp." in front of the variable name, because if you don't, you won't be able to access it outside this inline_script. By adding "exp." you make it part of your experiment and hence, accessible at any point of it.

    Do you understand now better?

    Eduard

    Buy Me A Coffee

  • edited October 2014

    Thanks for your help,
    when I try to begin an exp the software says:
    "Variable 'amount' is not set in item 'rest_of_trial'.
    You are trying to use a variable that does not exist. Make sure that you have spelled and capitalized the variable name correctly. You may wish to use the variable inspector (Control + I) to find the intended variable."

    When I open variable inspector and I search for amount's variable I find:
    "amount" in variable column
    [Set to 'exp.amount_list.pop('] in the second column.

    I put the script you post under the "run" label, is it correct?
    Will it work if I change:

    • numeric with character;

    • labels "amount" with "D";

    in this way:

    first inline_script:

    import random

    exp.D_list = ["1","2","3","4","5"] # or whatever it is in your case
    random.shuffle(exp.D_list)

    and the second inline_script:

    exp.set('D', exp.D_list.pop())

  • edited 11:46PM

    Hi Andrea,

    when I try to begin an exp the software says: "Variable 'amount' is not set in item 'rest_of_trial'.

    You defined your variable as part of the experiment, that is, if you want to access the variable, you have to tell Opensesame that it has to look for it in the experiment. The way this works is either by using brackets, [amount], or like this: exp.amount.

    Will it work if I change:

    numeric with character;

    labels "amount" with "D";

    Sure, the way you label your variables is pretty much your own decision.

    Eduard

    Buy Me A Coffee

  • edited October 2014

    Hi eduard,
    with the first inline I create the list:

    import random

    exp.amount_list = [1,2,3,4....45] # or whatever it is in your case

    random.shuffle(exp.amount_list);

    in the second inline I include the variable in the variable assistant:

    exp.set('amount', exp.amount_list.pop())

    and so when in the slider's question I write " If you have [prob] of win [amount]..." it should work or I forget to do something?

  • edited 11:46PM

    Exactly, that sums it up very well. I don't see a reason why it shouldn't work now, but why don't you just try it out?

    Eduard

    Buy Me A Coffee

  • edited 11:46PM

    I have tried it but the variable amount hasn't been identified in the slider

  • edited 11:46PM

    Does it work if you use "exp.amount" instead of [amount] ?

    Buy Me A Coffee

  • edited 11:46PM

    Nothing the software doesn't recall the list and put in the questions exactly the words "exp.amount"

    I try to move the inline script from run label to prepare label and the first windows works but when I click to accept answer it says:

    Error while executing inline script phase: prepare
    item: set_Amount_as_Variable
    line: 2
    exception message: 'int' object has no attribute 'pop'
    exception type: AttributeError

    Traceback (also in debug window):
    File "dist\libopensesame\inline_script.py", line 133, in prepare
    File "", line 2, in
    AttributeError: 'int' object has no attribute 'pop'

  • edited 11:46PM

    The error tells you that the element you're popping from is not a list, but an integer.
    So something went wrong there. Did you make sure, that you create a list in define_amount? Maybe you can post the code you used.

    Btw. you're right, you have to set the amount for the trial in the prepare phase of the inline_script.

    Buy Me A Coffee

  • edited 11:46PM

    I thought that amount_list was only the variable name and so I change it to "M" now I have changed it to "M_list" and the experiment work.
    Thanks for your help.

  • edited 11:46PM

    Nice!

    Good luck with it.

    Eduard

    Buy Me A Coffee

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