Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

annie::HopfieldNetwork Class Reference

#include <HopfieldNetwork.h>

Inheritance diagram for annie::HopfieldNetwork:

annie::Network List of all members.

Public Methods

 HopfieldNetwork (int size)
 HopfieldNetwork (int size, bool bias, bool bipolar)
 HopfieldNetwork (const char *filename)
virtual ~HopfieldNetwork ()
 Cleans up memory by getting rid of the weight matrix and neurons. More...

virtual void addPattern (int pattern[])
virtual real getEnergy ()
 Returns the energy at the current state of the network. More...

virtual real getEnergy (int pattern[])
virtual int getSize ()
 Returns the size of the patterns that can be stored (i.e., length of the pattern vector). More...

virtual void step ()
 Steps the network in time. More...

virtual int getTime ()
virtual int getPatternCount ()
virtual Matrix getWeightMatrix ()
 Returns a copy of the weight matrix that is used by this network. More...

virtual const char * getClassName ()
 Returns "HopfieldNetwork". More...

virtual void save (const char *filename)
virtual void setWeight (int i, int j, real weight)
virtual real getBias (int i)
virtual void setBias (int i, real bias)
virtual void setInput (int pattern[])
virtual void setInput (std::vector< int > &pattern)
virtual std::vector< int > getOutput ()
virtual std::vector< int > getNextOutput ()
virtual VECTOR getOutput (VECTOR &input)
virtual bool propagate (int pattern[], int timeout)
virtual bool propagate (std::vector< int > &pattern, int timeout)

Protected Methods

virtual bool _equal (std::vector< int > &p1, std::vector< int > &p2)

Protected Attributes

bool _bipolar
 true if patterns are bipolar (ie, elements are -1 or 1), false if not (elements are 0 or 1). More...

int _nPatterns
 The number of patterns that have been given to the network to be stored. More...

Matrix_weightMatrix
 The weight matrix of the network. More...

RecurrentNeuron ** _neurons
 The recurrent neurons, each of them is connected to everyone else with weights from the weight matrix. More...

int _time

Detailed Description

A Hopfield network - content addressable memory and energy. The Hopfield network is considered a landmark in the field of neural computing. This model can store a number of patterns and retrieve the correct pattern starting from a noisy or incomplete pattern so that a network can be trained to identify patterns or images. Hopfield proposed this model as a model of biological memory (often called "content addressable memory"), similar to the way a human brain recognizes an image based on the past experience or learning.

Hopfield also introduced another important idea by establishing a new connection between computation and physics with the concept of energy in his model and showed that computation can be viewed as a transition to lower energy states.


Constructor & Destructor Documentation

annie::HopfieldNetwork::HopfieldNetwork int    size
 

Creates a Hopfield network, which can store bipolar binary patterns (i.e., patterns consisting of -1's and 1's). Diagonal elments of the weight matrix will be zero. Neurons will NOT have a bias.

Parameters:
size  The size/number of bits of/in the patterns to be stored

annie::HopfieldNetwork::HopfieldNetwork int    size,
bool    bias,
bool    bipolar
 

Creates a Hopfield network, which can store binary patterns. Diagonal elments of the weight matrix will be zero.

Parameters:
size  The size/number of bits of/in the patterns to be stored
bias  true if the neurons are to have a bias, false otherwise
bipolar  true if patterns are bipolar (elements are -1 or 1), false if not (elements are 0 or 1).

annie::HopfieldNetwork::HopfieldNetwork const char *    filename
 

Loads a Hopfield network from a file.

See also:
save
Parameters:
filename  The name of the filename to load the network from
Exceptions:
Exception  on any error

virtual annie::HopfieldNetwork::~HopfieldNetwork   [virtual]
 

Cleans up memory by getting rid of the weight matrix and neurons.


Member Function Documentation

virtual bool annie::HopfieldNetwork::_equal std::vector< int > &    p1,
std::vector< int > &    p2
[protected, virtual]
 

virtual void annie::HopfieldNetwork::addPattern int    pattern[] [virtual]
 

Adds a pattern to the network by making suitable adjustments to the weight matrix.

Parameters:
pattern  The bipolar pattern (of getSize() length) to be stored
Exceptions:
Exception  If the given pattern is not bipolar (i.e., consisting of only -1s and 1s) and the network is designed for bipolar patters or if the pattern does not consist of 0s and 1s

virtual real annie::HopfieldNetwork::getBias int    i [virtual]
 

Get the bias at the given neuron

Parameters:
i  The neuron whose bias is wanted
Returns:
The bias

virtual const char* annie::HopfieldNetwork::getClassName   [virtual]
 

Returns "HopfieldNetwork".

Implements annie::Network.

virtual real annie::HopfieldNetwork::getEnergy int    pattern[] [virtual]
 

Returns the energy of the supplied pattern. Energy of a pattern depends on the weight matrix

virtual real annie::HopfieldNetwork::getEnergy   [virtual]
 

Returns the energy at the current state of the network.

virtual std::vector<int> annie::HopfieldNetwork::getNextOutput   [virtual]
 

Steps the network through one unit of time and returns the output.

Returns:
A vector v, where v[i] = output of the ith neuron

virtual VECTOR annie::HopfieldNetwork::getOutput VECTOR   input [virtual]
 

The HopfieldNetwork generally deals with vectors of integers only because the neurons are binary. But since this class implements the Network class, it must provide this function as well, which returns the same thing as setInput() following by getOutput() would, except that the neuron's output will be of type real instead of int

Implements annie::Network.

virtual std::vector<int> annie::HopfieldNetwork::getOutput   [virtual]
 

Returns the current outputs of the neurons.

Returns:
A vector v, where v[i] = current output at the ith neuron

virtual int annie::HopfieldNetwork::getPatternCount   [virtual]
 

The number of patterns that the network has been instructed to store This will be the same as the number of calls to addPattern

See also:
addPattern

virtual int annie::HopfieldNetwork::getSize   [virtual]
 

Returns the size of the patterns that can be stored (i.e., length of the pattern vector).

virtual int annie::HopfieldNetwork::getTime   [virtual]
 

The number of steps the network has taken since the last call to getOutput

See also:
getNextOutput , getOutput

virtual Matrix annie::HopfieldNetwork::getWeightMatrix   [virtual]
 

Returns a copy of the weight matrix that is used by this network.

virtual bool annie::HopfieldNetwork::propagate std::vector< int > &    pattern,
int    timeout
[virtual]
 

Sets the initial input of the network and then steps through time, returning true if the network converges before the given timeout.

Parameters:
pattern  The initial output of the network
timeout  The maximum number of steps the network should go through
Returns:
true if the pattern converges within the timeout, false otherwise

virtual bool annie::HopfieldNetwork::propagate int    pattern[],
int    timeout
[virtual]
 

Sets the initial input of the network and then steps through time, returning true if the network converges before the given timeout.

Parameters:
pattern  The initial output of the network
timeout  The maximum number of steps the network should go through
Returns:
true if the pattern converges within the timeout, false otherwise

virtual void annie::HopfieldNetwork::save const char *    filename [virtual]
 

Saves the network to a file

Todo:
Implement this!
Parameters:
filename  The name of the file to store the network into so that it can be loaded from there later

Implements annie::Network.

virtual void annie::HopfieldNetwork::setBias int    i,
real    bias
[virtual]
 

Sets the bias of the given neuron.

Parameters:
i  The neuron whose bias is to be set
bias  The bias value to give the ith neuron

virtual void annie::HopfieldNetwork::setInput std::vector< int > &    pattern [virtual]
 

Sets the initial output of the neuron to the values in the given vector of integers and sets time to 0.

Parameters:
pattern  A vector of integers containing the initial outputs of the neurons. The vector must contain getSize() elements, each -1 or 1 (if bipolar) or 0 or 1 if not.

virtual void annie::HopfieldNetwork::setInput int    pattern[] [virtual]
 

Sets the initial output of the neurons to the values in the given array and resets time to 0.

Parameters:
pattern  An array containing the initial outputs of the neurons. The array must contain getSize() elements

virtual void annie::HopfieldNetwork::setWeight int    i,
int    j,
real    weight
[virtual]
 

Sets the weight between the ith and jth neuron. Since the weights are symmetruc, the weight between neuron i and neuron j will be the same as the weight between neuron j and neuron i, which will be the same as the weight supplied.

Parameters:
i  The ith neuron
j  The jth neuron
weight  The weight of the link (i,j) and (j,i)

virtual void annie::HopfieldNetwork::step   [virtual]
 

Steps the network in time.


Member Data Documentation

bool annie::HopfieldNetwork::_bipolar [protected]
 

true if patterns are bipolar (ie, elements are -1 or 1), false if not (elements are 0 or 1).

RecurrentNeuron** annie::HopfieldNetwork::_neurons [protected]
 

The recurrent neurons, each of them is connected to everyone else with weights from the weight matrix.

int annie::HopfieldNetwork::_nPatterns [protected]
 

The number of patterns that have been given to the network to be stored.

int annie::HopfieldNetwork::_time [protected]
 

Matrix* annie::HopfieldNetwork::_weightMatrix [protected]
 

The weight matrix of the network.


The documentation for this class was generated from the following file:
Generated on Wed Apr 23 10:42:36 2003 for BioFilter by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002