what called this method of generation random sample
古いコメントを表示
Hi all
is the code below represent inverse cdf method?
y is pdf of any distribution
cdf_y = cumsum(y);
sum_y = sum(y);
for j = 1:N
randx = sum_y*rand();
i = 1;
while cdf_y(i) < randx
i = i + 1;
end
f(j) = x(i); end
please give me explain
1 件のコメント
José-Luis
2014 年 8 月 29 日
採用された回答
その他の回答 (1 件)
Image Analyst
2014 年 8 月 29 日
0 投票
Not sure exactly what you mean and how specific your question is to that exact code, but in general the process of generating a bunch of random numbers and running an "experiment" N times (in a loop like you did) is called a "Monte Carlo Simulation". For example, check out the attached Monty Hall Problem that I coded up as a Monte Carlo simulation.
10 件のコメント
Image Analyst
2014 年 8 月 29 日
That would be inverse transform sampling, http://en.wikipedia.org/wiki/Inverse_transform_sampling. See my attached demo which works with a Rayleigh distribution.

mutah
2014 年 8 月 29 日
Image Analyst
2014 年 8 月 29 日
編集済み: Image Analyst
2014 年 8 月 29 日
Well, sort of. I think that may be the intent of the author but they really messed up the code, and that's not even talking about the formatting. I did attach an example in my prior comment.
mutah
2014 年 8 月 29 日
Image Analyst
2014 年 8 月 29 日
編集済み: Image Analyst
2014 年 8 月 29 日
It's a Monte Carlo simulation but the problem is that x is not defined. A skilled MATLAB programmer would also use find() rather than while.
mutah
2014 年 8 月 29 日
編集済み: Image Analyst
2014 年 8 月 29 日
Image Analyst
2014 年 8 月 29 日
cumsum gives the cdf of y. For that x, the pdf if flat since it's a uniform distribution so the cdf will be a straight ramp. They use sum(y) to get the max value that the cdf could be. They just as well could have used cdf(end), because the cdf and pdf are not normalized and the sum of all y values is the number of x elements you have, which is 10,001.
Image Analyst
2014 年 8 月 31 日
Well, like I said, the while (and line before and two lines after) could be replaced:
i = find(cdf_y > randx, 1, 'first')
カテゴリ
ヘルプ センター および File Exchange で Waveform Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!