Fast Sampling From A Discrete Distribution

Version 1.0.0.0 (3,58 ko) par Peng Liu
This function generates independent random samples according to a prescribed discrete distribution.
242 téléchargements
Mise à jour 14 oct. 2016

Afficher la licence

This function generates independent random samples according to a prescribed discrete distribution. It accepts as inputs the discrete probability mass function, the size of the random matrix to be generated, and an optional input parameter which specifies the data type of the output (default to double). The output is a random matrix.

>> x = randsmpl(p, m, n)
returns an m-by-n matrix x of random samples drawn independently from the input (discrete) distribution specified with pmf p. Suppose that the sample space comprises K samples, then p must be a (row- or column-) vector containing K probability masses summing to 1. The output, x(i,j) = k, k = 1, ..., K, describes that the k-th sample is drawn in the (i,j)-th trial, for i = 1, ..., m and j = 1,...,n. The default output data type of x is 'double'.

>> x = randsmpl(p, m, n, classname)
returns an m-by-n matrix x whose data type is specified by classname. The classname input must be a valid numeric class name which includes the following
'double' (default) | 'single' | 'int64' | 'int32' | 'int16' | 'int8' | 'uint64' | 'uint32' | 'uint16' | 'uint8' |
If classname is not provided, it is default to 'double'.

The implementation of randsmpl is based on the discretize function, which was introduced in R2015a. For backward compatibility, we also provided an interp1 alternative. randsmpl is smart enough that it will automatically determine whether to use discretize or interp1 according to users' MATLAB version.

This function is extremely useful for fast sampling for Monte Carlo simulations. The performance and robustness of the function are highly optimized. Comments and suggestions will be appreciated.

Citation pour cette source

Peng Liu (2024). Fast Sampling From A Discrete Distribution (https://www.mathworks.com/matlabcentral/fileexchange/59724-fast-sampling-from-a-discrete-distribution), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2015a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Random Number Generation dans Help Center et MATLAB Answers
Remerciements

Inspiré par : Sampling from a discrete distribution

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Publié le Notes de version
1.0.0.0

more accurate title
Improved documentation
N/A

Better description
N/A