doobwa/mcmc.jl — pull request #4 by johnmyleswhite (2012-11-22 22:03:12+00:00)
Title: Prepare mcmc.jl for package distribution

These two commits (which must be separate to cope with case issues on OS X) begin to make mcmc.jl ready for distribution as a package. I'll go through and clean up the examples in a bit. For now, here's a simple example that shows how MCMC can be used as a package when installed into `~/.julia`.

load("Distributions")
using Distributions

load("MCMC")
using MCMC

function f(x)
log(0.75 * pdf(Normal(0.0, 1.0), x) + 0.25 * pdf(Normal(10.0, 1.0), x))
end

function mcmc(x::Float64, g::Function, sampler::Function, niter::Int64)
xs = zeros(niter)
gx = g(x)
for iter = 1:niter
x,gx = sampler(x,g,gx)
xs[iter] = x
end
return xs
end

samples = mcmc(0.0, f, slice_sampler, 50_000)
csvwrite("samples.csv", samples)