Fast Sampling From A Discrete Distribution

Versión 1.0.0.0 (3,58 KB) por Peng Liu
This function generates independent random samples according to a prescribed discrete distribution.
242 descargas
Actualizado 14 oct 2016

Ver licencia

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.

Citar como

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. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2015a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Random Number Generation en Help Center y MATLAB Answers.
Agradecimientos

Inspirado por: Sampling from a discrete distribution

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
1.0.0.0

more accurate title
Improved documentation
N/A

Better description
N/A