Code Monkey home page Code Monkey logo

cftp-sampling's Introduction

This repo contains a naive-generic-general implementation of the CFTP algorithm. It provides also a notebook of the Ising Model simulation using a specific version of the algorithm.


Coupling From The Past

The Coupling from the Past (CFTP) algorithm is a technique used in statistical physics and probabilistic graphical models to sample from the stationary distribution of a Markov chain. It was introduced by Propp and Wilson in 1996 as a method for exact sampling from a Markov chain without the need for burn-in or mixing time considerations.

The CFTP algorithm is particularly useful when dealing with models that exhibit irreducibility and aperiodicity, as it guarantees that the generated samples will be distributed according to the stationary distribution of the Markov chain. This property makes CFTP advantageous for tasks such as Bayesian inference, where obtaining samples from the target distribution is crucial.

The main idea behind the CFTP algorithm is to simulate the entire history of the Markov chain from the infinite past until the present, without requiring any knowledge about the initial state of the chain. By effectively coupling multiple copies of the Markov chain and letting them evolve simultaneously, the algorithm constructs a path that reaches the stationary distribution. Once this path is established, the samples generated at different time points along the path can be treated as independent samples from the stationary distribution.

CFTP Sampling pseudocode

  1. Initialize system to time t = 0.
  2. Set t = 1.
  3. Initialize an empty history array, H = [].
  4. Generate an initial state, X, for the system at time t.
  5. Append X to H: H.append(X).
  6. Repeat steps 7-10 until t = T:
    7. Generate a proposal state, Y, for the system at time t.
    8. Compute the acceptance probability, p = min(1, P(Y)/P(X)), where P(.) is the target distribution.
    9. Generate a random number, u, from a uniform distribution between 0 and 1.
    10. If u <= p, set X = Y; otherwise, set X = X.
    11. Append X to H: H.append(X).
    12. Increment t: t = t + 1.
  7. Set t = T - 1.
  8. Repeat steps 7-12 until t = 0:
    9. Generate a proposal state, Y, for the system at time t.
    10. Compute the acceptance probability, p = min(1, P(Y)/P(X)).
    11. Generate a random number, u, from a uniform distribution between 0 and 1.
    12. If u <= p, set X = Y; otherwise, set X = X.
    13. Append X to H: H.append(X).
    14. Decrement t: t = t - 1.
  9. The final history array, H, contains a sample from the target distribution at time T.

cftp-sampling's People

Contributors

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