9.2.1 DiscreteTime TwoDimensional 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 twodimensional 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 discretetime 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 TrajectoriesTrue. 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 DataFormatEnergy 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}},DataFormatEnergy]
Try 30 data pattern vectors at the same time. To avoid 30 trajectory and energy plots you can instead choose the option DataFormatParametricPlot. You can use the command RandomArray from the standard addon 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,DataFormatParametricPlot,PlotRange{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.
