Bryan O'Sullivan avatar Bryan O'Sullivan committed 3f8e3bc

Add Binary instances

Comments (0)

Files changed (20)

Statistics/Distribution/Beta.hs

   , bdBeta
   ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Numeric.SpecFunctions           (incompleteBeta, invIncompleteBeta, logBeta)
    -- ^ Beta shape parameter
  } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary BetaDistribution
+
 -- | Create beta distribution. Both shape parameters must be positive.
 betaDistr :: Double             -- ^ Shape parameter alpha
           -> Double             -- ^ Shape parameter beta

Statistics/Distribution/Binomial.hs

     , bdProbability
     ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import qualified Statistics.Distribution as D
     -- ^ Probability.
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary BinomialDistribution
+
 instance D.Distribution BinomialDistribution where
     cumulative = cumulative
 

Statistics/Distribution/CauchyLorentz.hs

   , standardCauchy
   ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import qualified Statistics.Distribution as D
   }
   deriving (Eq, Show, Read, Typeable, Data, Generic)
 
+instance Binary CauchyDistribution
+
 -- | Cauchy distribution
 cauchyDistribution :: Double    -- ^ Central point
                    -> Double    -- ^ Scale parameter (FWHM)

Statistics/Distribution/ChiSquared.hs

         , chiSquaredNDF
         ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Numeric.SpecFunctions (incompleteGamma,invIncompleteGamma,logGamma)
 newtype ChiSquared = ChiSquared Int
                      deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary ChiSquared
+
 -- | Get number of degrees of freedom
 chiSquaredNDF :: ChiSquared -> Int
 chiSquaredNDF (ChiSquared ndf) = ndf

Statistics/Distribution/Exponential.hs

     , edLambda
     ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import qualified Statistics.Distribution         as D
       edLambda :: Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary ExponentialDistribution
+
 instance D.Distribution ExponentialDistribution where
     cumulative      = cumulative
     complCumulative = complCumulative

Statistics/Distribution/FDistribution.hs

   , fDistributionNDF2
   ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import qualified Statistics.Distribution as D
                        }
                    deriving (Eq, Show, Read, Typeable, Data, Generic)
 
+instance Binary FDistribution
 
 fDistribution :: Int -> Int -> FDistribution
 fDistribution n m

Statistics/Distribution/Gamma.hs

     , gdScale
     ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Numeric.MathFunctions.Constants (m_pos_inf, m_NaN)
     , gdScale :: {-# UNPACK #-} !Double -- ^ Scale parameter, ϑ.
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary GammaDistribution
+
 -- | Create gamma distribution. Both shape and scale parameters must
 -- be positive.
 gammaDistr :: Double            -- ^ Shape parameter. /k/

Statistics/Distribution/Geometric.hs

     , gdSuccess
     ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import qualified Statistics.Distribution as D
       gdSuccess :: Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary GeometricDistribution
+
 instance D.Distribution GeometricDistribution where
     cumulative = cumulative
 

Statistics/Distribution/Hypergeometric.hs

     , hdK
     ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Numeric.SpecFunctions (choose)
     , hdK :: {-# UNPACK #-} !Int
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary HypergeometricDistribution
+
 instance D.Distribution HypergeometricDistribution where
     cumulative = cumulative
 

Statistics/Distribution/Normal.hs

     , standard
     ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Numeric.MathFunctions.Constants (m_sqrt_2, m_sqrt_2_pi)
     , ndCdfDenom :: {-# UNPACK #-} !Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary NormalDistribution
+
 instance D.Distribution NormalDistribution where
     cumulative      = cumulative
     complCumulative = complCumulative

Statistics/Distribution/Poisson.hs

     -- $references
     ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import qualified Statistics.Distribution as D
       poissonLambda :: Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary PoissonDistribution
+
 instance D.Distribution PoissonDistribution where
     cumulative (PD lambda) x
       | x < 0        = 0

Statistics/Distribution/StudentT.hs

   , studentTUnstandardized
   ) where
 
-
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import qualified Statistics.Distribution as D
 newtype StudentT = StudentT { studentTndf :: Double }
                    deriving (Eq, Show, Read, Typeable, Data, Generic)
 
+instance Binary StudentT
+
 -- | Create Student-T distribution. Number of parameters must be positive.
 studentT :: Double -> StudentT
 studentT ndf

Statistics/Distribution/Transform.hs

   , scaleAround
   ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Data.Functor          ((<$>))
     -- | Distribution being transformed.
   } deriving (Eq, Show, Read, Typeable, Data, Generic)
 
+instance (Binary d) => Binary (LinearTransform d)
+
 -- | Apply linear transformation to distribution.
 scaleAround :: Double           -- ^ Fixed point
             -> Double           -- ^ Scale parameter

Statistics/Distribution/Uniform.hs

     , uniformB
     ) where
 
+import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import qualified Statistics.Distribution as D
     , uniformB :: {-# UNPACK #-} !Double -- ^ Upper boundary of distribution
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary UniformDistribution
+
 -- | Create uniform distribution.
 uniformDistr :: Double -> Double -> UniformDistribution
 uniformDistr a b

Statistics/Math/RootFinding.hs

 
 import Statistics.Function.Comparison
 
+import Data.Binary (Binary)
 import Control.Applicative
 import Control.Monad       (MonadPlus(..), ap)
 import Data.Data (Data, Typeable)
             -- ^ A root was successfully found.
               deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance (Binary a) => Binary (Root a)
+
 instance Functor Root where
     fmap _ NotBracketed = NotBracketed
     fmap _ SearchFailed = SearchFailed

Statistics/Resampling.hs

 import Control.Concurrent (forkIO, newChan, readChan, writeChan)
 import Control.Monad (forM_, liftM, replicateM_)
 import Control.Monad.Primitive (PrimMonad, PrimState)
+import Data.Binary (Binary(..))
 import Data.Data (Data, Typeable)
 import Data.Vector.Algorithms.Intro (sort)
 import Data.Vector.Generic (unsafeFreeze)
       fromResample :: U.Vector Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary Resample where
+    put (Resample v) = put (U.toList v)
+    get = (Resample . U.fromList) `fmap` get
+
 -- | /O(e*r*s)/ Resample a data set repeatedly, with replacement,
 -- computing each estimate over the resampled data.
 --

Statistics/Resampling/Bootstrap.hs

 import Control.DeepSeq (NFData)
 import Control.Exception (assert)
 import Control.Monad.Par               (parMap,runPar)
+import Data.Binary (Binary)
 import Data.Data (Data)
 import Data.Typeable (Typeable)
 import Data.Vector.Unboxed ((!))
     -- ^ Confidence level of the confidence intervals.
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary Estimate
 instance NFData Estimate
 
 -- | Multiply the point, lower bound, and upper bound in an 'Estimate'

Statistics/Sample/KernelDensity/Simple.hs

     -- $references
     ) where
 
+import Data.Binary (Binary(..))
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Numeric.MathFunctions.Constants (m_1_sqrt_2, m_2_sqrt_pi)
       fromPoints :: U.Vector Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary Points where
+    put (Points v) = put (G.toList v)
+    get = (Points . G.fromList) `fmap` get
+
 -- | Bandwidth estimator for an Epanechnikov kernel.
 epanechnikovBW :: Double -> Bandwidth
 epanechnikovBW n = (80 / (n * m_2_sqrt_pi)) ** 0.2

Statistics/Sample/Powers.hs

     -- $references
     ) where
 
+import Data.Binary (Binary(..))
 import Data.Data (Data, Typeable)
 import Data.Vector.Generic   (unsafeFreeze)
 import Data.Vector.Unboxed   ((!))
 newtype Powers = Powers (U.Vector Double)
     deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance Binary Powers where
+    put (Powers v) = put (G.toList v)
+    get = (Powers . G.fromList) `fmap` get
+
 -- | O(/n/) Collect the /n/ simple powers of a sample.
 --
 -- Functions computed over a sample's simple powers require at least a
   .
   * Support for versions of GHC older than 7.2 is discontinued.
   .
-  * All datatypes support 'GHC.Generics'.
+  * All datatypes now support 'Data.Binary' and 'GHC.Generics'.
   .
   Changes in 0.10.3.0
   .
     Statistics.Test.Internal
   build-depends:
     base < 5,
+    binary >= 0.6.3.0,
     deepseq >= 1.1.0.2,
     erf,
     monad-par         >= 0.3.4,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.