- The first input argument in fullyConnectedLayer is the outputSize, i.e , the number of neurons in the next layer. So, fullyConnectedLayer(8, "Name", "myFullyConnectedLayer1") means 8 neurons in the next layer (all fully connected). Similarly for fullyConnectedLayer(1, "Name","myFullyConnectedLayer2") which is the last layer in this neural network (since th function to be approximated is 1-Dimensional in nature).
- featureInputLayer() takes in the numFeatures as the first input argument, as we are approximating a function which takes an 1-dimensional input, numFeatures = 1 here.
- The initial function is defined using an anonymous function fnc = @(x) x.^3.
- 80 data points in the range (-1,1) are generated from the function, where XTrain are the input data points and YTrain are the output values of the function.
- A neural network is designed with one input layer, one hidden layer with 8 fully connected neurons and a tanh activation function, one output layer with one fully connected neuron, and a regression layer specified for the output.
- The trainingOptions function is used to specify the training parameters, such as the optimizer (adam), maximum number of epochs, learning rate, shuffle interval, mini-batch size, plots, and verbosity.
- The trainNetwork function is used to train the neural network on the training data using the defined layers and opts.
- To test the accuracy of the trained network, 100 random test data points are generated and passed through the trained network using predict function and the output is stored in the variable YTest. A plot is then generated to compare the predicted and actual function outputs.