Application Notes for Intel® oneAPI Math Kernel Library Summary Statistics

ID 772991
Date 12/04/2020
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Estimating Quantiles

You can use the Summary Statistics routines to compute quantiles for a matrix of observations. The computation routine can calculate more than one quantile at a time. Quantile orders belonging to the interval (0,1) are packed and passed into the library as an array. You should allocate enough memory to hold results of the calculations. The size of the array should provide storage for at least d*p elements, where

  1. p is the dimension of the task.

  2. d is the number of the requested quantiles.

Quantiles in the array are packed component by component, starting from the first component of the random vector and following the quantile orders.

See the Mathematical Notation and Definitions chapter in the Summary Statistics section of [MKLMan] for additional information.

The example below illustrates quantile-related calculations:

#include "mkl_vsl.h"
#include <stdio.h>
#define DIM 3      /* dimension of the task */
#define N   1000   /* number of observations */
#define M   100    /* number of quantiles to compute */
 
int main()
{
   int i, status;
   VSLSSTaskPtr task;
   float x[DIM][N];      /* matrix of observations */
   float order_stats[N]; /* matrix to store order statistics */
   float q_order[M], quants[M];
   MKL_INT q_order_n;
   MKL_INT p, n, xstorage, ostatstorage;
   unsigned long long estimates;
   int indices[DIM]={1,0,0}; /* the first vector component is processed */
 
   /* Parameters of the task and initialization */
   p = DIM;
   n = N;
   q_order_n = M;
   xstorage  = VSL_SS_MATRIX_STORAGE_ROWS;
   ostatstorage = VSL_SS_MATRIX_STORAGE_ROWS;
 
   /* Calculate percentiles */
   for ( i = 0; i < M; i++ ) q_order[i] = (float)i / (float)M;
  
   /* Create a task */
   status = vslsSSNewTask( &task, &p, &n,
                           &xstorage, (float*)x, 0, indices );
 
   /* Initialize the task parameters */
   status = vslsSSEditQuantiles( task, &q_order_n, q_order,
                                 quants, order_stats, &ostatstorage );
 
   /* Compute the percentiles and order statistics */
   estimates = VSL_SS_QUANTS|VSL_SS_ORDER_STATS;
   status = vslsSSCompute( task, estimates, VSL_SS_METHOD_FAST );
 
   /* Deallocate the task resources */
   status = vslSSDeleteTask( &task );
 
   return 0;
}