Application Notes for oneMKL Summary Statistics

ID 772991
Date 3/31/2023
Public
Document Table of Contents

Computing Mean Absolute Deviation

Summary Statistics offers two methods for computation of mean absolute deviation:

  1. Method VSL_SS_METHOD_FAST is a performance-oriented implementation of the algorithm.

  2. Method VSL_SS_METHOD_FAST_USER_MEAN is an implementation of the algorithm when a user-defined mean is provided.

The calculation is straightforward and follows the pattern of the example below:

#include "mkl_vsl.h"
    
#define DIM 3      /* dimension of the task */ 
#define N   1000   /* number of observations */
  
int main()
{
    VSLSSTaskPtr task;
    float x[DIM][N];  /* matrix of observations */
    float mnad[DIM];
    MKL_INT p, n, xstorage;
    int status;
  
    /* Parameters of the task and initialization */
    p = DIM;
    n = N;
    xstorage = VSL_SS_MATRIX_STORAGE_ROWS;
  
    /* Create a task */
    status = vslsSSNewTask( &task, &p, &n, &xstorage, (float*)x, 0, 0 );
  
    /* Initialize the task parameters */
    status = vslsSSEditTask( task, VSL_SS_ED_MNAD, mnad );
  
    /* Compute median absolute deviation in observations */
    status = vslsSSCompute(task, VSL_SS_MNAD, VSL_SS_METHOD_FAST );
  
    /* Deallocate the task resources */
    status = vslSSDeleteTask( &task );
  
    return 0;
}

The size of the array to hold mean absolute deviations should be sufficient to hold at least p elements, where p is the dimension of the task.

Computation of mean absolute deviation is only possible for data arrays available at once, or in separate blocks of the dataset.

To achieve the best results, before you compute mean absolute deviation, provide the buffer for estimate of mean (or corresponding sum) even if you do not need this estimate.