Skip to content

Instantly share code, notes, and snippets.

Created September 18, 2014 20:42
Show Gist options
  • Save anonymous/b31ba4668d920692485f to your computer and use it in GitHub Desktop.
Save anonymous/b31ba4668d920692485f to your computer and use it in GitHub Desktop.
series win probability
import Data.List
import Control.Monad
import Data.Function
space = 10
ranks = [1..(space-1)]
matchResult rank = take 10 (take rank [1,1..] ++ [0,0..])
getPosterior::Int->Int->Int->Double
getPosterior wins losses rank = matches/all where
result = sequence.replicate (wins+losses).matchResult$rank
all = fromIntegral.length$result
condition x = sum x == wins
matches = fromIntegral.length.filter condition$result
normalize::[Double]->[Double]
normalize a = map (/s) a where
s = (sum a)
getProbability::Int->Int->Int->Double
getProbability games mustWin rank = wins/all where
result = sequence.replicate games.matchResult$rank
all = fromIntegral.length$result
isWin x = sum x >= mustWin
wins = fromIntegral.length.filter isWin$result
result wins losses toWinsWin = sum.zipWith (*) posterior$probability where
posterior = normalize.map (getPosterior wins losses)$ranks
mustWin = toWinsWin - wins
games = toWinsWin - losses - 1 + mustWin
probability = map (getProbability games mustWin) ranks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment