MATLAB code to sample arbitrary Lipschitz continuous densities on the interval.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
README.md
norm_sample.png
triangular-with-envelope.png

README.md

LipSample

MATLAB code to generate random variates following arbitrary Lipschitz continuous densities on the interval.

Example

Sample from the normal distribution (Lipschitz constant 0.25) restricted to [-5, 5].

sample = lipsample(@normpdf, 0.25, [-5 5], 10000000);

Plot the result.

pretty_hist(sample, [-5 5]);

Usage and functionalities

sample = lipsample(@f, L, [a b], m); Draws a sample of size m from the probability density function f which is Lipschitz continuous of order L on [a,b].

Notes

The function f does not have to be a normalized density, but it should be scaled to be near 1 as to improve efficiency. L is the Lipschitz constant of f, not of its renormalization.

Below you can see the envelope that was automatically constructed for the acceptance-rejection sampling of a triangular density (lipsample(@triangular, 4, [0 1], 1000000, 'N', 9);).