How to Generate random sampling from a probability distribution function generated by kernel density estimation?
8 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Bjorn Gustavsson
on 31 May 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 Comments
See Also
Categories
Find more on Kernel Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!