som-10.1.8: Self-Organising Maps

Copyright (c) Amy de Buitléir 2012-2018 BSD-style amy@nualeargais.ie experimental portable Safe Haskell2010

Data.Datamining.Clustering.SGMInternal

Description

A module containing private SGM internals. Most developers should use SGM instead. This module is subject to change without notice.

Synopsis

# Documentation

exponential :: (Floating a, Integral t) => a -> a -> t -> a Source #

A typical learning function for classifiers. exponential r0 d t returns the learning rate at time t. When t = 0, the learning rate is r0. Over time the learning rate decays exponentially; the decay rate is d. Normally the parameters are chosen such that:

• 0 < r0 < 1
• 0 < d

data SGM t x k p Source #

A Simplified Self-Organising Map (SGM). t is the type of the counter. x is the type of the learning rate and the difference metric. k is the type of the model indices. p is the type of the input patterns and models.

Constructors

 SGM FieldstoMap :: Map k (p, t)Maps patterns and match counts to nodes.learningRate :: t -> xA function which determines the learning rate for a node. The input parameter indicates how many patterns (or pattern batches) have previously been presented to the classifier. Typically this is used to make the learning rate decay over time. The output is the learning rate for that node (the amount by which the node's model should be updated to match the target). The learning rate should be between zero and one.maxSize :: IntThe maximum number of models this SGM can hold.diffThreshold :: xThe threshold that triggers creation of a new model.allowDeletion :: BoolDelete existing models to make room for new ones? The least useful (least frequently matched) models will be deleted first.difference :: p -> p -> xA function which compares two patterns and returns a non-negative number representing how different the patterns are. A result of 0 indicates that the patterns are identical.makeSimilar :: p -> x -> p -> pA function which updates models. For example, if this function is f, then f target amount pattern returns a modified copy of pattern that is more similar to target than pattern is. The magnitude of the adjustment is controlled by the amount parameter, which should be a number between 0 and 1. Larger values for amount permit greater adjustments. If amount=1, the result should be identical to the target. If amount=0, the result should be the unmodified pattern.nextIndex :: kIndex for the next node to add to the SGM.
Instances
 Generic (SGM t x k p) Source # Instance detailsDefined in Data.Datamining.Clustering.SGMInternal Associated Typestype Rep (SGM t x k p) :: Type -> Type # Methodsfrom :: SGM t x k p -> Rep (SGM t x k p) x0 #to :: Rep (SGM t x k p) x0 -> SGM t x k p # (NFData k, NFData p, NFData t, NFData x) => NFData (SGM t x k p) Source # Instance detailsDefined in Data.Datamining.Clustering.SGMInternal Methodsrnf :: SGM t x k p -> () # type Rep (SGM t x k p) Source # Instance detailsDefined in Data.Datamining.Clustering.SGMInternal type Rep (SGM t x k p) = D1 (MetaData "SGM" "Data.Datamining.Clustering.SGMInternal" "som-10.1.8-4U7idyllz4eEJA79g8KqEw" False) (C1 (MetaCons "SGM" PrefixI True) (((S1 (MetaSel (Just "toMap") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Map k (p, t))) :*: S1 (MetaSel (Just "learningRate") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (t -> x))) :*: (S1 (MetaSel (Just "maxSize") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int) :*: S1 (MetaSel (Just "diffThreshold") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 x))) :*: ((S1 (MetaSel (Just "allowDeletion") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool) :*: S1 (MetaSel (Just "difference") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (p -> p -> x))) :*: (S1 (MetaSel (Just "makeSimilar") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (p -> x -> p -> p)) :*: S1 (MetaSel (Just "nextIndex") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 k)))))

makeSGM :: Bounded k => (t -> x) -> Int -> x -> Bool -> (p -> p -> x) -> (p -> x -> p -> p) -> SGM t x k p Source #

makeSGM lr n dt diff ms creates a new SGM that does not (yet) contain any models. It will learn at the rate determined by the learning function lr, and will be able to hold up to n models. It will create a new model based on a pattern presented to it when (1) the SGM contains no models, or (2) the difference between the pattern and the closest matching model exceeds the threshold dt. It will use the function diff to measure the similarity between an input pattern and a model. It will use the function ms to adjust models as needed to make them more similar to input patterns.

isEmpty :: SGM t x k p -> Bool Source #

Returns true if the SGM has no models, false otherwise.

numModels :: SGM t x k p -> Int Source #

Returns the number of models the SGM currently contains.

modelMap :: SGM t x k p -> Map k p Source #

Returns a map from node ID to model.

counterMap :: SGM t x k p -> Map k t Source #

Returns a map from node ID to counter (number of times the node's model has been the closest match to an input pattern).

modelAt :: Ord k => SGM t x k p -> k -> p Source #

Returns the model at a specified node.

labels :: SGM t x k p -> [k] Source #

Returns the current labels.

models :: SGM t x k p -> [p] Source #

Returns the current models.

counters :: SGM t x k p -> [t] Source #

Returns the current counters (number of times the node's model has been the closest match to an input pattern).

time :: Num t => SGM t x k p -> t Source #

The current "time" (number of times the SGM has been trained).

addNode :: (Num t, Enum k, Ord k) => p -> SGM t x k p -> SGM t x k p Source #

Adds a new node to the SGM.

deleteNode :: Ord k => k -> SGM t x k p -> SGM t x k p Source #

Removes a node from the SGM. Deleted nodes are never re-used.

incrementCounter :: (Num t, Ord k) => k -> SGM t x k p -> SGM t x k p Source #

Increments the match counter.

trainNode :: (Num t, Ord k) => SGM t x k p -> k -> p -> SGM t x k p Source #

Trains the specified node to better match a target. Most users should use train, which automatically determines the BMU and trains it.

leastUsefulNode :: Ord t => SGM t x k p -> k Source #

Returns the node that has been the BMU least often.

deleteLeastUsefulNode :: (Ord t, Ord k) => SGM t x k p -> SGM t x k p Source #

Deletes the node that has been the BMU least often.

addModel :: (Num t, Ord t, Enum k, Ord k) => p -> SGM t x k p -> SGM t x k p Source #

Adds a new node to the SGM, deleting the least useful node/model if necessary to make room.

classify :: (Num t, Ord t, Num x, Ord x, Enum k, Ord k) => SGM t x k p -> p -> (k, x, Map k (p, x)) Source #

classify s p identifies the model s that most closely matches the pattern p. 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 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, Map k (p, x), SGM t x k p) Source #

Internal method. NOTE: This function may create a new model, but it does not modify existing models.

matchOrder :: (Ord a, Ord b) => (a, b) -> (a, b) -> Ordering Source #

Order models by ascending difference from the input pattern, then by creation order (label number).

trainAndClassify :: (Num t, Ord t, Num x, Ord x, Enum k, Ord k) => SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p) Source #

trainAndClassify s p identifies the model in s that most closely matches p, and updates it to be a somewhat better match. If necessary, it will create a new node and model. Returns the ID of the node with the best matching model, the difference between the best matching model and the pattern, the differences between the input and each model in the SGM, and the updated SGM.

train :: (Num t, Ord t, Num x, Ord x, Enum k, Ord k) => SGM t x k p -> p -> SGM t x k p Source #

train s p identifies the model in s that most closely matches p, and updates it to be a somewhat better match. If necessary, it will create a new node and model.

trainBatch :: (Num t, Ord t, Num x, Ord x, Enum k, Ord k) => SGM t x k p -> [p] -> SGM t x k p Source #

For each pattern p in ps, trainBatch s ps identifies the model in s that most closely matches p, and updates it to be a somewhat better match.