Howdy, Stranger!

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

Supported by

Reset variable for adaptive procedure

Good Evening,

I'm still quite new to Python (and programming in general) and trying to code a working-memory task (word span sequences) with an adaptive number of items to be remembered, depending on the performance in the trial before; however it is only adapted every two trials. In total there are 10 trials. I have a set of 9 words, from which randomly a number "n" is drawn.
So let's say I start with 3 words in a sequence and get two trials right, the number of words for the next two trials should increase to 4. If I get these next two wrong, the number should reduce to 3 again. If I get one correct and one wrong, the number of words per sequence should remain the same.
The words are to be presented one by one acoustically (with a ISI of 1500ms), and at the end the whole sequence is presented to the person administering the test. That person scores with "1" or "0" whether the response was correct or not (i.e. whether the sequence was reproduced correctly)

So I created a loop that contains 10 trials in sequential order and a "reset" variable that is alternatingly "0" and "1". The loop calls a sequence that contains two inline scripts. The first is for resetting my "adapt"-variable to 0, the second contains the actual trial.

So far so good, but the adaptive procedure "every other trial" does not seem be stable, Python produces quite frequent crashes, mostly after 5-7 trials. Most of the time the window just freezes and has to be shut down manually.

I assume that my coding is erroneous or contains pitfalls that I naively don't see ;)
I begin with evaluating whether the "adapt"-variable is +2 or -2 (from the previous two trials) and accordingly adjusting "n" (passed to function random.sample)

if adapt == -2:
    var.n = var.n - 1
elif adapt == 2: 
    var.n = var.n + 1

After the presentation of the sequence, I collect the keyboard response (0 or 1), adjusting "adapt" accordingly

if var.correct == 1:
    adapt = adapt + 1
else:
    adapt = adapt - 1

After every other trial, the "adapt" variable should be reset to zero, so that it only reflects two trials. I had to insert an extra inline script because within the actual trial-script it would not work at all. This way works sometimes, however not very stable. It seems to work when I omit the "adapt" procedure every two items and change the number of words per sequence after every trial:

if var.correct == 0:
    var.n = var.n - 1
elif var.correct == 1: 
    var.n = var.n + 1

I also get a

UserWarning: var name is stored as attribute of item experiment % (var, self.item.name))

which I found in another post (http://forum.cogsci.nl/index.php?p=/discussion/2616/random-crashes-on-droid-back-end-possibly-connected-to-var-store-warning), but appearantly it is not related to the issue? (although however, the phenomenon seems quite similar). In the other post it was suggested that memory may be an issue, however I'm running OS on a regular windows Laptop and am not using large files.

So do you have any ideas how I could solve this; maybe a completely different and more reasonable approach?
It will be very much appreciated :)

Cheers,
Gunnar

Comments

  • Hi Gunnar,

    Although you've provided a quite extensive description of the problem (which is always good and appreciated), it's still difficult to see what might be wrong without some more context. It would help if you post the exact error message that you get when the experiment crashes. Attaching the experiment to this discussion would also help.

    Cheers!
    Sebastiaan

  • Hi Sebastiaan,

    thanks for your answer. Please find attached the experiment.
    After a few items the experiment usually freezes after the keyboard response, so I have to shut down the experimental window "by force". After that the error message simply says that Python crashed. Besides there is a warning about non-integer numbers (which however also shows up when the experiment mysterically finishes without problem ;) ). Sometimes it suddenly shuts down after the last item was presented but also with the only error message "Python crashed".

    C:\Program Files (x86)\OpenSesame\lib\site-packages\numpy\core\numeric.py:190: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
    a = empty(shape, dtype, order)
    C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\var_store.py:236: UserWarning: var name is stored as attribute of item experiment
    % (var, self.item.name))

    Python seems to have crashed. This should not happen. If Python crashes often, please report it on the OpenSesame forum.

    I've been using Expyriment backend, but also Legacy didn't make any difference.
    Thanks again! :)
    Gunnar

  • Hi Gunnar,

    The freezing (which probably results in the Python interpreter crashing) is due to a simple logical bug in your code, leading to an infinite loop. Can you spot the issue here?

    var.sequence = random.sample(echt_kurz, var.n)
    if var.count_sequence > 0:
        while var.sequence[0] == firstitem:
            random.sample(echt_kurz, var.n)
    

    (Other than that, the error message that you see indicates that the Python interpreter has crashed, which should never happen, not even if you make a mistake in your code. I do suspect it's indirectly triggered by the infinite loop though.)

    Cheers!
    Sebastiaan

  • Hi Sebastiaan,

    ah yes of course, I was too focused on the other part :smiley: thanks!
    but it should work if I just assign the new random sample to the sequence variable in the while-loop, shouldn't it? If not, is there a way to avoid that two sequences in a row begin with the same word?

    while var.sequence[0] == firstitem:
            var.sequence = random.sample(echt_kurz, var.n)
    

    And I also have a follow-up question ;)
    As I will be presenting the stimuli acoustically, I need to prepare the samplers for each word of the sequence, so that I can simply loop through the sampler.play() for each word in the run phase. To my understanding it should be enough to prepare the sampler for each word once for the whole experiment (so I don't have to do it in every prepare-phase), is that correct? Something like

    wort_sound_list = []
    for i, word in enumerate(echt_kurz):
        word_sampler = exp.pool[word + '.ogg']
        word_sound = sampler(word_sampler)
        word_sound_list.append(word_sound)
    

    So then I could call the word_sound.play() in the run-phase for each element of the sequence. I would like to do something like the following, using [word] as a variable to call only the word_sounds that are element of the current sequence

    for word in var.sequence:
        word_sound.play()
        clock.sleep(var.interval - 5)
    

    This however will not work, as I cannot get the "word_sound.play()" to be dynamic (it just takes the last value of "word_sound" from the loop before; if I use a different index (e.g. "i") there is a warning that i_canvas does not exist). This is obvious, but is there a way to make the names of sounds (or canvases respectively) dynamic?
    Or do I have to prepare all the samplers for each word of the sequence anew in the prepare-phase for every trial? I hope it becomes clear what I'm trying to achieve?

    Thank you a lot
    Cheers,
    Gunnar

  • Hi Gunnar,

    What you're looking for is a dict. Right now you're creating a list of sampler objects, which makes it tricky to associate each sampler with a word (which effectively what you want to do). If you use a dict, you can use a word as the key, and the sampler object as the value. Then it's easy to retrieve the correct sampler object during each trial. Does that make sense? (I'll leave it to you as an exercise to implement this.)

    To my understanding it should be enough to prepare the sampler for each word once for the whole experiment (so I don't have to do it in every prepare-phase), is that correct?

    Totally.

    Cheers,
    Sebastiaan

  • Hi Sebastiaan,
    alright, thank you for the hint, and your 'didactic' answer ;) I'll give it a shot...
    Cheers,
    Gunnar

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