From 5db331b67582a92d00fdf9a11973fe66c5f19218 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Tue, 17 Jan 2023 17:41:57 +1100 Subject: compact data structure --- bin/cluster.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bin') 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 -- cgit v1.2.3