Giter Club home page Giter Club logo

babygiry's Introduction

BabyGiry -- A Probability Monad for Elementary Probability in Lean

This project aims to demonstrate how to "do probability with monads" using a simple toy version of the Giry monad. It allows you to define conditional probability distributions using "randomly do" blocks of the form:

def Posterior : Random ℚ := randomly do
  let p <-~ Unif (Linspace 0 1) -- "Let p be uniformly distributed on {0/10, 1/10, ..., 10/10}.
  let k <-~ Binomial 5 p -- Let k be the number of successes in 5 Bernoulli trials with success probability p.
  observe <| k = 3 -- Observe that k = 3.
  return p

-- #eval ℙ[p ≥ 4/10 ∧ p ≤ 6/10 | p ~ Posterior]
-- >> (1777 : Rat)/3333
-- #eval (1777 : Float)/3333
-- >> 0.533153

example : ℙ[p ≥ 4/10 ∧ p ≤ 6/10 | p ~ Posterior] = 1777/3333 := by rfl

In such a do block, "random variables" simply become dummy variables in a local context -- no need to fix a "background probability space" as usually done in classical probability theory to work with random variables.

The capability of computing conditional probabilities "automatically", by merely specifying a model, also illustrates the basic idea of a probabilistic programming language. See Examples.lean for more examples, including the famous Monty Hall Problem and a version of the Birthday Paradox.

babygiry's People

Contributors

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