Created
October 10, 2019 08:17
-
-
Save Moelf/c48adec32be53302a11ebb343d4cd462 to your computer and use it in GitHub Desktop.
CustomSampler https://pasteboard.co/IBirbG7.gif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
https://pasteboard.co/IBirbG7.gif