G01ANF finds approximate quantiles from a data stream of known size using an out-of-core algorithm.
SUBROUTINE G01ANF ( |
IND, N, RV, NB, EPS, NP, Q, QV, NQ, RCOMM, LRCOMM, ICOMM, LICOMM, IFAIL) |
INTEGER |
IND, N, NB, NP, NQ, LRCOMM, ICOMM(LICOMM), LICOMM, IFAIL |
REAL (KIND=nag_wp) |
RV(*), EPS, Q(*), QV(*), RCOMM(LRCOMM) |
|
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: IND – 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.
- Routine has processed all N data points (i.e., ).
Constraint:
on entry , , or .
- 2: N – INTEGERInput
On entry: , the total number of values in the data stream.
Constraint:
.
- 3: RV() – 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: 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 G01ANF.
Constraint:
if or , .
- 5: EPS – REAL (KIND=nag_wp)Input
On entry: approximation factor .
Constraint:
.
- 6: NP – INTEGEROutput
On exit: the number of elements processed so far.
- 7: Q() – REAL (KIND=nag_wp) arrayInput
-
Note: the dimension of the array
Q
must be at least
if
.
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 .
- 8: QV() – REAL (KIND=nag_wp) arrayOutput
-
Note: the dimension of the array
QV
must be at least
if
.
On exit: if , contains the -approximate quantiles specified by the value provided in .
- 9: NQ – INTEGERInput
On entry: if
, the number of quantiles requested, otherwise
NQ is not referenced.
Constraint:
if , .
- 10: RCOMM(LRCOMM) – REAL (KIND=nag_wp) arrayCommunication Array
- 11: LRCOMM – INTEGERInput
On entry: the dimension of the array
RCOMM as declared in the (sub)program from which G01ANF is called.
Constraint:
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: ICOMM(LICOMM) – INTEGER arrayCommunication Array
- 13: LICOMM – INTEGERInput
On entry: the dimension of the array
ICOMM as declared in the (sub)program from which G01ANF is called.
Constraints:
- 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: IFAIL – INTEGERInput/Output
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
On exit:
unless the routine detects an error (see
Section 6).
As an out-of-core routine G01ANF will only perform certain parameter 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
is recommended. If the output of error messages is undesirable, then the value
is recommended.
When the value is used it is essential to test the value of IFAIL on exit.
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Not applicable.