Howdy, Stranger!

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

Supported by

[open] N-back task

edited February 2015 in OpenSesame

Hi Dear All,

I've just started using OpenSesame and currently thinking about writing a standard N-back fMRI task to further share it with the whole community (it's one of the most commonly used paradigms and, I'm sure, many researchers will find it useful).

However, the software, my own enthusiasm and limited Python coding skills are everything that I have, so far.

So, I would really appreciate your help with this.

I am uploading this alpha-version of a standard N-back task (with shapes):
https://www.dropbox.com/s/t8myta7597jcw1o/nback_shapes_v0.1.opensesame.tar.gz?dl=0

It has 3 difficulties: N=1 (basically, just visual matching), N=2 and N=3, more levels can be easily added.

Ideally, I would like to implement an opportunity to sync the stimuli with TRs from the MR scanner, but it is not at the top of my list right now.

Here are the things that I'm currently struggling with:

  1. Cannot find a way to make the trials fixed (e.g. instead of defining "n1" loop based on number of repetitions, it would be nice if the task was still self-paced, but the loop was terminated after, say, every 45 seconds).
  2. Not sure how to record correct responses in a smart way.. There was another version that had different number of stimuli: 1-back: 1 shape after the 'key' stimulus, 2-back: 2, etc... But I just don't think it's a very elegant solution.
  3. I removed feedback from this version, as I did not know how to bind it to the correct responses.

Apologies if these things are too basic.. And I welcome any questions and comments you might have!

Best Wishes,
Alex

Comments

  • edited 6:00AM

    Hi Alex,

    However, the software, my own enthusiasm and limited Python coding skills are everything that I have, so far.

    This is usually enough, Python is quite easy to learn, so if you use your enthusiasm, you should be there in no time.

    Cannot find a way to make the trials fixed (e.g. instead of defining "n1" loop based on number of repetitions, it would be nice if the task was still self-paced, but the loop was terminated after, say, every 45 seconds).

    If you want it to be time-based, you can put the trial sequence into an inline_script in a way similar to this one:

    # the code gives you only pointers how to do it, it is not supposed to work by
    # copy & paste
    from openexp.canvas import canvas
    from openexp.keyboard import keyboard
    import random
    
    cv = canvas(exp)
    my_keyboard = keyboard(exp, keylist=['z', 'x'], timeout=3000)
    
    files_in_pool = ['star', 'circle', ...]
    
    
    # initialize timer
    t0, t1 = self.time(), self.time()
    while t1-t0 < 45000:
    
         # load image
         file = random.choice(files_in_pool)
         image_file = exp.get_file(file+'.png')
         stimuli.append(file)
    
         cv.image(image_file)
    
         # time response
         start_time = self.time() # as a reference for reaction time
         rp_key, end_time = my_keyboard.get_key()
    
         t1 = self.time()
    

    Not sure how to record correct responses in a smart way.. There was another version that had different number of stimuli: 1-back: 1 shape after the 'key' stimulus, 2-back: 2, etc... But I just don't think it's a very elegant solution

    The upper script is a good starting point for adding nice correct response logging
    You just have to define the correct response in the while loop,and compare it to the actual one. Again, here a way of doing it:


    # add before the while loop: trial_counter = 0 stimuli = [] # add in while loop trial_counter += 1 stimuli.append(file) # define correct response if stimuli[- (n+1)] == stimuli[-1] : # n-1 defined by condition, which you should specify earlier correct_response = 'key' # check for given response if correct_response == rp_key: given_response = 1 else: given_response = 0 # for all relevant variables: exp.set('variable_name', variable)

    I removed feedback from this version, as I did not know how to bind it to the correct responses.

    Add another canvas, which only shows feedback text:

    # beginning of script:
    feedback_cv = canvas(exp)
    
    # in the end of while loop:
    if given_response:
        text = 'correct!'
    else:
        text = 'Incorrect!'
    
    feedback_cv.text('text')
    feedback_cv.show()
    self.sleep(300)
    

    I hope these pointers will suffice for you to get started. Btw. I am not sure how exactly the paradigm is supposed to work. I have to versions in my mind, that make both sort of sense, so in case you realize I explained the wrong one, sorry. But still, you should be able to modify the code for your needs.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited 6:00AM

    I realized, it might have been better, if I just posted one coherent code snippet.
    Here you go!

    from openexp.canvas import canvas
    from openexp.keyboard import keyboard
    import random
    
    
    feedback_cv = canvas(exp)
    cv = canvas(exp)
    my_keyboard = keyboard(exp, keylist=['z', 'x'], timeout=3000)
    
    files_in_pool = ['star', 'circle', ...]
    trial_counter = 0
    stimuli = []
    
    # initialize timer
    t0, t1 = self.time(), self.time()
    while t1-t0 < 45000:
         trial_counter += 1
    
         # load image
         file = random.choice(files_in_pool)
         image_file = exp.get_file(file+'.png')
         stimuli.append(file)
    
         cv.image(image_file)
    
         # time response
         start_time = self.time() # as a reference for reaction time
         rp_key, end_time = my_keyboard.get_key()
    
         if stimuli[- (n+1)] == stimuli[-1] :
               #  n-1 defined by condition, which you should specify earlier
               correct_response = 'key'
    
         # check for given response
         if correct_response == rp_key:
               given_response = 1
         else:
               given_response = 0
    
    
         if given_response:
               text = 'correct!'
         else:
               text = 'Incorrect!'
    
         feedback_cv.text('text')
         feedback_cv.show()
         self.sleep(300)
    
        # for all relevant variables:
         exp.set('variable_name', variable)
    
         t1 = self.time()
    

    Buy Me A Coffee

  • edited February 2015

    Hi Dear All,

    Thanks a lot for all your help!
    After discussing the task with our group, we eventually decided to go for a pseudo-random sequence of events...
    The task is running relatively smoothly now I would say... However, I'm still struggling a bit with the logs (will manage it eventually, I hope).

    However, there is one particular problem that I still don't know how to fix...
    The thing is that I want to provide a feedback indicating which button (1-yes or 2-no) has been pressed without any correct/wrong indication [my experience suggests that without the feedback some subjects often get puzzled with this task]...

    The way it is supposed to look is as follows:
    image

    However, when I start my paradigm I'm getting this error:
    image

    Apologies for bothering... It's probably something straightforward (like incorrect assignment of the variables)...
    Could you please suggest what I have to change?

    I am attaching two archives:

    1.
    https://www.dropbox.com/s/zwk23k7rpw6jaek/nback_noFeedback.opensesame.tar.gz?dl=0
    [working version without the feedback]
    2.
    https://www.dropbox.com/s/43fmrsqcmbb246f/nback_wFeedback.opensesame.tar.gz?dl=0
    [an effort to implement this feedback with the error]

    Thank you very much for your time!

    Best,
    Alex

  • edited February 2015

    Ok..
    I think I found a way to implement the feedback eventually...
    Here is my working shortened version of n-back: https://www.dropbox.com/s/irvyfzub0j2wqzp/nback_wFeedbackDemoShortened.opensesame.tar.gz?dl=0

    However, I am not entirely sure how to fix the logs, which do not seem to generate the output I need...

    1. In particular, I'm not sure how to skip the first Ns and not to use them in accuracy calculation...
    2. Another issue is that the accuracy seems to be averaged across the trials, whereas I would like to have it calculated separately (e.g. for seq11, seq21, etc)...
    Right now the csv-output looks like this: https://www.dropbox.com/s/sndo6um9xzyiixp/subject-777.csv?dl=0

    I would really appreciate your suggestions Re these issues...

    Thanks a lot,
    Alex
  • edited 6:00AM

    Hi Alex,

    In particular, I'm not sure how to skip the first Ns and not to use them in accuracy calculation...

    You can do it pretty much the same way, you decided which feedback to present when. That is, in the run_if line of your logger, put something like this:
    count_OneBack1 >= N.
    Opensesame keeps track how often an item is repeated. In your logfile, you will find these count-variables. Pick the one that suits you best.

    Another issue is that the accuracy seems to be averaged across the trials, whereas I would like to have it calculated separately (e.g. for seq11, seq21, etc)...

    The most obvious solution that comes to my mind is defining accuracy yourself. So, on every trial increment a counter of trials per sequence and of correct responses per sequence, calculate the average accuracy, save it as a new variable, e.g. avg_acc_block or something similar and finally log it.

    I suppose, you could also adapt the actual logger to make what you want it to, but I think this is more work than necessary.

    I hope this helped.

    Good luck,

    Eduard

    Buy Me A Coffee

  • Hello Alex,

    Have you managed to finish your N-back test? I'm trying to implement a visual one but at the moment i'm strugling even to start. Do you still have your version? It would be of great help if could look at one implementation, but unfortunately your links have expired

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