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!