Skip to content

Instantly share code, notes, and snippets.

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

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)
#parent distribution is Gaussian
μ = 10
parent = Distributions.Normal(10) #μ = 10
parent_pdf(x) = Distributions.pdf(parent, x)
rᵢ = rand(n)
a = 6
b = 14
xᵢ = a .+ (b-a) .* rᵢ
βᵢ = parent_pdf.(xᵢ) ./ parent_pdf(median(xᵢ))
sᵢ = rand(n)
msk = βᵢ .> sᵢ
result = xᵢ[msk]
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)")

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.