I have a discete probability distribution (histogram) and want to invoke rand to produce n random samples that follow the distribution specified by the histogram -how?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a distribution specified by a 1d histogram, say [1 , 10; 2 , 50; 3 , 10; 4 , 30]
now I want to invoke rand to produce n discrete random samples (of value 1,2,3, or 4), such that the output distribution of the random samples matches closely the distribution specified by the histogram.
E.g. in this example for n=10 I would expect the output vector to have one 1, five 2s, one 3, and three 4s or a result that would be very close to it. How can I ensure that through rand()?
댓글 수: 0
답변 (3개)
Bjorn Gustavsson
2017년 2월 9일
0, always start by looking for a solution at the file exchange. 1, I did a quick search and perhaps these submissions solves your problem:
HTH
댓글 수: 0
Roger Stafford
2017년 2월 9일
편집: Roger Stafford
2017년 2월 9일
p = sum(bsxfun(@le,[0,0.1,0.6,0.7],rand(n,1)),2);
(Note: Since this is a probability distribution, you cannot always expect “ the output vector to have one 1, five 2s, one 3, and three 4s or a result that would be very close to it. ” There is always a finite probability that the result would be otherwise.)
댓글 수: 0
Image Analyst
2017년 2월 10일
You need "inverse transform sampling" : https://en.wikipedia.org/wiki/Inverse_transform_sampling Basically compute the CDF of the distribution, and use it to get samples.
I attach an m-file where I get samples drawn from a Rayleigh distribution.
You might also look at RANDRAW which does these distributions: Alpha, Anglit, Antilognormal, Arcsin, Bernoulli, Bessel, Beta, Binomial, Bradford, Burr, Cauchy, Chi, Chi-Square (Non-Central), Chi-Square (Central), Cobb-Douglas, Cosine, Double-Exponential, Erlang, Exponential, Extreme-Value, F (Central), F (Non-Central), Fisher-Tippett, Fisk, Frechet, Furry, Gamma, Generalized Inverse Gaussian, Generalized Hyperbolic, Geometric, Gompertz, Gumbel, Half-Cosine, Hyperbolic Secant, Hypergeometric, Inverse Gaussian, Laplace, Logistic, Lognormal, Lomax, Lorentz, Maxwell, Nakagami, Negative Binomial, Normal, Normal-Inverse-Gaussian (NIG), Pareto, Pareto2, Pascal, Planck, Poisson, Quadratic, Rademacher, Rayleigh, Rice, Semicircle, Skellam, Student's-t, Triangular, Truncated Normal, Tukey-Lambda, U-shape, Uniform (continuous), Von Mises, Wald, Weibull, Wigner Semicircle, Yule, Zeta, Zipf
댓글 수: 0
참고 항목
카테고리
AI, Data Science, and Statistics
Statistics and Machine Learning Toolbox
Probability Distributions
Discrete Distributions
Binomial Distribution
AI, Data Science, and Statistics
Statistics and Machine Learning Toolbox
Probability Distributions
Discrete Distributions
Hypergeometric Distribution
AI, Data Science, and Statistics
Statistics and Machine Learning Toolbox
Probability Distributions
Continuous Distributions
Chi-Square Distribution
더 보기
Help Center 및 File Exchange에서 Binomial Distribution에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!