hopfield-0.1.0.1: Hopfield Networks, Boltzmann Machines and Clusters

Safe HaskellNone

Hopfield.Hopfield

Contents

Description

Base Hopfield model, providing training and running.

Synopsis

Documentation

type Pattern = Vector IntSource

type Weights = Vector (Vector Double)Source

data LearningType Source

Constructors

Hebbian 
Storkey 

Instances

Hopfield data structure

data HopfieldData Source

Encapsulates the network weights together with the patterns that generate it with the patterns which generate it

Instances

weights :: HopfieldData -> WeightsSource

the weights of the network

patterns :: HopfieldData -> [Pattern]Source

the patterns which were used to train it

buildHopfieldData :: LearningType -> [Pattern] -> HopfieldDataSource

buildHopfieldData patterns: Takes a list of patterns and builds a Hopfield network (by training) in which these patterns are stable states. The result of this function can be used to run a pattern against the network, by using matchPattern.

Running

update :: MonadRandom m => Weights -> Pattern -> m (Maybe Pattern)Source

update weights pattern: Applies the update rule on pattern for the first updatable neuron given the Hopfield network (represented by weights).

Pre: length weights == length pattern

addPatterns :: LearningType -> HopfieldData -> [Pattern] -> HopfieldDataSource

Stores patterns in an already trained network. One has to ensure that this function is not over used, as this will decrease the capacity of the network.

repeatedUpdate :: MonadRandom m => Weights -> Pattern -> m PatternSource

repeatedUpdate weights pattern: Performs repeated updates on the given pattern until it reaches a stable state with respect to the Hopfield network (represented by weights). Pre: length weights == length pattern

updateChain :: MonadRandom m => HopfieldData -> Pattern -> m [Pattern]Source

Like repeatedUpdate, but collecting all patterns until convergence. The last pattern in the list is the converged pattern. The argument pattern is NOT prepended to the result list.

POST: The returned list is not empty.

matchPattern :: MonadRandom m => HopfieldData -> Pattern -> m (Either Pattern Int)Source

matchPatterns hopfieldData pattern: Computes the stable state of a pattern given a Hopfield network(represented by weights) and tries to find a match in a list of patterns which are stored in hopfieldData. Returns:

The index of the matching pattern in patterns, if a match exists The converged pattern (the stable state), otherwise

Pre: length weights == length pattern

computeH :: Weights -> Pattern -> Int -> IntSource

Computes the weighted sum of current neuron values, which will give us the value of the neuron (by taking the sign)

Energy

energy :: Weights -> Pattern -> DoubleSource

energy weights pattern: Computes the energy of a pattern given a Hopfield network (represented by weights). Pre: length weights == length pattern