Copyright  (c) Amy de Buitléir 20122013 

License  BSDstyle 
Maintainer  amy@nualeargais.ie 
Stability  experimental 
Portability  portable 
Safe Haskell  SafeInferred 
Language  Haskell98 
A Kohonen Selforganising Map (SOM). A SOM maps input patterns onto a regular grid (usually twodimensional) 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 nonnumeric 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
function. If you usedecayingGaussian
(which uses this function), your SOM should now learn more quickly.defaultSOM
 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). Selforganized formation of topologically correct feature maps. Biological Cybernetics, 43 (1), 59–69.
 data SOM f gm k p = SOM {
 sGridMap :: gm p
 sLearningFunction :: f
 sCounter :: Int
 data DecayingGaussian a = DecayingGaussian a a a a Int
 toGridMap :: GridMap gm p => SOM f gm k p > gm p
 trainNeighbourhood :: (Pattern p, Grid (gm p), GridMap gm p, Index (BaseGrid gm p) ~ Index (gm p), LearningFunction f, LearningRate f ~ Metric p) => SOM f gm k p > Index (gm p) > p > SOM f gm k p
 incrementCounter :: SOM f gm k p > SOM f gm k p
 counter :: SOM f gm k p > Int
 setCounter :: Int > SOM f gm k p > SOM f gm k p
Construction
A SelfOrganising Map (SOM).
Although SOM
implements GridMap
, most users will only need the
interface provided by Data.Datamining.Clustering.Classifier
. If
you chose to use the GridMap
functions, please note:
 The functions
adjust
, andadjustWithKey
do not increment the counter. You can do so manually withincrementCounter
.  The functions
map
andmapWithKey
are not implemented (they just return anerror
). It would be problematic to implement them because the input SOM and the output SOM would have to have the sameMetric
type.
SOM  

(GridMap gm p, (~) * k (Index (BaseGrid gm p)), Pattern p, Grid (gm p), GridMap gm (Metric p), (~) * k (Index (gm p)), (~) * k (Index (BaseGrid gm (Metric p))), Ord (Metric p), LearningFunction f, (~) * (LearningRate f) (Metric p)) => Classifier (SOM f gm) k p  
Foldable gm => Foldable (SOM f gm k)  
(Foldable gm, GridMap gm p, Grid (BaseGrid gm p)) => GridMap (SOM f gm k) p  
(Eq f, Eq (gm p)) => Eq (SOM f gm k p)  
(Show f, Show (gm p)) => Show (SOM f gm k p)  
Generic (SOM f gm k p)  
Grid (gm p) => Grid (SOM f gm k p)  
type BaseGrid (SOM f gm k) p = BaseGrid gm p  
type Rep (SOM f gm k p)  
type Direction (SOM f gm k p) = Direction (gm p)  
type Index (SOM f gm k p) = Index (gm p) 
data DecayingGaussian a Source
A typical learning function for classifiers.
returns a bell curveshaped
function. At time zero, the maximum learning rate (applied to the
BMU) is DecayingGaussian
r0 rf w0 wf tfr0
, and the neighbourhood width is w0
. Over time the
bell curve shrinks and the learning rate tapers off, until at time
tf
, the maximum learning rate (applied to the BMU) is rf
,
and the neighbourhood width is wf
. Normally the parameters
should be chosen such that:
 0 < rf << r0 < 1
 0 < wf << w0
 0 < tf
where << means "is much smaller than" (not the Haskell <<
operator!)
DecayingGaussian a a a a Int 
Eq a => Eq (DecayingGaussian a)  
Show a => Show (DecayingGaussian a)  
Generic (DecayingGaussian a)  
(Floating a, Fractional a, Num a) => LearningFunction (DecayingGaussian a)  
type Rep (DecayingGaussian a)  
type LearningRate (DecayingGaussian a) = a 
Deconstruction
toGridMap :: GridMap gm p => SOM f gm k p > gm p Source
Extracts the grid and current models from the SOM.
Advanced control
trainNeighbourhood :: (Pattern p, Grid (gm p), GridMap gm p, Index (BaseGrid gm p) ~ Index (gm p), LearningFunction f, LearningRate f ~ Metric p) => SOM f gm k p > Index (gm p) > p > SOM f gm k p Source
Trains the specified node and the neighbourood around it to better
match a target.
Most users should use train
, which automatically determines
the BMU and trains it and its neighbourhood.
incrementCounter :: SOM f gm k p > SOM f gm k p Source
setCounter :: Int > SOM f gm k p > SOM f gm k p Source