GithubHelp home page GithubHelp logo

danshai / metropolis_mcmc Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 12 KB

metropolis markov chain monte carlo algorithm

Python 100.00%
metropolis-hastings metropolis-monte-carlo metropolis-hastings-algorithm algorithm mcmc markov-chain monte-carlo

metropolis_mcmc's Introduction

Metropolis hastings mcmc algorithm

To carry out the Metropolis-Hastings algorithm, we need to draw random samples from the following distributions:

  • the standard uniform distribution
  • a proposal distribution p(x) that we choose to be N(0,σ)
  • the target distribution g(x) which is proportional to the posterior probability

Given an initial guess for θ with positive probability of being drawn, the Metropolis-Hastings algorithm proceeds as follows:

  • Choose a new proposed value (θpp) such that θp=θ+Δθ where Δθ∼N(0,σ)
  • Caluculate the ratio : ρ = g(θp | X)/g(θ | X) where g is the posterior probability.

If the proposal distribution is not symmetrical, we need to weight the acceptance probability to maintain detailed balance (reversibility) of the stationary distribution, and instead calculate:

ρ=g(θp | X) p(θ | θp) / g(θ | X) p(θp | θ)

Since we are taking ratios, the denominator cancels any distribution proportional to g will also work we can use:

ρ=p(X|θp)p(θp)/ p(X|θ)p(θ)

  • If ρ≥1, then set θ=θp
  • If ρ<1, then set θ=θp with probability ρ, otherwise set θ=θ (this is where we use the standard uniform distribution)

Repeat the earlier steps. After some number of iterations k, the samples θk+1,θk+2,… will be samples from the posterior distributions. Here are initial concepts to help your intuition about why this is so:

  • We accept a proposed move to θk+1 whenever the density of the (unnormalized) target distribution
  • at θk+1 is larger than the value of θk
  • so θ will more often be found in places where the target distribution is denser If this was all we accepted, θ would get stuck at a local mode of the target distribution, so we also accept occasional moves to lower density regions
  • it turns out that the correct probability of doing so is given by the ratio ρ - The acceptance criteria only looks at ratios of the target distribution, so the denominator cancels out and does not matter
  • that is why we only need samples from a distribution proportional to the posterior distribution So, θ will be expected to bounce around in such a way that its spends its time in places proportional to the density of the posterior distribution.
  • that is, θ is a draw from the posterior distribution.

metropolis_mcmc's People

Contributors

danshai avatar

Stargazers

 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.