naginterfaces.library.rand.sample¶
- naginterfaces.library.rand.sample(m, statecomm, ipop=None, n=None)[source]¶
sample
selects a pseudorandom sample without replacement from an integer vector.For full information please refer to the NAG Library document for g05nd
https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/g05/g05ndf.html
- Parameters
- mint
The sample size.
- 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()
.- ipopNone or int, array-like, shape , optional
The population to be sampled.
If is None, then the population is assumed to be the set of values and the array is not referenced.
- nNone or int, optional
Note: if this argument is None then a default value will be used, determined as follows: .
The number of elements in the population to be sampled.
- Returns
- isamplint, ndarray, shape
The selected sample.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, [‘state’] vector has been corrupted or not initialized.
- Notes
sample
selects elements from a population vector of length and places them in a sample vector . Their order in will be preserved in . Each of the (n;m) possible combinations of elements of may be regarded as being equally probable.For moderate or large values of it is theoretically impossible that all combinations of size may occur, unless is near or near . This is because (n;m) exceeds the cycle length of any of the base generators. For practical purposes this is irrelevant, as the time taken to generate all possible combinations is many millenia.
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 tosample
.
- References
Kendall, M G and Stuart, A, 1969, The Advanced Theory of Statistics (Volume 1), (3rd Edition), Griffin
Knuth, D E, 1981, The Art of Computer Programming (Volume 2), (2nd Edition), Addison–Wesley