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?
5 次查看(过去 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!