Git Product home page Git Product logo

cda-samplers's Introduction

cda-samplers

Examples of fitting a simple Gaussian mixture model with three different Bayesian sampling methods.

Developed for a lecture for Carnegie's Computational Data Analysis program

Setup

Install these packages.

When installing pystan, it involves compiling the code Stan (C++ code). Whatever compiler is used here needs to be in your path when running Stan. This is the alias Alex needs to call before running the ipython notebook for his version to work:

alias stancc="export CC=<your-version-of-clang>; export CXX=<your-version-of-clang++>"

If you have not installed standard astronomy libraries (numpy, scipy, matplotlib, astropy) you should do that too.

Data

The dataset we will use is not yet published but will be soon. For now, Alex will send you the file.

Reference

Alex's recommendation

This is motivated by empirical practice with relatively small problems.

  • Use dynesty by default. It's slowest but most robust. It's easier to spend computer time than human time.
  • Use emcee if dynesty is too slow and/or you have a complicated model.
  • Use pystan if emcee is too slow and your model can be written in terms of analytic functions

dynesty

Dynamic nested sampling.

Benefits:

  • Scientists are better at thinking about what prior they want than the intricacies of sampling
  • Good at multimodal stuff
  • Computes the evidence (I think that means it's good for model comparison)

Costs:

  • Slow and costly, about 10x more than other methods.
  • Need to be very careful about choosing your priors

emcee

Affine-invariant multiple walkers

Benefits:

  • Probably easiest to use
  • Lots of people in astronomy use it and can help you

Costs:

  • Need some practice with setting up walkers, how long to burn in, etc.
  • It's a bit fiddly how long you need to run
  • Not the most efficient sampler

pystan

Hamiltonian Monte Carlo in Stan

Benefits:

Costs:

  • The hardest to learn: you kind of need to know C++, it's a whole new language on top of that, and the language is only "intuitive" for statisticians
  • Cannot use very complicated models (e.g. interpolating grids)
  • The sampler is so efficient that you have to be a bit careful about priors too

cda-samplers's People

Contributors

alexji 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.