Anyway to compute subject performance over the last 25 trials?

meyert11's Avatar

meyert11

21 Sep, 2018 03:15 AM

Hi Chris,

We'd like to compute subject performance over the last 25 trials. In a typical programming language I'd create an array of length 25 and just fill in each slot with a 1 or 0 for performance, then cycle through the locations. I tried searching through Mworks to see if there was a way to do this, but I've been unsuccessful. I'd really like to keep this in Mworks, and not have to depend on Matlab or Python for it, any suggestions?

  1. Support Staff 1 Posted by Christopher Sta... on 21 Sep, 2018 02:13 PM

    Christopher Stawarz's Avatar

    Hi Travis,

    In a typical programming language I'd create an array of length 25 and just fill in each slot with a 1 or 0 for performance

    You can do that in MWorks with a list. For example:

    var performance = []
    
    protocol {
        performance = []
        trial (nsamples = 25) {
            performance[size(performance)] = disc_rand(0, 1)
        }
        report ('performance: $performance')
    }
    

    The final report action produces a message like

    performance: [1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0]
    

    You could also make the initial value of variable performance a list of length 25, but that isn't necessary in this case.

    Cheers,
    Chris

  2. 2 Posted by meyert11 on 21 Sep, 2018 02:31 PM

    meyert11's Avatar

    Hi Chris,

    Thanks for the quick response! Ok I'll look into lists, I saw that in 2014
    asmoly asked if lists could be updated (e.g. list[index] = 5), and your
    answer was no, I assume that this is now possible? I've only used the
    MWeditor to create and alter experiment xml's so I'll try to associate your
    code to the editor's steps. Do you have a link to how to incorporate code
    like yours into the xml? I ask because in a previous question (I think it
    was about using firmata with the manual reward window) you also sent code
    as the example. Is it as simple as using an editor (ie sublime) and copying
    the code into the xml? If this is the case, will subsequent MWeditor loads
    automatically bring up the code? Sorry for all the questions.

  3. 3 Posted by meyert11 on 21 Sep, 2018 03:24 PM

    meyert11's Avatar

    <update>
    Hi Chris, just wanted to shoot you a quick update and correction. I was
    confused in the earlier response in that there are 2 'Lists', one list is
    part of the Paradigm Components, and that's what I thought you were
    referring to, but I found a 2017 answer you gave that you updated the Dev
    version so that variables can be lists, and bingo, that was it! I have
    created a list P, with 25 default values [0,0...], and I'll have an
    index_counter that will cycle between 1 and 25, putting a 1 for correct, 0
    for wrong. Then I'll just need to sum them up and divide into 25 for
    performance! I'll let you know the result, if you have any tips, feel free
    to share.

    Thx!

    T

  4. 4 Posted by meyert11 on 21 Sep, 2018 03:54 PM

    meyert11's Avatar

    Hi Chris,

    It works!!!! Some things I learned:
    list variables start at 0, so if I wanted to go from 1:25, I actually
    needed a list size of 26 zeros for the default value. To sum I just did,
    P[1]+P[2]... and put that into a different variable that I then compute
    performance on. Thanks for the help, and being a sounding board ;)

    Here's how I set it up in MWeditor terms (for anyone else that wants to do
    something like this):
    variable P: type list: default value: 26 zeros.
    variable i_P: default 1, this is a cycling index counter that goes from 1
    to 25 then back to 1 ...
    When a trial is correct I assign P[i_P] = 1, wrong: P[i_P] = 0.
    At the end I then assign a different variable var = P[1]+P[2]...
    To compute performance I assign variable Performance to (var / 25)*100.

    T

  5. Support Staff 5 Posted by Christopher Sta... on 24 Sep, 2018 12:56 PM

    Christopher Stawarz's Avatar

    Hi Travis,

    Glad you were able to get this working. My only comment is to discourage you from trying to force 1-based indexing onto MWorks' zero-based lists. It might make things seem simpler at first, but ultimately it will make your code harder to understand and more prone to errors. (If you still want i_P to run from 1 to 25, just use i_P-1 as the indexing expression.)

    Cheers,
    Chris

  6. Christopher Stawarz closed this discussion on 01 Oct, 2018 02:32 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

07 Feb, 2019 02:24 PM
02 Feb, 2019 01:58 PM
01 Feb, 2019 06:25 PM
26 Jan, 2019 12:15 AM
18 Jan, 2019 05:44 PM