The routine may be called by the names g01anf or nagf_stat_quantiles_stream_fixed.
A quantile is a value which divides a frequency distribution such that there is a given proportion of data values below the quantile. For example, the median of a dataset is the quantile because half the values are less than or equal to it.
g01anf uses a slightly modified version of an algorithm described in a paper by Zhang and Wang (2007) to determine -approximate quantiles of a data stream of real values, where is known. Given any quantile , an -approximate quantile is defined as an element in the data stream whose rank falls within . In case of more than one -approximate quantile being available, the one closest to is returned.
Zhang Q and Wang W (2007) A fast algorithm for approximate quantiles in high speed data streams Proceedings of the 19th International Conference on Scientific and Statistical Database Management IEEE Computer Society 29
1: – IntegerInput/Output
On entry: indicates the action required in the current call to g01anf.
Return the required length of rcomm and icomm in and respectively. n and eps must be set and licomm must be at least .
Initialise the communication arrays and process the first nb values from the data stream as supplied in rv.
Process the next block of nb values from the data stream. The calling program must update rv and (if required) nb, and re-enter g01anf with all other parameters unchanged.
Calculate the nq -approximate quantiles specified in q. The calling program must set q and nq and re-enter g01anf with all other parameters unchanged. This option can be chosen only when .
On exit: indicates output from a successful call.
Lengths of rcomm and icomm have been returned in and respectively.
g01anf has processed np data points and expects to be called again with additional data (i.e., ).
g01anf has returned the requested -approximate quantiles in qv. These quantiles are based on np data points.
On entry: , the total number of values in the data stream.
3: – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array rv
must be at least
if or .
On entry: if or , the vector containing the current block of data, otherwise rv is not referenced.
4: – IntegerInput
On entry: if or , the size of the current block of data. The size of blocks of data in array rv can vary;, therefore, nb can change between calls to g01anf.
if or , .
5: – Real (Kind=nag_wp)Input
On entry: approximation factor .
6: – IntegerOutput
On exit: the number of elements processed so far.
7: – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array q
must be at least
On entry: if , the quantiles to be calculated, otherwise q is not referenced. Note that , corresponds to the minimum value and to the maximum value.
, for .
8: – Real (Kind=nag_wp) arrayOutput
Note: the dimension of the array qv
must be at least
On exit: if , contains the -approximate quantiles specified by the value provided in .
9: – IntegerInput
On entry: if , the number of quantiles requested, otherwise nq is not referenced.
if , .
10: – Real (Kind=nag_wp) arrayCommunication Array
11: – IntegerInput
On entry: the dimension of the array rcomm as declared in the (sub)program from which g01anf is called.
if , lrcomm must be at least equal to the value returned in by a call to g01anf with . This will not be more than , where .
12: – Integer arrayCommunication Array
13: – IntegerInput
On entry: the dimension of the array icomm as declared in the (sub)program from which g01anf is called.
if , ;
otherwise licomm must be at least equal to the value returned in by a call to g01anf with . This will not be more than , where and .
14: – IntegerInput/Output
On entry: ifail must be set to , or . If you are unfamiliar with this argument you should refer to Section 7 in the Introduction to the NAG Library CL Interface for details.
On exit: unless the routine detects an error (see Section 6).
As an out-of-core routine g01anf will only perform certain argument checks when a data checkpoint (including completion of data input) is signaled. As such it will usually be inappropriate to halt program execution when an error is detected since any errors may be subsequently resolved without losing any processing already carried out. Therefore, setting ifail to a value of or is recommended. If the output of error messages is undesirable, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Number of data elements streamed, is not sufficient for a quantile query when .
Supply more data or reprocess the data with a higher eps value.
On entry, and .
Constraint: if then .
On entry, and .
Constraint: if then for all .
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g01anf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
The average time taken by g01anf is .
This example calculates -approximate quantile for , and for a data stream of values. The stream is read in four blocks of varying size.