packages feed

hstatistics 0.2.5 → 0.2.5.1

raw patch · 3 files changed

+24/−5 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGES view
@@ -97,3 +97,6 @@  0.2.5: 		Added pcaN as requested by Marcel Ruegenberg++0.2.5.1:+		added pcaReduceN to PCA
hstatistics.cabal view
@@ -1,8 +1,8 @@ Name:               hstatistics-Version:            0.2.5+Version:            0.2.5.1 License:            BSD3 License-file:       LICENSE-Copyright:          (c) A.V.H. McPhail 2010, 2011, 2012+Copyright:          (c) A.V.H. McPhail 2010, 2011, 2012, 2013 Author:             Vivian McPhail Maintainer:         haskell.vivian.mcphail <at> gmail <dot> com Stability:          provisional@@ -16,7 +16,7 @@      .      Feature requests, suggestions, and bug fixes welcome. Category:           Math, Statistics-tested-with:        GHC ==7.4.1+tested-with:        GHC ==7.6.3  cabal-version:      >=1.8 
lib/Numeric/Statistics/PCA.hs view
@@ -67,10 +67,11 @@ pcaTransform d m = let d' = fmap (\x -> x - (scalar $ mean x)) d -- remove the mean from each dimension                    in I.listArray (1,cols m) $ toRows $ (trans m) <> (fromRows $ I.elems d') --- | perform a dimension-reducing PCA modification+-- | perform a dimension-reducing PCA modification, +--     using an eigenvalue threshhold pcaReduce :: I.Array Int (Vector Double)      -- ^ the data           -> Double                           -- ^ eigenvalue threshold-          -> I.Array Int (Vector Double)      -- ^ the reduced data, with n principal components+          -> I.Array Int (Vector Double)      -- ^ the reduced data pcaReduce d q = let u = fmap (scalar . mean) d                     d' = zipWith (-) (I.elems d) (I.elems u)                     cv = covarianceMatrix $ I.listArray (I.bounds d) d'@@ -81,5 +82,20 @@                     v = filter (\(x,_) -> x > q) v'  -- keep only eigens > than parameter                     m = fromColumns $ snd $ unzip v                  in I.listArray (I.bounds d) $ zipWith (+) (toRows $ m <> (trans m) <> fromRows d') (I.elems u) ++-- | perform a dimension-reducing PCA modification, using N components+pcaReduceN :: I.Array Int (Vector Double)      -- ^ the data+           -> Int                              -- ^ N, the number of components+           -> I.Array Int (Vector Double)      -- ^ the reduced data, with n principal components+pcaReduceN d n = let u = fmap (scalar . mean) d+                     d' = zipWith (-) (I.elems d) (I.elems u)+                     cv = covarianceMatrix $ I.listArray (I.bounds d) d'+                     (val',vec') = eigSH cv           -- the covariance matrix is real symmetric+                     val = toList val'+                     vec = toColumns vec'+                     v' = zip val vec+                     v = take n $ reverse $ sortBy (comparing fst) v'+                     m = fromColumns $ snd $ unzip v+                  in I.listArray (I.bounds d) $ zipWith (+) (toRows $ m <> (trans m) <> fromRows d') (I.elems u)   -----------------------------------------------------------------------------