hsgsom-0.2.0: An implementation of the GSOM clustering algorithm.

Portabilitynon-portable (requires STM)
Stabilityexperimental
Maintainergnn.github@gmail.com

Data.Datamining.Clustering.Gsom.Node

Description

The network of nodes which is build by GSOM consists if nodes of type Node and this module contains the definition if this type along with most of the functions altering or working on them.

Synopsis

Documentation

type Neighbours = [TVar Node]Source

A node's neighbours are stored in fields of type Neighbours.

type Neighbourhood = [(Int, Node)]Source

The type of neighbourhoods. Wherever a neighbourhood of a node is neede, this type should be used. A Neighbourhood consits of a list of pairs of nodes and their discrete grid distance from the source of the neighbourhood. The source node is the only one with distance 0 while immediate neighbours get distance one and so on.

data Node Source

The type of nodes of a gsom.

Constructors

Leaf

They're either Leafs, signalling neighbours of boundary nodes

Node

or they are actual nodes with a few associated values and a list of neighbouring nodes.

Fields

location :: Coordinates

Used to uniquely identify nodes. This is also the actual location of the node if the lattice it belongs to is beeing laid out in the two dimensional plane and it is used to store the node in the map comprising the lattice.

quantizationError :: TVar Double

The quantization error the node has accumulated so far.

weights :: TVar Input

The node's weight vector. This is the center of the voronoi cell the node represents.

neighbours :: Neighbours

The node's neighbours.

Instances

type Nodes = [Node]Source

isNode :: Node -> BoolSource

isLeaf node returns True if the given node is a Leaf and False otherwise.

neighbourhood :: Node -> Int -> STM NeighbourhoodSource

isNode node returns False if the given node is a Leaf and True otherwise.

Calculates the neighbourhood of the given size of the given node. A neighbourhood size of 0 means that only the given node will be an element of the returned set while a size of one will return the given node and it's immediate neighbours and so on. It's not very efficient so you shouldn't try big neihbourhood sizes. The returned neighbourhood always includes node.

newWeight :: Node -> Int -> STM ()Source

When a new node is spawned we need to calculate it's new weight vector. If the new node is spawned from parent p in direction d and p has a neighbour n in the direction d' opposite to d then the new weight vector nw is calculated according to the formula:

In all other cases there exists exactly one neighbour of the new node. Let this neighbour be called n and let d' be the direction in which we have to go to reach this neighbour from the new node. Let s then be the child of the new node's parent p in direction d'. The new weights are then calculated according to the formula:

  • nw = p + n - s.

node :: Coordinates -> Input -> Neighbours -> STM NodeSource

node id weights neighbours creates a node with the specified parameters and initial quantization error of 0.

propagate :: Node -> Nodes -> STM ()Source

propagate node propagates the accumulated error of the given node to it's neighbours.

unwrappedNeighbours :: Node -> STM NodesSource

unwrappedNeighbours node returns the list of neighbours of the given node. Note that neighbours is unwrapped, i.e. the returned list hast type Nodes not TVar Nodes.

update :: Input -> Double -> (Int -> Double) -> (Int, Node) -> STM ()Source

update input learning_rate kernel neighbour updates the weights of the neighbour according to the formula:

  • weight -> weight + learning_rate * (kernel d) (input - weight)

updateError :: Node -> Input -> STM ()Source

updateError node input updates the quantizationError of node. The new error is just the old error plus the distance of the node's weight vector from input.