Fast Sampling From A Discrete Distribution

버전 1.0.0.0 (3.58 KB) 작성자: Peng Liu
This function generates independent random samples according to a prescribed discrete distribution.
다운로드 수: 242
업데이트 날짜: 2016/10/14

라이선스 보기

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.

인용 양식

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. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2015a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0

more accurate title
Improved documentation
N/A

Better description
N/A