mealy 0.4.2 → 0.4.3
raw patch · 4 files changed
+88/−48 lines, 4 filesdep ~numhaskdep ~numhask-arraydep ~tdigest
Dependency ranges changed: numhask, numhask-array, tdigest
Files
- mealy.cabal +77/−14
- src/Data/Mealy.hs +9/−25
- src/Data/Mealy/Quantiles.hs +2/−3
- src/Data/Mealy/Simulate.hs +0/−6
mealy.cabal view
@@ -1,6 +1,6 @@-cabal-version: 2.4+cabal-version: 3.0 name: mealy-version: 0.4.2+version: 0.4.3 license: BSD-3-Clause copyright: Tony Day (c) 2013 - 2022 maintainer: tonyday567@gmail.com@@ -11,44 +11,107 @@ description: @mealy@ provides support for computing statistics (such as an average or a standard deviation) as current state. Usage is to supply a decay function representing the relative weights of recent values versus older ones, in the manner of exponentially-weighted averages. The library attempts to be polymorphic in the statistic which can be combined in applicative style.- .+ == Usage- .+ >>> import Mealy- .+ >>> fold ((,) <$> ma 0.9 <*> std 0.9) [1..100] (91.00265621044142,9.472822805289121) category: folding build-type: Simple-tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.2.5 || ==9.4.4+tested-with: GHC == 8.10.7 || ==9.2.8 || ==9.4.5 || ==9.6.2 source-repository head type: git location: https://github.com/tonyday567/mealy +common ghc2021-stanza+ if impl(ghc >=9.2)+ default-language:+ GHC2021+ if impl(ghc <9.2)+ default-language:+ Haskell2010+ default-extensions:+ BangPatterns+ BinaryLiterals+ ConstrainedClassMethods+ ConstraintKinds+ DeriveDataTypeable+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveLift+ DeriveTraversable+ DoAndIfThenElse+ EmptyCase+ EmptyDataDecls+ EmptyDataDeriving+ ExistentialQuantification+ ExplicitForAll+ FlexibleContexts+ FlexibleInstances+ ForeignFunctionInterface+ GADTSyntax+ GeneralisedNewtypeDeriving+ HexFloatLiterals+ ImplicitPrelude+ InstanceSigs+ KindSignatures+ MonomorphismRestriction+ MultiParamTypeClasses+ NamedFieldPuns+ NamedWildCards+ NumericUnderscores+ PatternGuards+ PolyKinds+ PostfixOperators+ RankNTypes+ RelaxedPolyRec+ ScopedTypeVariables+ StandaloneDeriving+ StarIsType+ TraditionalRecordSyntax+ TupleSections+ TypeApplications+ TypeOperators+ TypeSynonymInstances+ if impl(ghc <9.2) && impl(ghc >=8.10)+ default-extensions:+ ImportQualifiedPost+ StandaloneKindSignatures++common ghc-options-stanza+ ghc-options:+ -Wall+ -Wcompat+ -Wincomplete-record-updates+ -Wincomplete-uni-patterns+ -Wredundant-constraints+ -Widentities+ -Wpartial-fields+ library+ import: ghc2021-stanza+ import: ghc-options-stanza exposed-modules: Data.Mealy Data.Mealy.Quantiles Data.Mealy.Simulate hs-source-dirs: src- default-language: Haskell2010- ghc-options:- -Wall -Wcompat -Wincomplete-record-updates- -Wincomplete-uni-patterns -Wredundant-constraints- build-depends: , adjunctions ^>=4.4 , base >=4.12 && <5 , containers ^>=0.6.2 , mwc-probability ^>=2.3.1- , numhask ^>=0.10- , numhask-array ^>=0.10.1+ , numhask >=0.10 && <0.12+ , numhask-array >=0.10.1 && <0.12 , primitive >=0.7.2 && <0.9 , profunctors ^>=5.6.2- , tdigest ^>=0.2.1+ , tdigest >=0.2.1 && <4 , text >=1.2.4 && <2.1 , vector >=0.12.3 && <0.14 , vector-algorithms >=0.8.0 && <0.10
src/Data/Mealy.hs view
@@ -1,25 +1,8 @@-{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-}-{-# LANGUAGE DeriveFunctor #-}-{-# LANGUAGE DerivingVia #-}-{-# LANGUAGE DuplicateRecordFields #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE KindSignatures #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternSynonyms #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE StrictData #-}-{-# LANGUAGE TupleSections #-}+{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE NoImplicitPrelude #-}-{-# OPTIONS_GHC -Wall #-}-{-# OPTIONS_GHC -Wno-incomplete-patterns #-}-{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}-{-# OPTIONS_GHC -Wno-name-shadowing #-}-{-# OPTIONS_GHC -Wno-orphans #-}-{-# OPTIONS_GHC -Wno-type-defaults #-} -- | Online statistics for ordered data (such as time-series data), modelled as [mealy machines](https://en.wikipedia.org/wiki/Mealy_machine) module Data.Mealy@@ -72,7 +55,7 @@ import Data.List (scanl') import Data.Profunctor import Data.Sequence (Seq)-import qualified Data.Sequence as Seq+import Data.Sequence qualified as Seq import Data.Text (Text) import Data.Typeable (Typeable) import GHC.TypeLits@@ -176,6 +159,7 @@ {-# COMPLETE M #-} +-- | Create a Mealy from a (pure) function dipure :: (a -> a -> a) -> Mealy a a dipure f = M id f id @@ -273,7 +257,7 @@ -- -- >>> fold (absma 1) xs0 -- 0.8075705557429647-absma :: (Divisive a, Signed a) => a -> Mealy a a+absma :: (Divisive a, Absolute a) => a -> Mealy a a absma r = online abs (* r) {-# INLINEABLE absma #-} @@ -420,12 +404,12 @@ -- extract :: Averager (RegressionState n a) a -> (F.Array '[n] a) extract (A (RegressionState xx x xy y) c) = (\a b -> recip a `F.mult` b)- ((one / c) .* (xx - F.expand (*) x x))- ((xy - (y .* x)) *. (one / c))+ ((one / c) *| (xx - F.expand (*) x x))+ ((xy - (y *| x)) |* (one / c)) step x (xs, y) = rsOnline r x (inject (xs, y)) -- inject :: (F.Array '[n] a, a) -> Averager (RegressionState n a) a inject (xs, y) =- A (RegressionState (F.expand (*) xs xs) xs (y .* xs) y) one+ A (RegressionState (F.expand (*) xs xs) xs (y *| xs) y) one {-# INLINEABLE beta #-} rsOnline :: (Field a, KnownNat n) => a -> Averager (RegressionState n a) a -> Averager (RegressionState n a) a -> Averager (RegressionState n a) a@@ -519,7 +503,7 @@ -- | onlineL1' takes a function and turns it into a `Mealy` where the step is an incremental update of an (isomorphic) median statistic. onlineL1 ::- (Ord b, Field b, Signed b) => b -> b -> (a -> b) -> (b -> b) -> Mealy a b+ (Ord b, Field b, Absolute b) => b -> b -> (a -> b) -> (b -> b) -> Mealy a b onlineL1 i d f g = snd <$> M inject step extract where inject a = let s = abs (f a) in Medianer s one (i * s)@@ -543,6 +527,6 @@ -- | moving median -- > L.fold (maL1 inc d r) [1..n] -- 93.92822312742108-maL1 :: (Ord a, Field a, Signed a) => a -> a -> a -> Mealy a a+maL1 :: (Ord a, Field a, Absolute a) => a -> a -> a -> Mealy a a maL1 i d r = onlineL1 i d id (* r) {-# INLINEABLE maL1 #-}
src/Data/Mealy/Quantiles.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE RebindableSyntax #-}-{-# LANGUAGE StrictData #-} -- | Mealy quantile statistics. module Data.Mealy.Quantiles@@ -16,8 +15,8 @@ import Data.TDigest hiding (median) import Data.TDigest.Internal import Data.TDigest.Tree.Internal (TDigest (..), absMaxSize, emptyTDigest, insertCentroid, relMaxSize, size, toMVector)-import qualified Data.Vector.Algorithms.Heap as VHeap-import qualified Data.Vector.Unboxed as VU+import Data.Vector.Algorithms.Heap qualified as VHeap+import Data.Vector.Unboxed qualified as VU import NumHask.Prelude hiding (fold) data OnlineTDigest = OnlineTDigest
src/Data/Mealy/Simulate.hs view
@@ -1,10 +1,4 @@-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE ExtendedDefaultRules #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE RankNTypes #-} {-# LANGUAGE NoImplicitPrelude #-}-{-# OPTIONS_GHC -Wall #-}-{-# OPTIONS_GHC -fno-warn-type-defaults #-} -- | simulation to support testing of Mealy's using mwc-probability module Data.Mealy.Simulate