Skip to content

Instantly share code, notes, and snippets.

@Moelf Moelf/HW2.jl
Created Oct 10, 2019

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

Moelf commented Oct 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.