packages feed

hstatistics 0.2.0.6 → 0.2.0.7

raw patch · 3 files changed

+14/−10 lines, 3 files

Files

CHANGES view
@@ -35,3 +35,8 @@ 0.2.0.6: 		added PCA 		added ICA++0.2.0.7+		removed hard-coded sigmoid from ICA algorithm internals+		was not using seed passed to ica+		minor fixes to remove warnings
hstatistics.cabal view
@@ -1,5 +1,5 @@ Name:               hstatistics-Version:            0.2.0.6+Version:            0.2.0.7 License:            GPL License-file:       LICENSE Copyright:          (c) A.V.H. McPhail 2010
lib/Numeric/Statistics/ICA.hs view
@@ -43,8 +43,6 @@  import Numeric.Statistics -import Control.Monad(replicateM)- import System.Random  -----------------------------------------------------------------------------@@ -133,19 +131,19 @@ update :: (Double -> Double) -> (Double -> Double) -> Matrix Double -> Matrix Double -> Matrix Double update g g' w x = let y = w <> x                       ys = toRows y-                      bis = map (\y' -> - mean (y' * (mapVector sigmoid y'))) ys-                      ais = zipWith (\b y' -> -1 / (b - mean (mapVector sigmoid y'))) bis ys+                      bis = map (\y' -> - mean (y' * (mapVector g y'))) ys+                      ais = zipWith (\b y' -> -1 / (b - mean (mapVector g y'))) bis ys                       r = rows y                       ix = ((1,1),(r,r))-                      cov = fromArray2D $ I.listArray ix $ map (\(m,n) -> covariance (mapVector sigmoid' (ys!!(m-1))) (ys!!(n-1))) $ I.range ix+                      cov = fromArray2D $ I.listArray ix $ map (\(m,n) -> covariance (mapVector g' (ys!!(m-1))) (ys!!(n-1))) $ I.range ix                   in w + (diag $ fromList ais) <> ((diag $ fromList bis) + cov) <> w    decorrelate :: Matrix Double -> Matrix Double decorrelate w = let w' = w / (scalar $ sqrt $ pnorm PNorm2 (w <> trans w))-                in decorrelate w w'-    where decorrelate w w' +                in decorrelate' w w'+    where decorrelate' w w'                | converged 0.000001 w w' = w'-              | otherwise               = decorrelate w' ((scale 1.5 w') - (scale 0.5 (w <> trans w <> w)))+              | otherwise               = decorrelate' w' ((scale 1.5 w') - (scale 0.5 (w <> trans w <> w))) {- don't know how to do svd of non-square matrices decorrelate m = let (u,d,v) = svd m                 in u <> (diag (d ** (-0.5))) <> trans v <> m@@ -167,6 +165,7 @@      -> Matrix Double               -- ^ weight matrix      -> [Matrix Double]             -- ^ input data in chunks      -> Matrix Double               -- ^ ica transform (weight matrix)+ica' _ _  _ _ _ []     = error "no sample data" ica' g g' n t w (x:xs) = let w' = normalise n $ decorrelate $ update g g' w x                              in if converged t w w'                                  then w'@@ -182,7 +181,7 @@     -> I.Array Int (Vector Double) -- ^ data     -> (I.Array Int (Vector Double),Matrix Double) -- ^ transformed data, ica transform ica r g g' n t o s a = let i = I.rangeSize $ I.bounds a-                           w = random_vector s (o,i)+                           w = random_vector r (o,i)                            x' = fromRows $ I.elems a                            -- next line is BAD if distribution not stationary                            x = concat $ toBlocksEvery i s x'