som 9.0 → 9.0.1
raw patch · 2 files changed
+14/−6 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Datamining.Clustering.SGMInternal: matchOrder :: (Ord a, Ord b) => (a, b) -> (a, b) -> Ordering
Files
som.cabal view
@@ -1,5 +1,5 @@ Name: som-Version: 9.0+Version: 9.0.1 Stability: experimental Synopsis: Self-Organising Maps. Description: A Kohonen Self-organising Map (SOM) maps input patterns
src/Data/Datamining/Clustering/SGMInternal.hs view
@@ -19,7 +19,7 @@ import Prelude hiding (lookup) import Control.DeepSeq (NFData)-import Data.List (minimumBy, foldl')+import Data.List (minimumBy, sortBy, foldl') import Data.Ord (comparing) import qualified Data.Map.Strict as M import GHC.Generics (Generic)@@ -200,7 +200,9 @@ -- 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 differences between the input and each model in the SGM.+-- and the SGM labels paired with 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)])@@ -220,10 +222,16 @@ && (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- . toMap $ s+ where diffs = sortBy matchOrder . M.toList . M.map (difference s p)+ . M.map fst . toMap $ s+ (bmu, bmuDiff) = head diffs s' = incrementCounter bmu s++-- We want the model with the lowest difference from the input pattern.+-- If two models have the same difference, return the model that was+-- created earlier (has the lower label #).+matchOrder :: (Ord a, Ord b) => (a, b) -> (a, b) -> Ordering+matchOrder (a, b) (c, d) = compare (b, a) (d, c) -- | @'trainAndClassify' s p@ identifies the model in @s@ that most -- closely matches @p@, and updates it to be a somewhat better match.