Coder Social home page Coder Social logo

approximatebayesiancomputation.jl's Introduction

Binder Approximate Bayesian Computation in Julia

Build Status Build statusCoverage Statuscodecov

This package contains some approximate Bayesian computation algorithms.

A toy example for each algorithm is also provided in the examples.

Algorithms:

  • ABC rejection sampling (ABC-RS)
  • ABC Markov chain Monte Carlo (ABC-MCMC)
  • ABC population Monte Carlo (ABC-PMC)

Kernels:

  • Uniform
  • Gaussian

Distance function(s):

  • (Weighted) Euclidean distance
  • Gaussian kernel distance

Posterior inference checks are also provided see ?quantile_interval and ?loss.

Minimal working example

We will in this minimal working example using the ABC rejection sampling algorithm to learn the mean for a Normal distribution with known standard deviation.

Walk-through

Load packages, and set up the model.

using ApproximateBayesianComputation
using Distributions

μ = 0 # true value for the mean, the parameter that  we want to estimate
σ = 1 # known standard deviation
n = 100 # nbr of observations

y = rand(Normal(μ,σ),100) # generate some data

# the prior is a normal distribution with μ = 0.1, and σ = 1
prior = Normal(0.1, 1)

Define the functions needed for the ABC-RS algorithm.

# function to sample from the prior
sample_from_prior() = rand(prior)

# function to generate data
generate_data(μ) = rand(Normal(μ[1],σ),n)

# the summary statistics are the mean and the standard
# deviation, i.e. the sufficient statistics for the data
calc_summary(y_star,y) = [mean(y_star); std(y_star)]

# distance function
ρ(s_star, s) = euclidean_dist(s_star, s, ones(2))

Set up the ABC-RS problem.

problem = ABCRS(10^6,
                0.01,
                Data(y),
                1,
                cores = 1,
                print_interval = 10^5)

Run ABC-RS.

approx_posterior_samples = sample(problem,
                                  sample_from_prior,
                                  generate_data,
                                  calc_summary,
                                  ρ)

Check posterior quantile interval.

posterior_quantile_interval = quantile_interval(approx_posterior_samples)

Posterior and prior distribution.

How to use this package

This package is not added to METADATA.jl. But, you can still install the package locally by running:

Pkg.clone("https://github.com/SamuelWiqvist/ApproximateBayesianComputation.jl")

To run the examples directly in your browser simply click on the binder link, and then open the Jupyter notebook examples.ipynb. However, launching the binder server might take a while (in some cases up to 20 minutes) since the environment has to be installed on the server.

About this package

This package was originally created for the graduate course Approximate Bayesian Computation at Chalmers University of Technology.

approximatebayesiancomputation.jl's People

Contributors

samuelwiqvist avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.