How to Generate random sampling from a probability distribution function generated by kernel density estimation?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Bjorn Gustavsson
le 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 commentaires
Voir également
Catégories
En savoir plus sur Kernel Distribution dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!