PDFsampler is a MATLAB class that serves as a random number generator for custom probability distribution functions and is particularly useful for Monte Carlo simulations. Objects of this class are initialized using samples of your custom distribution of using histogram data of your PDF. It is well documented and pretty straight forward to use.
Pantelis Sopasakis (2021). PDFsampler (https://www.mathworks.com/matlabcentral/fileexchange/41689-pdfsampler), MATLAB Central File Exchange. Retrieved .
Thank you for this great function. In the nextRandom part of your function, how can I modify it to generate n number of samples not just a single one.
e.g. r = pdfs.nextRandom(100,1) to create 100 rows of random samples from that distribution?
Could you please tell me the name of the reconstruction method you are using? Perhaps a link to some research paper that references it?
@JonathanMayers: PDFSampler works with discrete distributions. You can pass the outputs of `hist` to its constructor.
random_numbers = [ ... ]; % some array
[v, p] = hist(random_numbers, 50);
sampler = PDFSampler(v, p);
% In case you have an array of data
% You can pass it directly to the constructor:
In any case, you sample from the PDF using `sampler.nextRandom`
Thanks for this. I am not sure how to use the class for a custom pdf. Could you please provide an example of this?
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!