How to Generate random sampling from a probability distribution function generated by kernel density estimation?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Bjorn Gustavsson
il 31 Mag 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 Commenti
Vedere anche
Categorie
Scopri di più su Kernel Distribution in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!