Welcome! Log In Create A New Profile

Advanced

alert_function

Posted by Jaewon 
alert_function
May 13, 2019 01:53PM
The alert_function is very useful, when you want to insert your own initialization/clean-up code or get notifications for the progress of the task.

The function is located in the NIMH ML's installation path. If you edit "alert_function.m" in the NIMH ML directory, the changes affect all the tasks that you run. If you want to customize the function only for a particular task, make a copy of it to the task directory and edit the copy. When "alert_function.m" is found both in the NIMH ML directory and your task directory, the one in the task directory has priority.

The alert_function is activated by toggling it on in the NIMH ML main menu.



The structure of the alert_function is like the following. The "hook" indicates the event at which the function is called, so place your code under appropriate case statements. If it is necessary to exchange information with the rest of the task code, use the "TrialRecord.User" field.
function alert_function(hook,MLConfig,TrialRecord)

switch hook
    case 'task_start'   % when the task starts by '[Space] Start' from the pause menu
        
    case 'block_start'
        
    case 'trial_start'
        
    case 'trial_end'
        
    case 'block_end'
        
    case 'task_end'      % when '[q] Quit' is selected in the pause menu

    case 'task_aborted'  % when the task stops with an error

    case 'task_paused'   % when the task is paused with ESC during the experiment

    case 'task_resumed'  % when the task is resumed by '[Space] Resume' from the pause menu
        
end

end

For example, if you want to stop the task after a certain number of success trials, you can do it as below.
case 'trial_end'

    % It is assumed you recorded the success status of each trial with the trialerror() function
    % in your timing script.
    success_count = sum(0==TrialRecord.TrialErrors);

    % Also you assigned the maximum number of success trials that you want to run
    % to TrialRecord.User.max_success_trials in the timing script.
    if success_count==TrialRecord.User.max_success_trials
        TrialRecord.Pause = true;  % The task will be paused.
    end

The "alert_function_Slack.m" file in the NIMH ML directory is an example that sends notifications to your smartphone via the Slack app. To try it, copy it to your task directory, rename the file to "alert_function.m" and follow the instructions in the file.
Attachments:
open | download - tips_alert_on.png (9.9 KB)

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.