CustomSampler https://pasteboard.co/IBirbG7.gif
using Plots, Statistics | |
using StatsPlots | |
using Distributions #this pkg actually is end game, but we're just using gaussian pdf | |
function custom_gaussian(n) | |
#b) | |
#parent distribution is Gaussian | |
μ = 10 | |
parent = Distributions.Normal(10) #μ = 10 | |
parent_pdf(x) = Distributions.pdf(parent, x) | |
#c) | |
rᵢ = rand(n) | |
#d) | |
a = 6 | |
b = 14 | |
xᵢ = a .+ (b-a) .* rᵢ | |
#e) | |
βᵢ = parent_pdf.(xᵢ) ./ parent_pdf(median(xᵢ)) | |
#f) | |
sᵢ = rand(n) | |
msk = βᵢ .> sᵢ | |
result = xᵢ[msk] | |
end | |
big_array = [] | |
@gif for n = 1:11^2 | |
append!(big_array, custom_gaussian(25)) | |
histogram(big_array, bin=7:0.3:13, normed=true, label="Normalized hist") | |
plot!(Normal(10), label="True PDF") | |
title!("Customized sampler with n=$(n*1000)") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Moelf commentedOct 10, 2019
https://pasteboard.co/IBirbG7.gif