packages feed

som 9.0.4 → 10.0.0

raw patch · 18 files changed

+175/−150 lines, 18 filesdep −MonadRandomdep −assertdep ~QuickCheckdep ~basedep ~containers

Dependencies removed: MonadRandom, assert

Dependency ranges changed: QuickCheck, base, containers, deepseq, grid, random, test-framework, test-framework-quickcheck2

Files

+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Changelog for som++10.0.0 Revamped to work with Stack v1.7.1.++## Unreleased changes
LICENSE view
@@ -1,4 +1,4 @@-Copyright Amy de Buitléir (c) 2010-2017+Copyright Amy de Buitléir (c) 2010-2018  All rights reserved. 
+ README.md view
@@ -0,0 +1,1 @@+# som
som.cabal view
@@ -1,75 +1,73 @@-name: som-version: 9.0.4-cabal-version: >=1.10-build-type: Simple-license: BSD3-license-file: LICENSE-copyright: (c) 2010-2017 Amy de Buitléir-maintainer: amy@nualeargais.ie-homepage: https://github.com/mhwombat/som#readme-bug-reports: https://github.com/mhwombat/som/issues-synopsis: Self-Organising Maps.-description:-    A Kohonen Self-organising Map (SOM) maps input patterns-    onto a regular grid (usually two-dimensional) where each-    node in the grid is a model of the input data, and does-    so using a method which ensures that any topological-    relationships within the input data are also represented-    in the grid. This implementation supports the use of-    non-numeric patterns.-    .-    In layman's terms, a SOM can be useful when you you want-    to discover the underlying structure of some data.-    .-    The userguide is available at-    <https://github.com/mhwombat/som/wiki>.-category: Math-author: Amy de Buitléir+-- This file has been generated from package.yaml by hpack version 0.28.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: 1330189cdf3ef7ee816d06173d1dce1e99b18deb50790491685a1afe06f6c712 +name:           som+version:        10.0.0+synopsis:       Self-Organising Maps+description:    Please see the README on GitHub at <https://github.com/mhwombat/som#readme>+category:       Math+homepage:       https://github.com/mhwombat/som#readme+bug-reports:    https://github.com/mhwombat/som/issues+author:         Amy de Buitléir+maintainer:     amy@nualeargais.ie+copyright:      2018 Amy de Buitléir+license:        BSD3+license-file:   LICENSE+build-type:     Simple+cabal-version:  >= 1.10+extra-source-files:+    ChangeLog.md+    README.md+ source-repository head-    type: git-    location: https://github.com/mhwombat/som+  type: git+  location: https://github.com/mhwombat/som  library-    exposed-modules:-        Data.Datamining.Clustering.SOM-        Data.Datamining.Clustering.SOMInternal-        Data.Datamining.Clustering.DSOM-        Data.Datamining.Clustering.DSOMInternal-        Data.Datamining.Clustering.SGM-        Data.Datamining.Clustering.SGMInternal-        Data.Datamining.Clustering.Classifier-        Data.Datamining.Pattern-    build-depends:-        assert >=0.0.1.2 && <0.1,-        base >=4.7 && <5,-        containers >=0.5.10.2 && <0.6,-        deepseq >=1.4.3.0 && <1.5,-        grid >=7.8.8 && <7.9,-        MonadRandom >=0.5.1 && <0.6-    default-language: Haskell2010-    hs-source-dirs: src-    ghc-options: -Wall+  exposed-modules:+      Data.Datamining.Clustering.Classifier+      Data.Datamining.Clustering.DSOM+      Data.Datamining.Clustering.DSOMInternal+      Data.Datamining.Clustering.SGM+      Data.Datamining.Clustering.SGMInternal+      Data.Datamining.Clustering.SOM+      Data.Datamining.Clustering.SOMInternal+      Data.Datamining.Pattern+  other-modules:+      Paths_som+  hs-source-dirs:+      src+  ghc-options: -Wall+  build-depends:+      base >=4.7 && <5+    , containers+    , deepseq+    , grid+  default-language: Haskell2010  test-suite som-test-    type: exitcode-stdio-1.0-    main-is: Main.hs-    build-depends:-        assert >=0.0.1.2 && <0.1,-        base >=4.10.0.0 && <4.11,-        test-framework-quickcheck2 >=0.3.0.4 && <0.4,-        QuickCheck >=2.10.0.1 && <2.11,-        test-framework >=0.8.1.1 && <0.9,-        som,-        containers >=0.5.10.2 && <0.6,-        grid >=7.8.8 && <7.9,-        MonadRandom >=0.5.1 && <0.6,-        random ==1.1.*-    default-language: Haskell2010-    hs-source-dirs: test-    other-modules:-        Data.Datamining.Clustering.DSOMQC-        Data.Datamining.Clustering.SGMQC-        Data.Datamining.Clustering.SOMQC-        Data.Datamining.PatternQC-    ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Data.Datamining.Clustering.DSOMQC+      Data.Datamining.Clustering.SGMQC+      Data.Datamining.Clustering.SOMQC+      Data.Datamining.PatternQC+      Paths_som+  hs-source-dirs:+      test+  ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall+  build-depends:+      QuickCheck+    , base >=4.7 && <5+    , containers+    , deepseq+    , grid+    , random+    , som+    , test-framework+    , test-framework-quickcheck2+  default-language: Haskell2010
src/Data/Datamining/Clustering/Classifier.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.Classifier--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental
src/Data/Datamining/Clustering/DSOM.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.SOM--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental
src/Data/Datamining/Clustering/DSOMInternal.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.DSOMInternal--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental
src/Data/Datamining/Clustering/SGM.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.SGM--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental@@ -27,11 +27,22 @@ -- -- References: ----- * de Buitléir, Amy, Russell, Michael and Daly, Mark. (2012). Wains:---   A pattern-seeking artificial life species. Artificial Life, 18 (4),---   399-423. --- --- * Kohonen, T. (1982). Self-organized formation of topologically +-- * Amy de Buitléir, Mark Daly, and Michael Russell.+--   The Self-generating Model: an Adaptation of the Self-organizing Map+--   for Intelligent Agents and Data Mining.+--   In: Artificial Life and Intelligent Agents: Second International+--   Symposium, ALIA 2016, Birmingham, UK, June 14-15, 2016,+--   Revised Selected Papers.+--   Ed. by Peter R. Lewis et al. Springer International Publishing,+--   2018, pp. 59–72.+--   Available at http://amydebuitleir.eu/publications/.+--+-- * Amy de Buitléir, Michael Russell, and Mark Daly.+--   Wains: A pattern-seeking artificial life species.+--   Artificial Life, (18)4:399–423, 2012.+--   Available at http://amydebuitleir.eu/publications/.+--+-- * Kohonen, T. (1982). Self-organized formation of topologically --   correct feature maps. Biological Cybernetics, 43 (1), 59–69. ------------------------------------------------------------------------ @@ -46,6 +57,7 @@     numModels,     modelMap,     counterMap,+    modelAt,     -- models,     -- counters,     -- * Learning and classification
src/Data/Datamining/Clustering/SGMInternal.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.SGMInternal--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental@@ -120,6 +120,10 @@ counterMap :: SGM t x k p -> M.Map k t counterMap = M.map snd . toMap +-- | Returns the model at a specified node.+modelAt :: Ord k => SGM t x k p -> k -> p+modelAt s k = (modelMap s) M.! k+ -- | Returns the current labels. labels :: SGM t x k p -> [k] labels = M.keys . toMap@@ -200,31 +204,34 @@ --   It will not make any changes to the classifier. --   Returns the ID of the node with the best matching model, --   the difference between the best matching model and the pattern,---   and the SGM labels paired  with the difference between the input---   and the corresponding model.+--   and the SGM labels paired with the model and the difference+--   between the input and the corresponding model. --   The final paired list is sorted in decreasing order of similarity. classify   :: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)-    => SGM t x k p -> p -> (k, x, [(k, x)])-classify s p = (bmu, bmuDiff, diffs)-  where sFull = s { maxSize = 0, allowDeletion = False } -- no changes!-        (bmu, bmuDiff, diffs, _) = classify' sFull p-        +    => SGM t x k p -> p -> (k, x, M.Map k (p, x))+classify s p = (bmu, bmuDiff, report)+  where sFull = s { maxSize = numModels s, allowDeletion = False }+          -- don't allow any changes!+        (bmu, bmuDiff, report, _) = classify' sFull p + -- NOTE: This function may create a new model, but it does not modify -- existing models. classify'   :: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)-    => SGM t x k p -> p -> (k, x, [(k, x)], SGM t x k p)+    => SGM t x k p -> p -> (k, x, M.Map k (p, x), SGM t x k p) classify' s p   | isEmpty 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 diffs = sortBy matchOrder . M.toList . M.map (difference s p)-                    . M.map fst . toMap $ s-        (bmu, bmuDiff) = head diffs+  | otherwise                 = (bmu, bmuDiff, report, s')+  where report+          = M.map (\p0 -> (p0, difference s p p0)) . modelMap $ s+        (bmu, bmuDiff)+          = head . sortBy matchOrder . map (\(k, (_, x)) -> (k, x))+              . M.toList $ report         s' = incrementCounter bmu s  -- We want the model with the lowest difference from the input pattern.@@ -242,9 +249,9 @@ --   and the updated SGM. trainAndClassify   :: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)-    => SGM t x k p -> p -> (k, x, [(k, x)], SGM t x k p)-trainAndClassify s p = (bmu, bmuDiff, diffs, s3)-  where (bmu, bmuDiff, diffs, s2) = classify' s p+    => SGM t x k p -> p -> (k, x, M.Map k (p, x), SGM t x k p)+trainAndClassify s p = (bmu, bmuDiff, report, s3)+  where (bmu, bmuDiff, report, s2) = classify' s p         s3 = trainNode s2 bmu p  -- | @'train' s p@ identifies the model in @s@ that most closely@@ -263,4 +270,4 @@   :: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)     => SGM t x k p -> [p] -> SGM t x k p trainBatch = foldl' train-  +
src/Data/Datamining/Clustering/SOM.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.SOM--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental
src/Data/Datamining/Clustering/SOMInternal.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.SOMInternal--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental@@ -16,6 +16,8 @@  module Data.Datamining.Clustering.SOMInternal where +import Prelude hiding (lookup)+ import Control.DeepSeq (NFData) import qualified Data.Foldable as F (Foldable, foldr) import Data.List (foldl', minimumBy)@@ -24,7 +26,6 @@ import qualified Math.Geometry.GridMap as GM (GridMap(..)) import Data.Datamining.Clustering.Classifier(Classifier(..)) import GHC.Generics (Generic)-import Prelude hiding (lookup)  -- | A typical learning function for classifiers. --   @'decayingGaussian' r0 rf w0 wf tf@ returns a bell curve-shaped
src/Data/Datamining/Pattern.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Pattern--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental
test/Data/Datamining/Clustering/DSOMQC.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.DSOMQC--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental
test/Data/Datamining/Clustering/SGMQC.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.SGMQC--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental@@ -19,6 +19,7 @@     test   ) where +import Control.DeepSeq (deepseq) import Data.Datamining.Pattern (adjustNum, absDifference) import Data.Datamining.Clustering.SGMInternal import Data.List ((\\), minimumBy)@@ -94,14 +95,22 @@  prop_classify_chooses_best_fit :: TestSGM -> Double -> Property prop_classify_chooses_best_fit (TestSGM s _) x-  = property $ bmu == fst (minimumBy (comparing snd) diffs)-  where (bmu, _, diffs, _) = trainAndClassify s x+  = property $ bmu == bmu2+  where (bmu, _, report, _) = trainAndClassify s x+        bmu2 = fst (minimumBy (comparing f) . M.toList $ report)+        f (_, (_, d)) = d  prop_classify_never_creates_model :: TestSGM -> Double -> Property prop_classify_never_creates_model (TestSGM s _) x   = not (isEmpty s) ==> bmu `elem` (labels s)   where (bmu, _, _) = classify s x +prop_classify_never_causes_error_unless_som_empty+  :: TestSGM -> Double -> Property+prop_classify_never_causes_error_unless_som_empty (TestSGM s _) p+  = not (isEmpty s) ==> property $ deepseq x True+  where x = classify s p+ prop_trainNode_reduces_diff :: TestSGM -> Double -> Property prop_trainNode_reduces_diff (TestSGM s _) x = not (isEmpty s) ==>   diffAfter < diffBefore || diffBefore == 0@@ -171,14 +180,9 @@ prop_classification_results_are_consistent   :: TestSGM -> Double -> Property prop_classification_results_are_consistent (TestSGM s _) x-  = property $ bmu == fst (minimumBy (comparing snd) diffs)-  where (bmu, _, diffs, _) = trainAndClassify s x--prop_classification_results_are_consistent2-  :: TestSGM -> Double -> Property-prop_classification_results_are_consistent2 (TestSGM s _) x-  = property $ bmuDiff == snd (minimumBy (comparing snd) diffs)-  where (_, bmuDiff, diffs, _) = trainAndClassify s x+  = property $ bmuDiff == minimum diffs+  where (_, bmuDiff, report, _) = trainAndClassify s x+        diffs = map (\(_, (_, d)) -> d) . M.toList $ report  prop_classification_stabilises :: TestSGM -> [Double] -> Property prop_classification_stabilises (TestSGM s _)  ps@@ -215,6 +219,8 @@       prop_classify_chooses_best_fit,     testProperty "prop_classify_never_creates_model"       prop_classify_never_creates_model,+    testProperty "prop_classify_never_causes_error_unless_som_empty"+      prop_classify_never_causes_error_unless_som_empty,     testProperty "prop_trainNode_reduces_diff"       prop_trainNode_reduces_diff,     testProperty "prop_diff_lt_threshold_after_training"@@ -230,12 +236,10 @@       prop_classification_is_consistent,     testProperty "prop_classification_results_are_consistent"       prop_classification_results_are_consistent,-    testProperty "prop_classification_results_are_consistent2"-      prop_classification_results_are_consistent2,     testProperty "prop_classification_stabilises"       prop_classification_stabilises,     testProperty "prop_models_not_deleted_unless_allowed"       prop_models_not_deleted_unless_allowed,     testProperty "prop_models_not_deleted_unless_allowed2"-      prop_models_not_deleted_unless_allowed2    +      prop_models_not_deleted_unless_allowed2   ]
test/Data/Datamining/Clustering/SOMQC.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.Clustering.SOMQC--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental
test/Data/Datamining/PatternQC.hs view
@@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- | -- Module      :  Data.Datamining.PatternQC--- Copyright   :  (c) Amy de Buitléir 2012-2016+-- Copyright   :  (c) Amy de Buitléir 2012-2018 -- License     :  BSD-style -- Maintainer  :  amy@nualeargais.ie -- Stability   :  experimental
− test/Main.hs
@@ -1,33 +0,0 @@---------------------------------------------------------------------------- |--- Module      :  Main--- Copyright   :  (c) Amy de Buitléir 2012-2016--- License     :  BSD-style--- Maintainer  :  amy@nualeargais.ie--- Stability   :  experimental--- Portability :  portable------ Tests-----------------------------------------------------------------------------{-# LANGUAGE UnicodeSyntax #-}-module Main where--import Data.Datamining.PatternQC ( test )-import Data.Datamining.Clustering.SOMQC ( test )-import Data.Datamining.Clustering.SGMQC ( test )-import Data.Datamining.Clustering.DSOMQC ( test )--import Test.Framework as TF ( defaultMain, Test )--tests :: [TF.Test]-tests = -  [ -    Data.Datamining.PatternQC.test,-    Data.Datamining.Clustering.SGMQC.test,-    Data.Datamining.Clustering.SOMQC.test,-    Data.Datamining.Clustering.DSOMQC.test-  ]--main :: IO ()-main = defaultMain tests
+ test/Spec.hs view
@@ -0,0 +1,30 @@+------------------------------------------------------------------------+-- |+-- Module      :  Main+-- Copyright   :  (c) Amy de Buitléir 2012-2018+-- License     :  BSD-style+-- Maintainer  :  amy@nualeargais.ie+-- Stability   :  experimental+-- Portability :  portable+--+-- Tests+--+------------------------------------------------------------------------+import Data.Datamining.PatternQC ( test )+import Data.Datamining.Clustering.SOMQC ( test )+import Data.Datamining.Clustering.SGMQC ( test )+import Data.Datamining.Clustering.DSOMQC ( test )++import Test.Framework as TF ( defaultMain, Test )++tests :: [TF.Test]+tests = +  [ +    Data.Datamining.PatternQC.test,+    Data.Datamining.Clustering.SGMQC.test,+    Data.Datamining.Clustering.SOMQC.test,+    Data.Datamining.Clustering.DSOMQC.test+  ]++main :: IO ()+main = defaultMain tests