what called this method of generation random sample
Mostrar comentarios más antiguos
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 comentario
José-Luis
el 29 de Ag. de 2014
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 29 de Ag. de 2014
0 votos
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 comentarios
Image Analyst
el 29 de Ag. de 2014
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
el 29 de Ag. de 2014
Image Analyst
el 29 de Ag. de 2014
Editada: Image Analyst
el 29 de Ag. de 2014
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
el 29 de Ag. de 2014
Image Analyst
el 29 de Ag. de 2014
Editada: Image Analyst
el 29 de Ag. de 2014
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
el 29 de Ag. de 2014
Editada: Image Analyst
el 29 de Ag. de 2014
Image Analyst
el 29 de Ag. de 2014
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
el 31 de Ag. de 2014
Well, like I said, the while (and line before and two lines after) could be replaced:
i = find(cdf_y > randx, 1, 'first')
Categorías
Más información sobre Inverse Gaussian Distribution en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!