Documentation /  Neural Networks /  Hopfield Networks /  Examples /

IntroductionDiscrete-Time Classification of Letters

9.2.1 Discrete-Time Two-Dimensional Example

Load the Neural Networks package.

In[1]:=<<NeuralNetworks`

In this small example there are two pattern vectors {1,-1} and {-1,1}. Since the vectors are two-dimensional you can display the results to illustrate the outcome.

Generate and look at class vectors.

In[2]:=x={{1,-1},{-1,1}};
NetClassificationPlot[x]

The two pattern vectors are placed in the corners of the plot. The idea is now that disturbed versions of the two pattern vectors should be classified to the correct undisturbed pattern vector.

Define a discrete-time Hopfield network.

In[4]:=hop = HopfieldFit[x]

Out[4]=

Since the discrete Hopfield network is the default type you do not have to specify that you want this type.

Some descriptive information is obtained by using NetInformation.

In[5]:=

Out[5]=

A new data pattern may be classified by processing it with the obtained model.

Evaluate the network for some disturbed data vectors.

In[6]:=hop[{0.4,-0.6}]

Out[6]=

More information about the evaluation of the Hopfield network on data vectors can be obtained by using NetPlot. The default is to plot the state trajectories as a function of time.

Plot the state vectors versus time.

In[7]:=NetPlot[hop, {{0.4, -0.6}}]

It might be interesting to obtain the trajectories for further manipulation. They can be obtained using the evaluation rule with the option TrajectoriesRuleTrue. Then the trajectories are returned instead of only the final value, which is the default.

Obtain the state trajectory.

In[8]:=

Out[8]=

The trajectory is the numerical solution to Eq. (2.26) describing the network; see Section 2.7, Hopfield Network.

NetPlot can also be used for several patterns simultaneously.

Evaluate two data vectors simultaneously.

In[9]:=res = NetPlot[hop, {{0.4, -0.6}, {0.6, 0.7}}]

By giving the option DataFormatRuleEnergy you obtain the energy decrease from the initial point, the data vector, to the convergence point as a function of the time.

Look at the energy decrease.

In[10]:=res = NetPlot[hop, {{0.4, -0.6}, {0.6, 0.7}},DataFormatRuleEnergy]

Try 30 data pattern vectors at the same time. To avoid 30 trajectory and energy plots you can instead choose the option DataFormatRuleParametricPlot. You can use the command RandomArray from the standard add-on package Statistics`ContinuousDistributions` to generate random vectors.

Plot a contour plot with state vector trajectories.

In[11]:=<< Statistics`ContinuousDistributions`
x = RandomArray[UniformDistribution[-1, 1], {10, 2}];
NetPlot[hop,x,DataFormatRuleParametricPlot,PlotRangeRule{-1.2,1.2}]

All trajectories converge to {-1,1} or {1,-1}, which are the two pattern vectors used to define the Hopfield network with HopfieldFit.

IntroductionDiscrete-Time Classification of Letters


Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information