Skip to content

Instantly share code, notes, and snippets.

View drbenvincent's full-sized avatar

Benjamin T. Vincent drbenvincent

View GitHub Profile
@drbenvincent
drbenvincent / rejectionSamplingDemo.m
Last active May 26, 2018 11:41
rejection sampling demo - Matlab
%% true probability distribution
true_func = @(x) betapdf(x,1+1,1+10);
%% Do rejection sampling
% create many samples on interval 0-1
x_samples = rand(10^6,1);
% evaluate for each sample
sample_value = true_func(x_samples);
% accept in proportion to highest
max_value = max(sample_value);