This file contains hidden or 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
-- Context Tree Code | |
import System.Random | |
import Control.Monad | |
import Data.IORef | |
class Model m where | |
update :: m -> [Bool] -> Bool -> m | |
updateBlock :: m -> [Bool] -> [Bool] -> m | |
predict1 :: m -> [Bool] -> Bool -> Double | |
predictList :: m -> [Bool] -> [Bool] -> Double |
This file contains hidden or 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
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE ExistentialQuantification #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
module Graphics.Bling.Sampling ( | |
-- * Sampling Types | |
SampleWindow(..), Sampler, Sampled, mkRandomSampler, mkStratifiedSampler, | |
mkStratifiedSampler', |
This file contains hidden or 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 qualified Data.Map as M -- cabal install unordered-containers | |
import qualified Data.ByteString.Char8 as B | |
import Data.List (foldl') | |
main = B.interact $ exhibit . foldl' updateCount M.empty . B.words | |
where exhibit counts = B.concat $ zipWith pretty keys_ counts_ where | |
counts_ = M.elems counts ; keys_ = M.keys counts | |
pretty w count = w +++ " :: " +++ show count +++ "\n" | |
updateCount m w = M.insertWith (+) w (1::Int) m |