diff options
author | Justin Bedo <cu@cua0.org> | 2023-01-17 17:41:57 +1100 |
---|---|---|
committer | Justin Bedo <cu@cua0.org> | 2023-01-17 21:28:02 +1100 |
commit | 5db331b67582a92d00fdf9a11973fe66c5f19218 (patch) | |
tree | 2740ee99407c93723971d2dff5a3026c87ecf09b /bin | |
parent | 67309843bae5bfb88c7416f89809e38a400da209 (diff) |
compact data structure
Diffstat (limited to 'bin')
-rw-r--r-- | bin/cluster.hs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/bin/cluster.hs b/bin/cluster.hs index 4d67541..dd8f2c6 100644 --- a/bin/cluster.hs +++ b/bin/cluster.hs @@ -7,6 +7,7 @@ import Data.Fixed (mod') import Data.Foldable (toList) import Data.List import qualified Data.Map as M +import GHC.Compact import Numeric.Log hiding (sum) import Options.Applicative import PPL @@ -94,7 +95,7 @@ drawGraph path ps cl = writeFile path $ "digraph{" <> edges <> "}" -- Normalise to frequency of parent norm :: [Double] -> [Double] - norm xxs@(x : xs) = x : zipWith (\i y -> y / xxs !! parent i) [1..] xs + norm xxs@(x : xs) = x : zipWith (\i y -> y / xxs !! parent i) [1 ..] xs -- Command line args data Options = Options @@ -129,9 +130,9 @@ main = run =<< execParser opts run opts = do setStdGen . mkStdGen $ seed opts (hdr : lines) <- lines <$> readFile (input opts) - let parsed = map (map dbl . tail . words) lines - dbl = round . read :: String -> Int - ((ps, cl), _) <- foldl1' (\a c -> if mml a < mml c then a else c) . take (nsamples opts) <$> mh (mhfrac opts) (model parsed) + let dbl = round . read :: String -> Int + parsed <- compact $ map (map dbl . tail . words) lines + ((ps, cl), _) <- foldl1' (\a c -> if mml a < mml c then a else c) . take (nsamples opts) <$> mh (mhfrac opts) (model $ getCompact parsed) writeFile (propsPath opts) . unlines $ map (intercalate "," . map show) ps writeFile (clusterPath opts) . unlines $ map show cl when (dotPath opts /= "") $ drawGraph (dotPath opts) ps cl |