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에서 Inverse Gaussian Distribution에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!