som 4.2 → 5.0
raw patch · 4 files changed
+30/−30 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Datamining.Clustering.SOM: gaussian :: Floating a => a -> a -> Int -> a
- Data.Datamining.Clustering.SOMInternal: gaussian :: Floating a => a -> a -> Int -> a
Files
- som.cabal +1/−1
- src/Data/Datamining/Clustering/Classifier.hs +4/−3
- src/Data/Datamining/Clustering/SOM.hs +19/−8
- src/Data/Datamining/Clustering/SOMInternal.hs +6/−18
som.cabal view
@@ -1,5 +1,5 @@ name: som-version: 4.2+version: 5.0 synopsis: Self-Organising Maps description: A Kohonen Self-organising Map (SOM) maps input patterns onto a regular grid (usually two-dimensional) where each
src/Data/Datamining/Clustering/Classifier.hs view
@@ -34,8 +34,8 @@ models ∷ c k p → [p] -- | @'differences' c target@ returns the indices of all nodes in - -- @c@, paired with the difference between @target@ and the node's - -- model.+ -- @c@, paired with the difference between @target@ and the + -- node's model. differences ∷ (Pattern p, v ~ Metric p) ⇒ c k p → p → [(k, v)] -- | @classify c target@ returns the index of the node in @c@ @@ -59,7 +59,8 @@ -- index of the node in @c@ whose model best matches the input -- @target@, and a modified copy of the classifier @c@ that has -- partially learned the @target@. Invoking @classifyAndTrain c p@- -- may be faster than invoking @(p `classify` c, train c p)@, but they+ -- may be faster than invoking @(p `classify` c, train c p)@, but + -- they -- should give identical results. classifyAndTrain ∷ (Ord v, v ~ Metric p) ⇒
src/Data/Datamining/Clustering/SOM.hs view
@@ -7,17 +7,29 @@ -- Stability : experimental -- Portability : portable ----- A Kohonen Self-organising Map (SOM). A 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.+-- A Kohonen Self-organising Map (SOM). A 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. A tutorial is available at -- <https://github.com/mhwombat/som/wiki>. --+-- NOTES: +--+-- * Version 5.0 fixed a bug in the @`decayingGaussian`@ function. If+-- you use @`defaultSOM`@ (which uses this function), your SOM+-- should now learn more quickly.+--+-- * The @gaussian@ function has been removed because it is not as+-- useful for SOMs as I originally thought. It was originally designed+-- to be used as a factor in a learning function. However, in most+-- cases the user will want to introduce a time decay into the+-- exponent, rather than simply multiply by a factor.+-- -- References: -- -- * Kohonen, T. (1982). Self-organized formation of topologically @@ -32,7 +44,6 @@ SOM, defaultSOM, customSOM,- gaussian, decayingGaussian, -- * Deconstruction toGridMap,@@ -42,6 +53,6 @@ ) where import Data.Datamining.Clustering.SOMInternal (SOM, defaultSOM,- customSOM, gaussian, decayingGaussian, toGridMap, trainNeighbourhood,+ customSOM, decayingGaussian, toGridMap, trainNeighbourhood, incrementCounter)
src/Data/Datamining/Clustering/SOMInternal.hs view
@@ -20,7 +20,6 @@ SOM(..), defaultSOM, customSOM,- gaussian, decayingGaussian, -- * Deconstruction toGridMap,@@ -149,7 +148,7 @@ -- at "time" zero. The BMU is the model which best matches the -- current target pattern. ----- [@w@] The width of the bell curve at "time" zero.+-- [@w@] The width of the bell curve at time zero. -- -- [@t@] Controls how rapidly the learning rate decays. After this -- time, any learning done by the classifier will be negligible.@@ -190,19 +189,6 @@ sCounter=0 } --- | Calculates @r/e/^(-d^2/2w^2)@.--- This form of the Gaussian function is useful as a learning rate--- function. In @'gaussian' r w d@, @r@ specifies the highest learning--- rate, which will be applied to the SOM node that best matches the--- input pattern. The learning rate applied to other nodes will be--- applied based on their distance @d@ from the best matching node.--- The value @w@ controls the \'width\' of the Gaussian. Higher values--- of @w@ cause the learning rate to fall off more slowly with--- distance @d@.-gaussian ∷ Floating a ⇒ a → a → Int → a-gaussian r w d = r * exp (-d'*d'/(2*w*w))- where d' = fromIntegral d- -- | Configures a typical learning function for classifiers. -- @'decayingGaussian' r w0 tMax@ returns a bell curve-shaped -- function. At time zero, the maximum learning rate (applied to the@@ -211,6 +197,8 @@ -- @tMax@, the learning rate is negligible. decayingGaussian ∷ Floating a ⇒ a → a → Int → (Int → Int → a)-decayingGaussian r w0 tMax =- \t d → let t' = fromIntegral t in gaussian r w0 d * exp (-t'/tMax')- where tMax' = fromIntegral tMax+decayingGaussian r w0 tMax t d = r * s * exp (-(d'*d')/(2*w0*w0*s*s))+ where s = exp (-t'/tMax')+ t' = fromIntegral t+ tMax' = fromIntegral tMax+ d' = fromIntegral d