Howdy, Stranger!

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

Supported by

Remember and present again only trials with wrong responses after a loop in OSweb

SERSER
edited November 2021 in OSWeb

Hi everyone,

I have a problem with OSweb: I have a loop and I want to present again only the trials with wrong answer. Let's suppose I have a loop with 4 trials, i answer correctly only on two of them. After the end of the loop I want to present again just the 3 trials I answered wrong, and repeat this mechanism until all the trials will be answered correctly.

I understand in python how to do this, but i'm not able to traspose in java...

How can I do this in OSweb?

Thank you all

SER

Comments

  • Hi @SER,

    There may be various ways to go about achieving what you're after. Doing it without Python code is a little challenging, but here's one solution I can suggest (hopefully I'm not making this a lot more complicated that it needs to be).

    I put together an example task with a series of 15 trials where subjects simply have to press the key corresponding to the letter appearing on the screen. Here's the general structure of the task:

    Here's the key idea: We're gonna have the N trials (15 in my example) repeat and keep track of what trials need be presented and which should not by updating an array variable that contains N elements. That array would take the value [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] at the onset of the experiment. Each of the elements in the array will correspond to a trial marked by the trialindex variable in the Trials_loop. As the subject responds, we'll look at whether their response is correct or not and update the appropriate element in that array accordingly. The Trials_loop contains two nested sequences. The lower level one contains the instructions to run a typical trial. The higher level one is there to check the value of the array's element corresponding to the current trial is, so that we can use code at that stage to condition the running of the lower level sequence to that information. Last bit: the Trials_loop is itself contained in a higher level loop with one trial and a cycle repetition set to 100, with a break condition that will be met when all trials have been responded to correctly (which will happen when the sum of the array's elements is N (i.e., 15, in this case): sum of [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]. In a nutshell, the Trials_loop will be repeated over and over (well, up to 100 times anyway), though only trials that have not been responded to correctly thus far will be presented, and the whole thing stops when all trials have been responded to correctly. The method I'm suggesting ensures that all trials to be presented are presented in a new random order every time the loop runs.

    I'm describing below the key steps in more detail... (Note that I sprinkled the code task with various instructions to print to console; it's very handing to help monitoring and debugging. If running the task in the browser, you'll need to make the console visible to track that information - Ctrl+i in Chrome, for example).

    STEP 1

    We're starting by initializing some variables and counters in Javascript inside the initializing inline_javascript object:

    // declares function to sets all elements of a array to a specific value
    function setAll(a, v) {
      var i, n = a.length;
      for (i = 0; i < n; ++i) {
        a[i] = v;
      }
    }
    
    // sets allcorrect and trials counter to zero
    vars.trials_counter=0
    vars.allcorrect=0
    
    // creates an array and sets all 15 elements to zero
    var arr = new Array(15)
    setAll(arr,'0')
    // stores the array in an OS variable
    vars.trials_array = arr
    // output to console for monitoring
    console.log ("Trials array: "+arr)
    

    Here, we're setting some counters to zero: trials_counter will keep track of how many trials the subject is completing, and allcorrect is the variable that starts up being 0 but will change to 1 if all trials have been responded to correctly (we'll use this as a break condition in the macro_loop).

    We're also creating trials_array: an array of N (15) elements, and we set them up all to zero using the setAll function we're creating in this code too.

    STEP 2

    We nest loops and sequences so as to be able to condition the presentation of the trial_sequence to whether the current trial is one that has not received a correct response before:

    The trial_sequence will only run if runtrial is equal to zero. And runtrial is defined just before in the trial_filtering inline_javascript object:

    vars.runtrial = vars.trials_array[vars.trialindex]
    

    Let's imagine that the current trial is row 7 in the Trials_loop. The stimulus to be shown is "g". This line of code looks into the trials_array variable and retrieves the trialindexth element. So, in this case, because the trialindex for row 7 is 6, we'll look at the 7th element of the trials_array (the first element being the 0th, so trialindex is 6 in the 7th element). Let's imagine that the task has just begun, no correct response has been produced in any trial, the trials_array will be [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] (I highlighted the element in position 7 (trialindex 6) in bold). runtrial takes that value (0). Hence, the "Run if" condition set for trial_sequence in the events listed in the Trial_decision sequence is met and the trial_sequence is executed (hence the trial goes ahead, the "g" stimulus is presented and the subject's response registered).

    So far so good...

    STEP 3

    In the Trial_sequence, we have some code too. The code in pre_monitoring is just there for monitoring and debugging. It simply outputs to the console the state of various variables, so that we can check everything is going as it should.

    console.log("______________________________________")
    console.log ("PRE RESPONSE")
    console.log ("Stimulus: "+vars.stimulus+" TrialIndex: "+vars.trialindex)
    console.log("Value for array element "+vars.trialindex+" : "+vars.trials_array[vars.trialindex])
    

    At the end of the trial comes some important code (set_status inline_javascript).

    I break it down into its separate bits:

    We first increment the number of trials presented so far (this is not critical but I thought it'd be useful to get an idea of how many trials subjects complete before all stimuli are responded to correctly):

    vars.trials_counter++
    

    Next, if the subject's response is correct, we're gonna update the appropriate element in the Trials_array to 1, The element is indicated by the trial_index value of the current trial. If the response is correct, we set that element to 1. So, let's imagine that the very first first trial presented is row 7 of the Trials_loop: before the subject responds, the trials_array is [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]. After correct response, that array will be [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0].

    // updates the trials_array if the response is correct
    if (vars.correct==1) {
       vars.trials_array[vars.trialindex]=1
    }
    

    Next, we're gonna sum up the elements of the Trials_array and store it in total, and build a string of the array that we'll use for monitoring purposes in the console.

    // summing the elements of the trials_array (that is, the number of correct responses currently stored for each trial of the loop)
    var total = 0
    var arraystring =""
    for (var i = 0, iLen = vars.trials_array.length; i < iLen; i++) {
       // sum up too non-zero values for some reason, adding zeros to, say 3, results in 30
       // so I limit the summing to values that are equal to 1
       if (vars.trials_array[i]==1) {
          total += vars.trials_array[i]
       }
    arraystring = arraystring + vars.trials_array[i]
    }
    

    If total = 15, then it means that all trials have been responded to correctly (since we have 15 trials). In that case, we set allcorrect to 1.

    if (total==15) {
       vars.allcorrect=1
    }
    

    This will have the immediate effect of breaking out of the macro_loop, because of the way we set up the Break if property:

    The rest of the code in set_status is for monitoring and debugging purposes:

    // For monitoring and debugging purposes
    console.log ("POST RESPONSE")
    console.log ("Trials array: "+arraystring)
    console.log ("Sum of array elements: "+total)
    console.log ("Score: "+vars.correct+" TrialIndex: "+vars.trialindex)
    console.log("Value for array element "+vars.trialindex+" : "+vars.trials_array[vars.trialindex])
    console.log ("Allcorrect: "+vars.allcorrect)
    console.log ("Number of trials presented so far: "+vars.trials_counter)
    

    Et voilà! We've done the hard bit!

    A couple more things...

    I implemented a feedback in the trial using two feedback objects and conditioning their presentation on whether the response is correct or not:

    Note also that you'll need to set carefully the variables being logged in the data logger. When running the experiment through OSWeb, the compatibility check will fail if the logger is set to log all variables (because it can use a lot of bandwidth). So you'll need to make sure you manually include the variables you want in the data output.

    Your task will be implemented differently than my example, of course, but hopefully the description above will be useful to you.

    You can download my example here:

    Hope this helps!

    Fabrice.

    Buy Me A Coffee

  • Hi @SER and @Fab ,


    I didn't read this thread entirely, but I was just wondering whether you are familiar with the repeat_cycle plugin:



    Cheers,


    Lotje

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

  • Hi @lvanderlinden,

    Does look like a much simpler solution indeed! πŸ˜€

    Does it execute all the trials from a loop before repeating some, or are repeated trials mixed with no-presented-yet trials?

    Best,

    Fabrice.

    Buy Me A Coffee

  • Hi @Fab ,


    If you append a repeat_cycle item to the end of your trial_sequence and force it to repeat each cycle on which the response was incorrect, like so:


    OpenSesame will first run all cycles from the block_loop and then, after having run the whole loop , only repeat the trials on which participants responded erroneously (see the example below).


    If, alternatively, you want to repeat an error trial immediately, you need to use a work-around with a nested structure, like so:



    I hope the examples make sense!

    And the good thing is that the repeat_cycle plugin also works online! :)


    Cheers,


    Lotje

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

  • Hi @lvanderlinden,

    Great, thank you for this! Really useful! I'm learning something new every day!

    @SER, that solution should work well in your experiment and is a lot simpler than mine!

    Best,

    Fabrice.

    Buy Me A Coffee

  • Hi @lvanderlinden and @Fab,

    @lvanderlinden thank you so much, this works so good also online! I tried the repeat_cycle plugin but I put it in the wrong place.

    @Fab thank you too, i will study your solution to improve my programmer skills! πŸ˜‰

    Cheers,

    Sara

  • Hi @lvanderlinden,

    I have just another question: does your solution work with random loop? πŸ˜₯

    Cheers,

    Sara

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