Skip to content

Instantly share code, notes, and snippets.

@Moelf
Created October 10, 2019 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Moelf/c48adec32be53302a11ebb343d4cd462 to your computer and use it in GitHub Desktop.
Save Moelf/c48adec32be53302a11ebb343d4cd462 to your computer and use it in GitHub Desktop.
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
@Moelf
Copy link
Author

Moelf commented Oct 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment