|
5.2.3 Function Approximation in Two Dimensions
An FF network can have any number of inputs and outputs. In the previous two examples there was only one input. Here is an example with two inputs.
Read in the Neural Networks package.
In[1]:=
Generate data and look at the function.
In[2]:=

The training data is placed in x and y, where x is the input data and y is the output data.
You can modify the example by changing the function generating the data and by changing the number of neuron basis functions in the following initialization. Notice that you will obtain slightly different results even if you repeat the example without any changes at all. This is due to the randomness in the initialization algorithm of the FF network.
Check the dimensions of the data.
In[8]:=
Out[8]=
Out[9]=
There are 100 input-output data pairs with two-dimensional inputs and one-dimensional outputs.
Initialize an FF network with four neurons.
In[10]:=
Out[10]=
You can apply the initialized network to the input data and plot the network output. Compare the result with the true function in the previous plot.
Look at the initialized FF network.
In[11]:=

So far the network has only been initialized. Now it is time to train it.
Fit the FF network to the data.
In[13]:=

You can look at the result by evaluating the trained network at the input data points as follows.
Look at the result with the fitted FF network.
In[14]:=

Notice that there are usually several local minima. If you repeat the initialization and the training, you obtain different results.
The plot does not, however, show how the function looks in between the data points. By using NetPlot, which gives a plot based on the Mathematica command, Plot3D, you obtain a plot with any number of evaluation points. If you apply NetPlot to the training record you obtain a graphics array showing the evolution of the function approximation during the training.
In[16]:=

If you prefer an animation of the training progress, you can load <<Graphics`Animation` and then change the command to Apply[ShowAnimation,NetPlot[fitrecord,x,y,Intervals 1, DataFormat FunctionPlot,DisplayFunction Identity]].
You can obtain a histogram of the errors between the network output and the true output with NetPlot by choosing DataFormat ErrorDistribution. This might help you to find outliers in the data and to explain if something goes wrong.
In[17]:=

Each bar shows the number of samples given an estimation error within the borders of the bars.
Of course, you can also obtain the previous plot by using the command Histogram in the following way.
In[18]:=

|