Sampling from a PDF histogram

**HISTOGRAM_PDF_SAMPLE**
is a MATLAB library which
demonstrates how sampling can be done by starting with the
formula for a PDF, creating a histogram, constructing a
histogram for the CDF, and then sampling.

We would prefer to compute the CDF exactly by integration of the PDF, then invert the formula for the CDF to get a formula for random samples. But often the CDF is not invertible, and often it's not possible to get an exact formula for the CDF in any case. For such problems, the histogram approach may provide a relatively straightforward solution.

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

**HISTOGRAM_PDF_SAMPLE** is available in
a Matlab version.

FEM1D_SAMPLE, a MATLAB program which samples a scalar or vector finite element function of one variable, defined by FEM files, returning interpolated values at the sample points.

FEM2D_SAMPLE, a MATLAB program which evaluates a finite element function defined on an order 3 or order 6 triangulation of a 2D region.

FEM3D_SAMPLE, a MATLAB program which evaluates a finite element function defined on 3D tetrahedral mesh.

HISTOGRAM_DATA_2D_SAMPLE, a MATLAB program which demonstrates how to construct a Probability Density Function (PDF) from a frequency table over a 2D domain, and then to use that PDF to create new samples.

PDFLIB, a MATLAB library which evaluates Probability Density Functions (PDF's) and produces random samples from them, including beta, binomial, chi, exponential, gamma, inverse chi, inverse gamma, multinomial, normal, scaled inverse chi, and uniform.

PROB, a MATLAB library which evaluates, samples, inverts, and characterizes a number of Probability Density Functions (PDF's) and Cumulative Density Functions (CDF's), including anglit, arcsin, benford, birthday, bernoulli, beta_binomial, beta, binomial, bradford, burr, cardiod, cauchy, chi, chi squared, circular, cosine, deranged, dipole, dirichlet mixture, discrete, empirical, english sentence and word length, error, exponential, extreme values, f, fisk, folded normal, frechet, gamma, generalized logistic, geometric, gompertz, gumbel, half normal, hypergeometric, inverse gaussian, laplace, levy, logistic, log normal, log series, log uniform, lorentz, maxwell, multinomial, nakagami, negative binomial, normal, pareto, planck, poisson, power, quasigeometric, rayleigh, reciprocal, runs, sech, semicircular, student t, triangle, uniform, von mises, weibull, zipf.

RANLIB, a MATLAB library which produces random samples from Probability Density Functions (PDF's), including Beta, Chi-square Exponential, F, Gamma, Multivariate normal, Noncentral chi-square, Noncentral F, Univariate normal, random permutations, Real uniform, Binomial, Negative Binomial, Multinomial, Poisson and Integer uniform, by Barry Brown and James Lovato.

REJECTION_SAMPLE, a MATLAB library which demonstrates acceptance/rejection sampling.

WALKER_SAMPLE, a MATLAB library which efficiently samples a discrete probability vector using Walker sampling.

- cdf_to_sample.m, uses the histogrammed CDF to compute samples.
- histogram_to_cdf.m uses the histogrammed PDF to compute a histogrammed CDF.
- pdf_to_histogram.m uses the PDF formula to compute a histogrammed PDF.
- r8vec_bracket4.m seeks the interval which contains each point in a vector.
- timestamp.m, prints the current YMDHMS date as a time stamp.

CHEBYSHEV1 is a test case for the PDF rho(x)=1/sqrt(1-x*x)/pi for x between -1 and +1, which is infinite at the endpoints.

- chebyshev1_cdf.m, evaluates the CDF.
- chebyshev1_pdf.m, evaluates the PDF.
- chebyshev1_test.m
- chebyshev1_pdf.png
- chebyshev1_cdf.png
- chebyshev1_histogram.png

CHEBYSHEV13 is a test case for the PDF rho(x)=(1-x*x)^(-1/6) for x between -1 and +1, which is infinite at the endpoints. (In order to integrate to 1 over [-1,+1], multiply by the factor gamma(4/3)/sqrt(pi)/gamma(5.6).)

- chebyshev13_cdf.m, evaluates the CDF.
- chebyshev13_pdf.m, evaluates the PDF.
- chebyshev13_test.m
- chebyshev13_pdf.png
- chebyshev13_cdf.png
- chebyshev13_histogram.png

CHEBYSHEV2 is a test case for the PDF rho(x)=2*sqrt(1-x*x)/pi for x between -1 and +1.

- chebyshev2_cdf.m, evaluates the CDF.
- chebyshev2_pdf.m, evaluates the PDF.
- chebyshev2_test.m
- chebyshev2_pdf.png
- chebyshev2_cdf.png
- chebyshev2_histogram.png

- histogram_pdf_sample_test.m, the calling program;
- histogram_pdf_sample_test_output.txt, the output file.

You can go up one level to the MATLAB source codes.