packages feed

numhask-space 0.3.0 → 0.3.1

raw patch · 4 files changed

+16/−14 lines, 4 files

Files

numhask-space.cabal view
@@ -1,5 +1,5 @@ name: numhask-space-version: 0.3.0+version: 0.3.1 synopsis:   numerical spaces description:
src/NumHask/Space/Histogram.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE DataKinds #-}-{-# LANGUAGE TupleSections #-} {-# OPTIONS_GHC -Wall #-}  -- | A histogram, if you squint, is a series of contiguous ranges, annotated with values.@@ -7,6 +6,7 @@   ( Histogram (..),     DealOvers (..),     fill,+    cutI,     regular,     makeRects,     regularQuantiles,@@ -17,6 +17,8 @@ where  import qualified Control.Foldl as L+import Data.Bool+import Data.Foldable import qualified Data.List import qualified Data.Map as Map import Data.Maybe@@ -43,15 +45,15 @@ -- -- >>> fill [0,50,100] [1..100] -- Histogram {cuts = [0.0,50.0,100.0], values = fromList [(1,50.0),(2,50.0)]}-fill :: (Functor f, Foldable f) => [Double] -> f Double -> Histogram-fill cs xs = Histogram cs (histMap cs xs)+fill :: (Foldable f) => [Double] -> f Double -> Histogram+fill cs xs = Histogram cs (foldl' (\x a -> Map.insertWith (+) (cutI cs a) 1 x) Map.empty xs)++-- | find the index of the bucket the value is contained in.+cutI :: (Ord a) => [a] -> a -> Int+cutI bs n = go bs 0   where-    histMap cs' xs' =-      L.fold count $-        (\x -> L.fold countBool (fmap (x >) cs')) <$> xs'-    count = L.premap (,1.0) countW-    countBool = L.Fold (\x a -> x + if a then 1 else 0) 0 id-    countW = L.Fold (\x (a, w) -> Map.insertWith (+) a w x) Map.empty id+    go [] i = i+    go (x:xs) i = bool i (go xs (i+1)) (n>x)  -- | Make a histogram using n equally spaced cuts over the entire range of the data --
src/NumHask/Space/Time.hs view
@@ -18,7 +18,6 @@ import qualified Data.Text as Text import Data.Text (Text) import Data.Time-import GHC.Base (String) import GHC.Generics import NumHask.Space.Types import Prelude@@ -204,7 +203,7 @@ -- | whether to include lower and upper times data PosDiscontinuous = PosInnerOnly | PosIncludeBoundaries --- | dates attached to charts are often discontinuous, but we want to smooth that reality over and show a continuous range on the axis+-- | dates used for time series analysis or attached to charts are often discontinuous, but we want to smooth that reality over and show a continuous range on the axis -- The assumption with getSensibleTimeGrid is that there is a list of discountinuous UTCTimes rather than a continuous range.  Output is a list of index points for the original [UTCTime] and label tuples, and a list of unused list elements. -- -- >>> placedTimeLabelDiscontinuous PosIncludeBoundaries (Just "%d %b") 2 [UTCTime (fromGregorian 2017 12 6) 0, UTCTime (fromGregorian 2017 12 29) 0, UTCTime (fromGregorian 2018 1 31) 0, UTCTime (fromGregorian 2018 3 3) 0]
src/NumHask/Space/Types.hs view
@@ -28,6 +28,7 @@ where  import Prelude+import Data.Kind (Type)  -- | Space is a continuous range of numbers that contains elements and has an upper and lower value. --@@ -42,7 +43,7 @@ class Space s where    -- | the underlying element in the space-  type Element s :: *+  type Element s :: Type    -- | lower boundary   lower :: s -> Element s@@ -162,7 +163,7 @@ -- > getUnion (sconcat (Union <$> (gridSpace s g))) == s class (Space s, Num (Element s)) => FieldSpace s where -  type Grid s :: *+  type Grid s :: Type    -- | create equally-spaced elements across a space   grid :: Pos -> s -> Grid s -> [Element s]