Howdy, Stranger!

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

Supported by

[solved] Resetting counters

edited June 2013 in OpenSesame

Hey all,

So I am trying to figure out how to reset a counter. I have a loop for blocks which contains a loop for trials. In order to loop through blocks and trials I trying to use count_variables as indices, in particular the count_blockloop and count_trialsequence in the inline_code.

So the block works just fine, but its the trial looping that breaks since the counter does not restart with each block and so it goes beyond the number of elements in a dictionary from which the trials are drawn. I tried doing self.experiment.set('counter_trialsequence', 0) in the block inline_code, but that has no effect.

So any other idea of how to restart the counter from within the block inline_code?

Thanks,

SillyNapalm

Comments

  • edited 8:59AM

    Hi SillyNapalm,

    The items maintain their own counter, which needs to be explicitly reset. Otherwise, as you have experienced, it will simply keep overwriting the count_[item_name] variable. The following should do the trick:

    # Uncomment for 0.25 and earlier
    # exp = self.experiment
    exp.items['item_to_reset'].count = 0

    Cheers,
    Sebastiaan

  • edited 8:59AM

    Thanks for the reply. I tried it, but it returns a KeyError. So how do I add it to the dictionary? Or maybe its something else...

    I would also be grateful if you could point me to where I can find documentation for the experiment dictionary methods as I fail to see it on the main website.

  • edited 8:59AM
    Thanks for the reply. I tried it, but it returns a KeyError. So how do I add it to the dictionary? Or maybe its something else...

    Did you use the correct item name? For example, if the sequence is called trial_sequence you would use the following statement:

    exp.items['trial_sequence'].count = 0
    I would also be grateful if you could point me to where I can find documentation for the experiment dictionary methods as I fail to see it on the main website.

    Unfortunately, there's no systematic documentation on this. The available functions depend on the item, and are not really intended to be accessed by the user. I sometimes access them nonetheless, like now, but that's kind of a hack for want of a better solution.

    Still, you could get a list of functions of attributes with a script like this:

    item = 'my_item_name'
    for i in dir(exp.items[item]):
        print '%s (%s)' % (i, type(eval('exp.items[item].%s' % i)))

    Cheers!

  • edited 8:59AM

    Yeah, I have the correct name. And I tried several combinations. Also, it does not matter where I put it in the experiment it always returns the KeyError.

    Any ideas? I could change the approach completely, but it would be nice for this to work since this is rather simple and fast.

  • edited 8:59AM

    Really? The exp.items dictionary is the place were all the items are stored. Are you sure you didn't accidentally modify exp.items? Or is there a typo (it's case sensitive)? You can check what's in the items dictionary with a script like this:

    for item in exp.items:
        print '%s (%s)' % (item, exp.items[item].__class__)

    This should give something like the following output, where the first part is the item name (= key in the dictionary).

    inline_script (libopensesame.inline_script.inline_script)
    experiment (libopensesame.sequence.sequence)
    getting_started (notepad.notepad)
    welcome (libopensesame.sketchpad.sketchpad)

    If it really doesn't work you could upload the entire script to something pastebin or paste it here, so I can take a look at it.

    Cheers!

  • edited 8:59AM

    I got it. The issue was that I was using 'count_var_name' instead of 'var_name' when applying count method. I suppose I was going based on the variable inspector.

    Anyhow, the issue is closed.

    Thanks,

    SillyNapalm

  • edited 8:59AM

    Can you reset the 'count' experiment variable itself? I would like my log file to only have one count column, which I will reset for each part of the experiment.

    Best regards,
    Jákup

  • Hi Jákup,

    What is the item you want to count? And when do you want to reset it?

    If, for instance, you want to count the number of trials and reset this counter at the beginning of every new block, I think the code Sebastiaan posted above should work.

    For example, if your trial sequence item is called trial_sequence, you would append an inline_script item to your block sequence item and place the following piece of code here:

    exp.items['trial_sequence'].count = 0

    By resetting this variable at the beginning of a new block, the variable count_trial_sequence (that you're probably familiar with) will automatically be reset to zero as well.

    Does this help? If this was not exactly what you were asking for, perhaps you could provide us with some more information about what output variables you would like to have in your log files.

    Best wishes,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 8:59AM

    Hello Lotje.
    Thank you very much for your help :) This will definitely work, as well. But isn't there a built in variable called simply 'count'? I was thinking, that instead of logging all the various instantiations of the count_* variables, that I could simply reset the built in counter, at each new portion of the program. Or is this variable perhaps the count_trial_sequence counter? :)

    Best regards,
    Jákup

  • edited December 2012

    Hi Jakub!

    I think I can answer that as well. The count_trial_sequence is the amount of times the sequence item called 'trial_sequence' (which you probably have) is run.

    Secondly, a built-in counter would be very hard to implement, since for every experiment you usually want to count different thing. What you could do, is make your own custom counter. Use an inline_script item to start the counter, use one every time you would want the counter to go up and use one for resetting:

    starting the counter:

    self.experiment.set("my_counter", 0)
    

    making the counter go up by one:

    self.experiment.set("my_counter", self.get("my_counter"+1))
    

    resetting the counter:

    self.experiment.set("my_counter", 0)
    
  • edited 8:59AM

    Hello again Edwin :)
    And thank you very much :) That is indeed a good idea, if I truly want to customize how I want the experiment counted.

    But there is a built in variable called 'count'. If you log it using the logger, it will count all the cycles throughout the experiment. If you can't see it in the logger item, you can just add this to the logger script:

     log "count"

    In my experiment, I could of course log, for example, "count_session1_squence" + "count_session2_sequence" + "count_questionnaire_sequence" separately. But then my log file will have a separate column for each of these counters, and I will have to manually edit them to a single one as "count". So, if it would be possible to reset control the count variable itself, that would be nice.

    exp.set('count')

    doesn't seem to work.

    Of course, this is just nit-picking, and I could settle for putting each item, I wish to be counted together in the same sequences, and then just count that sequence. But I'm curious if it is possible to use the count variable in this was. I'm doing the same for "response" - i.e., I only log that variable, and not any other separate response variables.

    All the best!
    Jákup

  • edited December 2012

    Hi Jákup,

    Just a quick note:

    Perhaps it's helpful to understand what the count variable actually is, because it's potentially a bit confusing: Every item has a variable that is called count, which simply counts how often the item has been called. This variable is specific to a particular item, and only accessible from within that item. This item variable is used to set a 'global' variable in the experiment, which is called count_[item name]. If you are interested, you can see in the source how this happens in an item's prepare phase: https://github.com/smathot/OpenSesame/blob/master/libopensesame/item.py#L76

    So if you do

    self.get('count')

    in an inline_script, you will get the counter for that inline_script item. Similarly, if you log count in a logger, you will log the counter for that logger. This may seem like a global counter, but it's not: It's simply the counter for that specific item. This is due to the fact that variables can exist at two levels, as explained (inadequately I must admit) here: Either as a 'global' experiment variable, accessible to all items, or as a 'local' item variable, only from within a specific item.

    There is no global counter, for the reason that Edwin mentioned: OpenSesame does not know what your experiment 'means' and as such does not know how to maintain an appropriate counter. Instead, it offers separate counters for all items, for you to interpret. Does that make sense? Generally speaking, it is count_trial_sequence that you want, but it depends on your experiment.

    Hope this clears things up a bit!

    Cheers!

  • edited December 2012

    It certainly did, thanks for clarifying :)

    So when I log the response variable, in a similar way, it is not a global variable called "response", but a local one, that is replaced by the same variable in subsequent items?

    So, logging the logger's count simulates what I was looking for, correct? Is there a way to reset it?

    Best regards,

    Jákup

  • edited 8:59AM
    So when I log the response variable, in a similar way, it is not a global variable called "response", but a local one, that is replaced by the same variable in subsequent items?

    Well, the rule is a follows: When a logger self.get()s a variable, it first checks whether this variable exists at the item level. If not, it checks whether the variable exists at the experiment level. In the case of response, this variable generally only exists at the experiment level. But you will see that if, just to test, you add the line ...

    set response this_is_a_dummy_response

    ... to the logger script, the logger will pick this newly set item-level response variable (which is not what you want, of course, but just to illustrate). So it's a fallback mechanism, where item-level variables get precedence.

    So, logging the logger's count simulates what I was looking for, correct? Is there a way to reset it?

    Yes, see my first response in this thread ;)

    exp.items['item_to_reset'].count = 0

    The item to reset would in this case be the name of the logger item. This will reset the item-level count variable and indirectly the experiment-level count_[item name] variable.

    Cheers!

  • edited 8:59AM

    Oh... yes :) Silly me 8-|

    Thanks a bunch for taking the time to explain this in debt!

    Jákup

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