Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
47
Task/Probabilistic-choice/Haskell/probabilistic-choice.hs
Normal file
47
Task/Probabilistic-choice/Haskell/probabilistic-choice.hs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import System.Random (newStdGen, randomRs)
|
||||
|
||||
dataBinCounts :: [Float] -> [Float] -> [Int]
|
||||
dataBinCounts thresholds range =
|
||||
zipWith
|
||||
(-)
|
||||
(xs <> [sampleSize])
|
||||
(0 : xs)
|
||||
where
|
||||
sampleSize = length range
|
||||
xs =
|
||||
(-) sampleSize . length
|
||||
. flip filter range
|
||||
. (<)
|
||||
<$> thresholds
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main = do
|
||||
g <- newStdGen
|
||||
let fractions = recip <$> [5 .. 11] :: [Float]
|
||||
expected = fractions <> [1 - sum fractions]
|
||||
actual =
|
||||
(/ 1000000.0) . fromIntegral
|
||||
<$> dataBinCounts
|
||||
(scanl1 (+) expected)
|
||||
(take 1000000 (randomRs (0, 1) g))
|
||||
piv n x = take n (x <> repeat ' ');
|
||||
|
||||
putStrLn " expected actual"
|
||||
mapM_ putStrLn $
|
||||
zipWith3
|
||||
( \l s c ->
|
||||
piv 7 l
|
||||
<> (piv 13 (show s) <> piv 12 (show c))
|
||||
)
|
||||
[ "aleph",
|
||||
"beth",
|
||||
"gimel",
|
||||
"daleth",
|
||||
"he",
|
||||
"waw",
|
||||
"zayin",
|
||||
"heth"
|
||||
]
|
||||
expected
|
||||
actual
|
||||
Loading…
Add table
Add a link
Reference in a new issue