nag_approx_quantiles_arbitrary (g01apc) finds approximate quantiles from a large arbitrary-sized data stream using an out-of-core algorithm.
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.
nag_approx_quantiles_arbitrary (g01apc) uses a slightly modified version of an algorithm described in a paper by
Zhang and Wang (2007) to determine
-approximate quantiles of a large arbitrary-sized data stream of real values, where
is a user-defined approximation factor. Let
denote the number of data elements processed so far then, 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 used.
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:
ind – Integer *Input/Output
On initial entry: must be set to .
On entry: indicates the action required in the current call to nag_approx_quantiles_arbitrary (g01apc).
- Initialize the communication arrays and attempt to process the first nb values from the data stream. eps, rv and nb must be set and licomm must be at least .
- Attempt to process the next block of nb values from the data stream. The calling program must update rv and (if required) nb, and re-enter nag_approx_quantiles_arbitrary (g01apc) with all other parameters unchanged.
- Continue calculation following the reallocation of either or both of the communication arrays rcomm and icomm.
- Calculate the nq -approximate quantiles specified in q. The calling program must set q and nq and re-enter nag_approx_quantiles_arbitrary (g01apc) with all other parameters unchanged. This option can be chosen only when .
On exit: indicates output from the call.
- nag_approx_quantiles_arbitrary (g01apc) has processed np data points and expects to be called again with additional data.
- Either one or more of the communication arrays rcomm and icomm is too small. The new minimum lengths of rcomm and icomm have been returned in and respectively. If the new minimum length is greater than the current length then the corresponding communication array needs to be reallocated, its contents preserved and nag_approx_quantiles_arbitrary (g01apc) called again with all other parameters unchanged.
If there is more data to be processed, it is recommended that
lrcomm and
licomm are made significantly bigger than the minimum to limit the number of reallocations.
- nag_approx_quantiles_arbitrary (g01apc) has returned the requested -approximate quantiles in qv. These quantiles are based on np data points.
Constraint:
, , or .
- 2:
rv[] – const doubleInput
-
Note: the dimension,
dim, of the array
rv
must be at least
when
,
or
.
On entry: if
,
or
, the vector containing the current block of data, otherwise
rv is not referenced.
- 3:
nb – 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 nag_approx_quantiles_arbitrary (g01apc).
Constraint:
if , or , .
- 4:
eps – doubleInput
On entry: approximation factor .
Constraint:
.
- 5:
np – Integer *Output
On exit: , the number of elements processed so far.
- 6:
q[] – const doubleInput
-
Note: the dimension,
dim, of the array
q
must be at least
when
.
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.
Constraint:
if , , for .
- 7:
qv[] – doubleOutput
-
Note: the dimension,
dim, of the array
qv
must be at least
when
.
On exit: if , contains the -approximate quantiles specified by the value provided in .
- 8:
nq – IntegerInput
On entry: if
, the number of quantiles requested, otherwise
nq is not referenced.
Constraint:
if , .
- 9:
rcomm[lrcomm] – doubleCommunication Array
On entry: if
or
then the first
elements of
rcomm as supplied to nag_approx_quantiles_arbitrary (g01apc) must be identical to the first
elements of
rcomm returned from the last call to nag_approx_quantiles_arbitrary (g01apc), where
is the value of
lrcomm used in the last call. In other words, the contents of
rcomm must not be altered between calls to this function. If
rcomm needs to be reallocated then its contents must be preserved. If
then
rcomm need not be set.
On exit:
rcomm holds information required by subsequent calls to nag_approx_quantiles_arbitrary (g01apc)
- 10:
lrcomm – IntegerInput
On entry: the dimension of the array
rcomm.
Constraints:
- if , ;
- otherwise .
- 11:
icomm[licomm] – IntegerCommunication Array
On entry: if
or
then the first
elements of
icomm as supplied to nag_approx_quantiles_arbitrary (g01apc) must be identical to the first
elements of
icomm returned from the last call to nag_approx_quantiles_arbitrary (g01apc), where
is the value of
licomm used in the last call. In other words, the contents of
icomm must not be altered between calls to this function. If
icomm needs to be reallocated then its contents must be preserved. If
then
icomm need not be set.
On exit:
holds the minimum required length for
rcomm and
holds the minimum required length for
icomm. The remaining elements of
icomm are used for communication between subsequent calls to nag_approx_quantiles_arbitrary (g01apc).
- 12:
licomm – IntegerInput
On entry: the dimension of the array
icomm.
Constraints:
- if , ;
- otherwise .
- 13:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
- NE_ARRAY_SIZE
-
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_ILLEGAL_COMM
-
The contents of
icomm have been altered between calls to this function.
The contents of
rcomm have been altered between calls to this function.
- NE_INT
-
On entry, , or and .
Constraint: if , or then .
On entry, and .
Constraint: if then .
On entry, .
Constraint: , , or .
- NE_INTERNAL_ERROR
-
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
- NE_Q_OUT_OF_RANGE
-
On entry, and .
Constraint: if then for all .
- NE_REAL
-
On entry, .
Constraint: .
- NE_TOO_SMALL
-
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.
Not applicable.
nag_approx_quantiles_arbitrary (g01apc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the
Users' Note for your implementation for any additional implementation-specific information.
It is not possible to determine in advance the final size of the communication arrays
rcomm and
icomm without knowing the size of the dataset. However, if a rough size (
) is known, the speed of the computation can be increased if the sizes of the communication arrays are not smaller than
where