naginterfaces.library.rand.sample_wgt¶
- naginterfaces.library.rand.sample_wgt(order, wt, m, statecomm, ipop=None)[source]¶
sample_wgt
selects a pseudorandom sample, without replacement and allowing for unequal probabilities.For full information please refer to the NAG Library document for g05ne
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g05/g05nef.html
- Parameters
- orderstr, length 1
A flag indicating the sorted status of the vector.
is sorted in ascending order,
is sorted in descending order,
is unsorted and
sample_wgt
will sort the weights prior to using them.Irrespective of the value of , no checks are made on the sorted status of , e.g., it is possible to supply , even when is not sorted.
In such cases the array will not be sorted internally, but
sample_wgt
will still work correctly except, possibly, in cases of extreme weight values.It is usually more efficient to specify a value of that is consistent with the status of .
- wtfloat, array-like, shape
, the relative probability weights. These weights need not sum to .
- mint
, the size of the sample required.
- 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
Note: the required length for this argument is determined as follows: if : ; otherwise: .
The population to be sampled. If then the population is assumed to be the set of values and the array is not referenced. 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 . If then that value can appear in more than once.
- Returns
- isamplint, ndarray, shape
The selected sample.
- Raises
- NagValueError
- (errno )
On entry, had an illegal value.
- (errno )
On entry, at least one weight was less than zero.
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, [‘state’] vector has been corrupted or not initialized.
- (errno )
On entry, , number of nonzero weights .
Constraint: must be at least nonzero weights.
- Notes
sample_wgt
selects elements from either the set of values or a supplied population vector of length . The probability of selecting the th element is proportional to a user-supplied weight, . Each element will appear at most once in the sample, i.e., the sampling is done without replacement.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_wgt
.