packages feed

uncertain 0.3.0.0 → 0.3.1.0

raw patch · 7 files changed

+60/−48 lines, 7 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Numeric.Uncertain: instance GHC.Generics.Constructor Numeric.Uncertain.C1_0Uncert
- Numeric.Uncertain: instance GHC.Generics.Datatype Numeric.Uncertain.D1Uncert
- Numeric.Uncertain: instance GHC.Generics.Selector Numeric.Uncertain.S1_0_0Uncert
- Numeric.Uncertain: instance GHC.Generics.Selector Numeric.Uncertain.S1_0_1Uncert
+ Numeric.Uncertain: infixl 6 +/-
- Numeric.Uncertain.Correlated: liftC :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated: liftC :: (forall t. AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated: liftC2 :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated: liftC2 :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated: liftC3 :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated: liftC3 :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated: liftC4 :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated: liftC4 :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated: liftC5 :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated: liftC5 :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated: liftCF :: (Functor f, Fractional a) => (forall t. f (AD t (Sparse a)) -> AD t (Sparse a)) -> f (CVar s a) -> CVar s a
+ Numeric.Uncertain.Correlated: liftCF :: Functor f => (forall t. f (AD t (Sparse a)) -> AD t (Sparse a)) -> f (CVar s a) -> CVar s a
- Numeric.Uncertain.Correlated.Interactive: liftC :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated.Interactive: liftC :: (forall t. AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated.Interactive: liftC2 :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated.Interactive: liftC2 :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated.Interactive: liftC3 :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated.Interactive: liftC3 :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated.Interactive: liftC4 :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated.Interactive: liftC4 :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated.Interactive: liftC5 :: Fractional a => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a
+ Numeric.Uncertain.Correlated.Interactive: liftC5 :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a)) -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a -> CVar s a
- Numeric.Uncertain.Correlated.Interactive: liftCF :: (Functor f, Fractional a) => (forall t. f (AD t (Sparse a)) -> AD t (Sparse a)) -> f (CVar s a) -> CVar s a
+ Numeric.Uncertain.Correlated.Interactive: liftCF :: Functor f => (forall t. f (AD t (Sparse a)) -> AD t (Sparse a)) -> f (CVar s a) -> CVar s a
- Numeric.Uncertain.MonteCarlo: sampleUncert :: (PrimMonad m, Functor m) => Uncert Double -> Gen (PrimState m) -> m Double
+ Numeric.Uncertain.MonteCarlo: sampleUncert :: PrimMonad m => Uncert Double -> Gen (PrimState m) -> m Double

Files

CHANGELOG.md view
@@ -1,17 +1,28 @@-Changelog-=========+Version 0.3.1.0+=============== +<https://github.com/mstksg/uncertain/releases/tag/v0.3.1.0>++*   Added support for *GHC 8.0* by providing pattern synonym type signatures in+    the proper format.+*   `(:+/-)` pattern synonym now exported as a "constructor" with `Uncert`+*   Generalized the type signatures for `liftCX` functions to work for all `a`.+    Restriction to `Fractional` now occurs only at exit points of the `CVar`+    abstraction.+*   Removed the redundant constraint on `Functor m` for the *MonteCarlo*+    module's `liftUX` functions.+ Version 0.3.0.0----------------+===============  <https://github.com/mstksg/uncertain/releases/tag/v0.3.0.0> -*   **(Breaking change)** Moved the top-level modules from `Data` to `Numeric`,+*   **(Breaking change)** Moved the top-level modules from *Data* to *Numeric*,     to better reflect the nature of the library and to align with the     convention of other similar libraries.  Version 0.2.0.0----------------+===============  <https://github.com/mstksg/uncertain/releases/tag/v0.2.0.0> 
README.md view
@@ -21,10 +21,10 @@ 7.13 +/- 0.05 91800 +/- 100 12.5 `withVar` 0.36-'exact' 7.9512+exact 7.9512 81.42 `withPrecision` 4-7    :: Uncertain Double-9.18 :: Uncertain Double+7    :: Uncert Double+9.18 :: Uncert Double fromSamples [12.5, 12.7, 12.6, 12.6, 12.5] ``` @@ -138,7 +138,7 @@ 91. +/- 7. ``` -In a library like [interval], this would result in `91 +/- 10` (that is, a+In a library like [intervals][], this would result in `91 +/- 10` (that is, a lower bound of 46 + 35 and an upper bound of 58 + 43).  However, with experimental data, errors in two independent samples tend to "cancel out", and result in an overall aggregate uncertainty in the sum of approximately 7.
src/Numeric/Uncertain.hs view
@@ -24,10 +24,14 @@  module Numeric.Uncertain   ( -- * 'Uncert'+#if __GLASGOW_HASKELL__ >= 810+    Uncert((:+/-))+#else     Uncert #if __GLASGOW_HASKELL__ >= 708   , pattern (:+/-) #endif+#endif     -- ** Creating 'Uncert' values   , (+/-), exact, withPrecision, withPrecisionAtBase, withVar, fromSamples     -- ** Inspecting properties@@ -131,7 +135,7 @@                    }   deriving (Data, Typeable, Generic, Generic1) --- | Get the mean/central value/expected value of an 'Uncert'.+-- | Get the mean (central) value of an 'Uncert'. uMean :: Uncert a -> a uMean = _uMean {-# INLINE uMean #-}@@ -205,7 +209,9 @@ -- functionality (to allow use as a constructor) only supported on GHC -- 7.10 and above. ---#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 800+pattern (:+/-) :: Floating a => a -> a -> Uncert a+#elif __GLASGOW_HASKELL__ >= 710 pattern (:+/-) :: () => Floating a => a -> a -> Uncert a #endif pattern x :+/- dx <- Un x (sqrt->dx)@@ -362,7 +368,7 @@ -- you can use things like '*', 'sqrt', 'atan2', etc. -- -- @--- ghci> liftUF (\[x,y,z] -> x*y+z) [12.2 +/- 0.5, 56 +/- 2, 0.12 +/- 0.08]+-- ghci> liftUF (\\[x,y,z] -> x*y+z) [12.2 +/- 0.5, 56 +/- 2, 0.12 +/- 0.08] -- 680 +/- 40 -- @ --@@ -405,7 +411,7 @@ -- you can use things like 'sqrt', 'sin', 'negate', etc. -- -- @--- ghci> liftU (\x -> log x ^ 2) (12.2 +/- 0.5)+-- ghci> liftU (\\x -> log x ^ 2) (12.2 +/- 0.5) -- 6.3 +/- 0.2 -- @ liftU@@ -430,7 +436,7 @@ -- you can use things like '*', 'atan2', '**', etc. -- -- @--- ghci> liftU2 (\x y -> x**y) (13.5 +/- 0.1) (1.64 +/- 0.08)+-- ghci> liftU2 (\\x y -> x**y) (13.5 +/- 0.1) (1.64 +/- 0.08) -- 70 +/- 10 -- @ liftU2
src/Numeric/Uncertain/Correlated/Interactive.hs view
@@ -14,8 +14,8 @@ -- For example, with the "Numeric.Uncertain.Correlated" interface: -- -- @--- ghci> evalCorr $ do---         x <- sampleUncert $ 12.5 +/- 0.8+-- ghci> 'evalCorr' $ do+--         x <- sampleUncert $ 12.5 '+/-' 0.8 --         y <- sampleUncert $ 15.9 +/- 0.5 --         z <- sampleUncert $ 1.52 +/- 0.07 --         let k = y**x@@ -43,8 +43,8 @@ -- have both imported at the same time in /ghci/ or in a file, or import -- them qualified if you must. ----- Also note that all of these methods only work with @'Uncertain'--- 'Double'@s, and are not polymorphic over different numeric types.+-- Also note that all of these methods only work with @'Uncert' 'Double'@s,+-- and are not polymorphic over different numeric types. -- -- Be aware that this module is not robustly tested in heavily concurrent -- situations/applications.
src/Numeric/Uncertain/Correlated/Internal.hs view
@@ -120,7 +120,7 @@ --         y1 <- 'resolveUncert' $ sum (replicate 10 x) --         y2 <- resolveUncert $ 10 * x --         return (y1, y2)--- (125 +/- 8, 125 +/- 8)+-- (125 +\/- 8, 125 +\/- 8) -- -- ghci> 'evalCorr' $ do --         xs <- replicateM 10 ('sampleUncert' (12.5 +/- 0.8))@@ -147,7 +147,7 @@ -- The first parameter is a dummy phantom parameter used to prevent 'CVar's -- from leaking out of the computation (see 'evalCorr').  The second -- parameter is the numeric type of all samples within the description (for--- example, if you ever sample an 'Uncert Double', the second parameter wil+-- example, if you ever sample an @'Uncert' 'Double'@, the second parameter wil -- be 'Double').  The third parameter is the result type of the -- computation -- the value the 'Corr' is describing. newtype Corr s a b = Corr { corrFree :: Free (CorrF s a) b@@ -199,16 +199,16 @@ -- you can use things like '*', 'sqrt', 'atan2', etc. -- -- @--- ghci> evalCorr $ do---         x <- sampleUncert $ 12.5 +/- 0.8+-- ghci> 'evalCorr' $ do+--         x <- 'sampleUncert' $ 12.5 '+/-' 0.8 --         y <- sampleUncert $ 15.9 +/- 0.5 --         z <- sampleUncert $ 1.52 +/- 0.07---         resolveUncert $ liftCF (\[a,b,c] -> (a+c) * logBase c (b**a)) x y z+--         'resolveUncert' $ liftCF (\\[a,b,c] -> (a+c) * logBase c (b**a)) x y z -- 1200 +/- 200 -- @ -- liftCF-    :: (Functor f, Fractional a)+    :: Functor f     => (forall t. f (AD t (Sparse a)) -> AD t (Sparse a)) -- ^ Function on container of values to lift     -> f (CVar s a)     -- ^ Container of 'CVar' samples to apply the function to     -> CVar s a@@ -231,16 +231,15 @@ -- you can use things like 'sqrt', 'sin', 'negate', etc. -- -- @--- ghci> evalCorr $ do---         x <- sampleUncert $ 12.5 +/- 0.8+-- ghci> 'evalCorr' $ do+--         x <- 'sampleUncert' $ 12.5 '+/-' 0.8 --         y <- sampleUncert $ 15.9 +/- 0.5---         resolveUncert $ liftC (\z -> log z ^ 2) (x + y)+--         'resolveUncert' $ liftC (\\z -> log z ^ 2) (x + y) -- 11.2 +/- 0.2 -- @ -- liftC-    :: Fractional a-    => (forall t. AD t (Sparse a) -> AD t (Sparse a)) -- ^ Function on values to lift+    :: (forall t. AD t (Sparse a) -> AD t (Sparse a)) -- ^ Function on values to lift     -> CVar s a         -- ^ 'CVar' sample to apply the function to     -> CVar s a liftC f = curryH1 $ liftCF (uncurryH1 f)@@ -258,16 +257,15 @@ -- you can use things like '*', 'atan2', '**', etc. -- -- @--- ghci> evalCorr $ do---         x <- sampleUncert $ 12.5 +/- 0.8+-- ghci> 'evalCorr' $ do+--         x <- 'sampleUncert' $ 12.5 '+/-' 0.8 --         y <- sampleUncert $ 15.9 +/- 0.5---         resolveUncert $ liftC2 (\a b -> log (a + b) ^ 2) x y+--         'resolveUncert' $ liftC2 (\\a b -> log (a + b) ^ 2) x y -- 11.2 +/- 0.2 -- @ -- liftC2-    :: Fractional a-    => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a))+    :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a))     -> CVar s a     -> CVar s a     -> CVar s a@@ -277,8 +275,7 @@ -- | Lifts a three-argument (curried) function over the samples represented -- by three 'CVar's.  See 'liftC2' and 'liftCF' for more details. liftC3-    :: Fractional a-    => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a))+    :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a))     -> CVar s a     -> CVar s a     -> CVar s a@@ -289,8 +286,7 @@ -- | Lifts a four-argument (curried) function over the samples represented -- by four 'CVar's.  See 'liftC2' and 'liftCF' for more details. liftC4-    :: Fractional a-    => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a))+    :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a))     -> CVar s a     -> CVar s a     -> CVar s a@@ -302,8 +298,7 @@ -- | Lifts a five-argument (curried) function over the samples represented -- by five 'CVar's.  See 'liftC2' and 'liftCF' for more details. liftC5-    :: Fractional a-    => (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a))+    :: (forall t. AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a) -> AD t (Sparse a))     -> CVar s a     -> CVar s a     -> CVar s a
src/Numeric/Uncertain/MonteCarlo.hs view
@@ -47,11 +47,11 @@ -- 2.4 +/- 0.2 -- ghci> exp x / z * sin (y ** z) -- 10.9 +/- 0.9--- ghci> MC.liftU3 (\a b c -> exp a / c * sin (b**c)) x y z g+-- ghci> MC.liftU3 (\\a b c -> exp a / c * sin (b**c)) x y z g -- 10.8 +/- 1.0 -- ghci> pi + 3 * logBase x y -- 52 +/- 5--- ghci> MC.liftU2 (\a b -> pi + 3 * logBase a b) x y g+-- ghci> MC.liftU2 (\\a b -> pi + 3 * logBase a b) x y g -- 51 +/- 5 -- @ --@@ -83,9 +83,9 @@ -- sampleUncert #if __GLASGOW_HASKELL__ < 710-    :: PrimMonad m-#else     :: (PrimMonad m, Functor m)+#else+    :: PrimMonad m #endif     => Uncert Double     -> Gen (PrimState m)@@ -98,7 +98,7 @@ -- -- @ -- ghci> g <- 'create'--- ghci> MC.liftU (\x -> log x ^ 2) (12.2 +/- 0.5) g+-- ghci> MC.liftU (\\x -> log x ^ 2) (12.2 +/- 0.5) g -- 6.3 +/- 0.2 -- @ --@@ -121,7 +121,7 @@ -- -- @ -- ghci> g <- 'create'--- ghci> M.liftUF (\[x,y,z] -> x*y+z) [12.2 +/- 0.5, 56 +/- 2, 0.12 +/- 0.08] g+-- ghci> M.liftUF (\\[x,y,z] -> x*y+z) [12.2 +/- 0.5, 56 +/- 2, 0.12 +/- 0.08] g -- 680 +/- 40 -- @ --@@ -143,7 +143,7 @@ -- -- @ -- ghci> g <- 'create'--- ghci> MC.liftU2 (\x y -> x**y) (13.5 +/- 0.1) (1.64 +/- 0.08)+-- ghci> MC.liftU2 (\\x y -> x**y) (13.5 +/- 0.1) (1.64 +/- 0.08) -- 70 +/- 20 -- @ --
uncertain.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                uncertain-version:             0.3.0.0+version:             0.3.1.0 synopsis:            Manipulating numbers with inherent experimental/measurement uncertainty description:         See <https://github.com/mstksg/uncertain/blob/master/README.md README.md>.                      .