packages feed

som 8.1.1 → 8.2.1

raw patch · 4 files changed

+21/−12 lines, 4 files

Files

som.cabal view
@@ -1,5 +1,5 @@ Name:              som-Version:           8.1.1+Version:           8.2.1 Stability:         experimental Synopsis:          Self-Organising Maps. Description:       A Kohonen Self-organising Map (SOM) maps input patterns @@ -33,7 +33,7 @@ source-repository this   type:     git   location: https://github.com/mhwombat/som.git-  tag:      8.1.1+  tag:      8.2.1   library
src/Data/Datamining/Clustering/SOSInternal.hs view
@@ -60,6 +60,9 @@     maxSize :: Int,     -- | The threshold that triggers creation of a new model.     diffThreshold :: x,+    -- | Delete existing models to make room for new ones? The least+    --   useful (least frequently matched) models will be deleted first.+    allowDeletion :: Bool,     -- | A function which compares two patterns and returns a     --   /non-negative/ number representing how different the patterns     --   are.@@ -93,12 +96,12 @@ -- them more similar to input patterns. makeSOS   :: Bounded k-    => (t -> x) -> Int -> x -> (p -> p -> x) -> (p -> x -> p -> p)-      -> SOS t x k p-makeSOS lr n dt diff ms =+    => (t -> x) -> Int -> x -> Bool -> (p -> p -> x)+      -> (p -> x -> p -> p) -> SOS t x k p+makeSOS lr n dt ad diff ms =   if n <= 0     then error "max size for SOS <= 0"-    else SOS M.empty lr n dt diff ms minBound+    else SOS M.empty lr n dt ad diff ms minBound  -- | Returns true if the SOS has no models, false otherwise. isEmpty :: SOS t x k p -> Bool@@ -207,7 +210,9 @@     => SOS t x k p -> p -> (k, x, [(k, x)], SOS t x k p) classify s p   | isEmpty s                 = classify (addModel p s) p-  | bmuDiff > diffThreshold s = classify (addModel p s) p+  | bmuDiff > diffThreshold s+      && (numModels s < maxSize s || allowDeletion s)+                              = classify (addModel p s) p   | otherwise                 = (bmu, bmuDiff, diffs, s')   where (bmu, bmuDiff) = minimumBy (comparing snd) diffs         diffs = M.toList . M.map (difference s p) . M.map fst
test/Data/Datamining/Clustering/SOSQC.hs view
@@ -67,13 +67,14 @@   show (TestSOS _ desc) = desc  buildTestSOS-  :: Double -> Double -> Int -> Double -> [Double] -> TestSOS-buildTestSOS r0 d maxSz dt ps = TestSOS s' desc+  :: Double -> Double -> Int -> Double -> Bool -> [Double] -> TestSOS+buildTestSOS r0 d maxSz dt ad ps = TestSOS s' desc   where lrf = exponential r0 d-        s = makeSOS lrf maxSz dt absDifference adjustNum+        s = makeSOS lrf maxSz dt ad absDifference adjustNum         desc = "buildTestSOS " ++ show r0 ++ " " ++ show d                  ++ " " ++ show maxSz                  ++ " " ++ show dt+                 ++ " " ++ show ad                  ++ " " ++ show ps         s' = trainBatch s ps @@ -84,8 +85,9 @@   r0 <- choose (0, 1)   d <- positive   dt <- choose (0, 1)+  ad <- arbitrary   ps <- vectorOf numPatterns arbitrary-  return $ buildTestSOS r0 d maxSz dt ps+  return $ buildTestSOS r0 d maxSz dt ad ps  instance Arbitrary TestSOS where   arbitrary = sized sizedTestSOS@@ -115,7 +117,7 @@  prop_diff_lt_threshold_after_training :: TestSOS -> Double -> Property prop_diff_lt_threshold_after_training (TestSOS s _) x =-  property $ diffAfter < diffThreshold s+  numModels s < maxSize s ==> diffAfter < diffThreshold s   where s' = train s x         (_, diffAfter, _, _) = classify s' x 
test/Main.hs view
@@ -15,6 +15,7 @@  import Data.Datamining.PatternQC ( test ) import Data.Datamining.Clustering.SOMQC ( test )+import Data.Datamining.Clustering.SOSQC ( test ) import Data.Datamining.Clustering.SSOMQC ( test ) import Data.Datamining.Clustering.DSOMQC ( test ) @@ -25,6 +26,7 @@   [      Data.Datamining.PatternQC.test,     Data.Datamining.Clustering.SSOMQC.test,+    Data.Datamining.Clustering.SOSQC.test,     Data.Datamining.Clustering.SOMQC.test,     Data.Datamining.Clustering.DSOMQC.test   ]