som-7.4.1: Self-Organising Maps.

Copyright(c) Amy de Buitléir 2012-2014
LicenseBSD-style
Maintaineramy@nualeargais.ie
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Datamining.Pattern

Contents

Description

Tools for identifying patterns in data.

Synopsis

Patterns

class Pattern p where Source

A pattern to be learned or classified.

Associated Types

type Metric p Source

Methods

difference :: p -> p -> Metric p Source

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 -> Metric p -> p -> p Source

makeSimilar 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.

Instances

Numbers as patterns

If you wish to use, say, a Double as a pattern, one option is to use no-warn-orphans and add the following to your code:

instance Double => Pattern Double where
  type Metric Double = Double
  difference = absDifference
  makeSimilar = adjustNum

adjustNum :: (Num a, Ord a, Eq a) => a -> a -> a -> a Source

absDifference :: Num a => a -> a -> a Source

Numeric vectors as patterns

Raw vectors

If you wish to use raw numeric vectors as a pattern, one option is to use no-warn-orphans and add the following to your code:

instance (Floating a, Fractional a, Ord a, Eq a) => Pattern [a] where
  type Metric [a] = a
  difference = euclideanDistanceSquared
  makeSimilar = adjustVector

adjustVector :: (Num a, Ord a, Eq a) => [a] -> a -> [a] -> [a] Source

adjustVector target amount vector adjusts vector to move it closer to target. The amount of adjustment is controlled by the learning rate r, which is a number between 0 and 1. Larger values of r permit more adjustment. If r=1, the result will be identical to the target. If amount=0, the result will be the unmodified pattern.

euclideanDistanceSquared :: Num a => [a] -> [a] -> a Source

Calculates the square of the Euclidean distance between two vectors.

magnitudeSquared :: Num a => [a] -> a Source

Normalised vectors

data NormalisedVector a Source

A vector that has been normalised, i.e., the magnitude of the vector = 1.

Instances

normalise :: Floating a => [a] -> NormalisedVector a Source

Normalises a vector

Scaled vectors

data ScaledVector a Source

A vector that has been scaled so that all elements in the vector are between zero and one. To scale a set of vectors, use scaleAll. Alternatively, if you can identify a maximum and minimum value for each element in a vector, you can scale individual vectors using scale.

Instances

Show a => Show (ScaledVector a) 
(Fractional a, Ord a, Eq a) => Pattern (ScaledVector a) 
type Metric (ScaledVector a) = a 

scale :: Fractional a => [(a, a)] -> [a] -> ScaledVector a Source

Given a vector qs of pairs of numbers, where each pair represents the maximum and minimum value to be expected at each index in xs, scale qs xs scales the vector xs element by element, mapping the maximum value expected at that index to one, and the minimum value to zero.

scaleAll :: (Fractional a, Ord a) => [[a]] -> [ScaledVector a] Source

Scales a set of vectors by determining the maximum and minimum values at each index in the vector, and mapping the maximum value to one, and the minimum value to zero.