NAG Library Routine Document
G05PVF
1 Purpose
G05PVF generates training and validation datasets suitable for use in cross-validation or jack-knifing.
2 Specification
SUBROUTINE G05PVF ( |
K, FOLD, N, M, SORDX, X, LDX, USEY, Y, USEW, W, NT, STATE, IFAIL) |
INTEGER |
K, FOLD, N, M, SORDX, LDX, USEY, USEW, NT, STATE(*), IFAIL |
REAL (KIND=nag_wp) |
X(LDX,*), Y(*), W(*) |
|
3 Description
Let denote a matrix of observations on variables and and each denote a vector of length . For example, might represent a matrix of independent variables, the dependent variable and the associated weights in a weighted regression.
G05PVF generates a series of training datasets, denoted by the matrix, vector, vector triplet of observations, and validation datasets, denoted with observations. These training and validation datasets are generated as follows.
Each of the original observations is randomly assigned to one of equally sized groups or folds. For the th sample the validation dataset consists of those observations in group and the training dataset consists of all those observations not in group . Therefore at most samples can be generated.
If is not divisible by then the observations are assigned to groups as evenly as possible, therefore any group will be at most one observation larger or smaller than any other group.
When using the resulting datasets are suitable for leave-one-out cross-validation, or the training dataset on its own for jack-knifing. When using the resulting datasets are suitable for -fold cross-validation. Datasets suitable for reversed cross-validation can be obtained by switching the training and validation datasets, i.e., use the th group as the training dataset and the rest of the data as the validation dataset.
One of the initialization routines
G05KFF (for a repeatable sequence if computed sequentially) or
G05KGF (for a non-repeatable sequence) must be called prior to the first call to G05PVF.
4 References
None.
5 Parameters
- 1: – INTEGERInput
-
On entry: , the number of folds.
Constraint:
.
- 2: – INTEGERInput
-
On entry: the number of the fold to return as the validation dataset.
On the first call to G05PVF
should be set to
and then incremented by one at each subsequent call until all
sets of training and validation datasets have been produced. See
Section 9 for more details on how a different calling sequence can be used.
Constraint:
.
- 3: – INTEGERInput
-
On entry: , the number of observations.
Constraint:
.
- 4: – INTEGERInput
-
On entry: , the number of variables.
Constraint:
.
- 5: – INTEGERInput
-
On entry: determines how variables are stored in
X.
Constraint:
or .
- 6: – REAL (KIND=nag_wp) arrayInput/Output
-
Note: the second dimension of the array
X
must be at least
if
and at least
if
.
The way the data is stored in
X is defined by
SORDX.
If , contains the th observation for the th variable, for and .
If , contains the th observation for the th variable, for and .
On entry: if
,
X must hold
, the values of
for the original dataset, otherwise,
X must not be changed since the last call to G05PVF.
On exit: values of for the training and validation datasets, with held in observations to and in observations to .
- 7: – INTEGERInput
-
On entry: the first dimension of the array
X as declared in the (sub)program from which G05PVF is called.
Constraints:
- if , ;
- otherwise .
- 8: – INTEGERInput
-
On entry: if , the original dataset includes and will be processed alongside .
Constraint:
or .
- 9: – REAL (KIND=nag_wp) arrayInput/Output
-
Note: the dimension of the array
Y
must be at least
if
.
If
,
Y is not referenced on entry and will not be modified on exit.
On entry: if
,
Y must hold
, the values of
for the original dataset, otherwise
Y must not be changed since the last call to G05PVF.
On exit: values of for the training and validation datasets, with held in elements to and in elements to .
- 10: – INTEGERInput
-
On entry: if , the original dataset includes and will be processed alongside .
Constraint:
or .
- 11: – REAL (KIND=nag_wp) arrayInput/Output
-
Note: the dimension of the array
W
must be at least
if
.
If
,
W is not referenced on entry and will not be modified on exit.
On entry: if
,
W must hold
, the values of
for the original dataset, otherwise
W must not be changed since the last call to G05PVF.
On exit: values of for the training and validation datasets, with held in elements to and in elements to .
- 12: – INTEGEROutput
-
On exit: , the number of observations in the training dataset.
- 13: – INTEGER arrayCommunication Array
-
Note: the actual argument supplied
must be the array
STATE supplied to the initialization routines
G05KFF or
G05KGF.
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
- 14: – 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.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: G05PVF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
-
On entry, and .
Constraint: .
-
On entry, and .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, .
Constraint: or .
-
More than of the data did not move when the data was shuffled. of the observations stayed put.
-
On entry, and .
Constraint: if , .
-
On entry, and .
Constraint: if , .
-
Constraint: or .
-
Constraint: or .
-
On entry,
STATE vector has been corrupted or not initialized.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
Not applicable.
8 Parallelism and Performance
G05PVF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G05PVF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
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.
G05PVF will be computationality more efficient if each observation in
X is contiguous, that is
.
Because of the way G05PVF stores the data you should usually generate the
training and validation datasets in order, i.e., set
on the first call and increment it by one at each subsequent call. However, there are times when a different calling sequence would be beneficial, for example, when performing different cross-validation analyses on different threads. This is possible, as long as the following is borne in mind:
- G05PVF must be called with first.
- Other than the first set, you can obtain the training and validation dataset in any order, but for a given X you can only obtain each once.
For example, if you have three threads, you would call G05PVF once with
. You would then copy the
X returned onto each thread and generate the remaing
sets of data by splitting them between the threads. For example, the first thread runs with
, the second with
and the third with
.
10 Example
This example uses G05PVF to facilitate -fold cross-validation.
A set of simulated data is split into
training and validation datasets.
G02GBF is used to fit a logistic regression model to each training dataset and then
G02GPF is used to predict the response for the observations in the validation dataset.
The counts of true and false positives and negatives along with the sensitivity and specificity is then reported.
10.1 Program Text
Program Text (g05pvfe.f90)
10.2 Program Data
Program Data (g05pvfe.d)
10.3 Program Results
Program Results (g05pvfe.r)