The routine may be called by the names g05nff or nagf_rand_resample.
3Description
Given a vector , of integer values, g05nff selects elements with the probability of selecting proportional to a user-supplied weight, . The sampling is done with replacement, so that each value, , may appear more than once in the sample.
The most common usage case for g05nff is where was obtained using some other sampling method, for example, importance sampling. In such a case, this routine is used to perform resampling.
Several methods of calculating , the number of times appears in the sample, are available:
•Multinomial Resampling:
The vector of counts; is drawn from a multinomial distribution with probabilities given by the normalised weights, .
•Systematic Resampling:
where are the normalised weights, , , for and is defined to be zero.
In other words, is the number of shifted and scaled uniform variates contained in bins defined by the partial sums of normalised weights.
•Residual Resampling:
,
where (i.e. the integer part of ), and the vector of residual counts, is drawn from a multinomial distribution with probabilities given by .
See g05tgf for more information on the multinomial distribution and Douc et al. (2005) for more details on the resampling methods.
If multiple samples are requested () then the chosen resampling method is performed independently for each sample.
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 g05nff.
4References
Douc R,
Cappe O, and
Moulines E
(2005)
Comparison of resampling schemes for particle filtering
Proceedings of the 4th International Symposium on Image and Signal Processing and Analysis
64–69
https://dx.doi.org/10.1109/ISPA.2005.195385
Li T,
Bolic M, and
Djuric P M
(2015)
Resampling Methods for Particle Filtering: Classification, implementation, and strategies
IEEE Signal Processing Magazinevol. 32, no. 3
70–86
https://dx.doi.org/10.1109/MSP.2014.2330626
5Arguments
1: – IntegerInput
On entry: a flag indicating the resampling method to use.
Multinomial resampling will be used.
Systematic resampling will be used.
Residual resampling will be used.
Constraint:
, or .
2: – IntegerInput
On entry: , the size of the population.
Constraint:
.
3: – Real (Kind=nag_wp) arrayInput
On entry: , the weights. These weights need not sum to .
Constraints:
, for ;
at least one (and preferably more than one) weight must be nonzero.
4: – Integer arrayInput
On entry: , the vector to be sampled from. If then the is assumed to be the set of values and ipop is not referenced.
Elements of ipop with the same value are not combined, therefore, if and then there is a nonzero probability that the sample will contain both and , irrespective of their values.
If the values to be returned in isampl are counts, i.e., , then ipop is not referenced.
5: – IntegerInput
On entry: the dimension of the array ipop as declared in the (sub)program from which g05nff is called.
Constraint:
or .
6: – IntegerInput
On entry: , the size of the sample required.
Constraint:
.
7: – IntegerInput
On entry: the number of times to resample.
Constraint:
.
8: – IntegerInput
On entry: a flag indicating what is returned in isampl.
The values returned in isampl are taken from the population.
Note: the second dimension of the array isampl
must be at least
.
On exit: the selected samples.
If then each column of isampl contains the values from that make up the sample. If then contains the number of times that appears in the th sample.
10: – IntegerInput
On entry: the first dimension of the array isampl as declared in the (sub)program from which g05nff is called.
Constraints:
if , ;
otherwise .
11: – 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.
12: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or 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).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, .
Constraint: , or .
On entry, .
Constraint: .
On entry, and .
Constraint: .
On entry, all the weights are zero.
Constraint: at least one weight must be nonzero.
On entry, and .
Constraint: or .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: or .
There was no random component to the sample. Check the sample size and weights are as expected.
Specifically, check that more than one weight is nonzero.
If , also check the combination of m and weights.
On entry, ,
and .
Constraint: .
On entry, ,
and .
Constraint: .
On entry, state vector has been corrupted or not initialized.
An unexpected error has been triggered by this routine. Please
contact NAG.
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.
7Accuracy
Not applicable.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g05nff 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.
9Further Comments
It should be noted that whilst a given sample is a random selection from , the ordering of the sample within isampl may not be. For example, when the values returned are likely to be in the same order that the values appear in . If it is important that the returned values represent a random sample from rather than a ordered random sample then each sample should be randomly permuted via a subsequent call to g05ncf. The same applies to the order in which multiple samples are returned. One consequence of this is that if you call g05nff once with , say, and then again (using the same initial values for state), with the first column of isampl may not be the same in both cases since, on the second call, the sample from the first call may be returned in the second column rather than the first.