How to Generate random sampling from a probability distribution function generated by kernel density estimation?
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I generate the PDF using ksdensity function matlab. Now I want to genrate random samples for the Monte Carlo simulation from that PDF, Anybody has an idea how to generate these random samples?
Many thanks in advance
MAnsour
0 Kommentare
Antworten (1)
Bjorn Gustavsson
am 31 Mai 2019
Either you do something like this (Untested-unverified-off-the-cuff^TM):
% Assuming pdfKD values at x:
cdfKD = cumtrapz(x,pdfKD);
cdfKD = (cdfKD - cdfKD(1))/(cdfKD(end)-cdfKD(1)); % normalizing the cdf to be between zero and 1 at the end of your intervall
Q = rand(n);
randVals = interp1(cdfKD,x,Q,'pchip-or-linear');
Or you take a look at the file exchange contributions that solves just this task:
HTH
0 Kommentare
Siehe auch
Kategorien
Mehr zu Kernel Distribution finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!