naginterfaces.library.rand.resample¶
- naginterfaces.library.rand.resample(wt, statecomm, rtype=3, ipop=None, m=None, nrs=1, otype=2)[source]¶
resample
selects a pseudorandom sample (or resamples) from a vector of integers based on the supplied weights.For full information please refer to the NAG Library document for g05nf
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g05/g05nff.html
- Parameters
- wtfloat, array-like, shape
, the weights. These weights need not sum to .
- statecommdict, RNG communication object, modified in place
RNG communication structure.
This argument must have been initialized by a prior call to
init_repeat()
orinit_nonrepeat()
.- rtypeint, optional
A flag indicating the resampling method to use.
Multinomial resampling will be used.
Systematic resampling will be used.
Residual resampling will be used.
- ipopNone or int, array-like, shape , optional
Note: the required length for this argument is determined as follows: if : ; otherwise: .
, the vector to be sampled from. If then the is assumed to be the set of values .
Elements of 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 are counts, i.e., , then is not referenced.
- mNone or int, optional
Note: if this argument is None then a default value will be used, determined as follows: .
, the size of the sample required.
- nrsint, optional
The number of times to resample.
- otypeint, optional
A flag indicating what is returned in .
The values returned in are taken from the population.
The values returned in are counts.
See for more information.
- Returns
- isamplint, ndarray, shape
The selected samples.
If then each column of contains the values from that make up the sample.
If then contains the number of times that appears in the th sample.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: , or .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, all the weights are zero.
Constraint: at least one weight must be nonzero.
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: or .
- (errno )
On entry, [‘state’] vector has been corrupted or not initialized.
- Warns
- NagAlgorithmicWarning
- (errno )
There was no random component to the sample. Check the sample size and weights are as expected.
- Notes
Given a vector , of integer values,
resample
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
resample
is where was obtained using some other sampling method, for example, importance sampling. In such a case, this function 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
int_multinomial()
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 functions
init_repeat()
(for a repeatable sequence if computed sequentially) orinit_nonrepeat()
(for a non-repeatable sequence) must be called prior to the first call toresample
.
- References
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 Magazine (vol. 32, no. 3), 70–86, https://dx.doi.org/10.1109/MSP.2014.2330626