Last active
January 1, 2016 20:39
-
-
Save andresilva/8198607 to your computer and use it in GitHub Desktop.
Monty Hall Problem using PFP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz.syntax.monad._ | |
import spire.math._ | |
import spire.implicits._ | |
import pfp.Distribution._ | |
// data Outcome = Win | Lose | |
sealed trait Outcome | |
case object Win extends Outcome | |
case object Lose extends Outcome | |
// firstChoice :: Dist Outcome | |
// firstChoice = uniform [Win,Lose,Lose] | |
def firstChoice = uniform[Outcome, Rational].apply(Win :: Lose :: Lose :: Nil) | |
// switch :: Trans Outcome | |
// switch Win = certainly Lose | |
// switch Lose = certainly Win | |
def switch(o: Outcome) = o match { | |
case Win => certainly[Outcome, Rational](Lose) | |
case Lose => certainly[Outcome, Rational](Win) | |
} | |
firstChoice.plot | |
// | |
// Win 1/3 ################################# | |
// Lose 2/3 ################################################################## | |
// | |
(firstChoice >>= switch).plot | |
// | |
// Win 2/3 ################################################################## | |
// Lose 1/3 ################################# | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment