I'm trying to create a neural network for the function y=x^2 with:
- 1 input layer
- 1 output layer
- 2 hidden layers, with each layer having 4 neurons
The code is as follows (Sample3.m):
% providing inputs and outputs
x=-10:0.1:10;y=x.*x;% creating 2 hidden layers with 4 neurons each
hidden_layer_l2=[4 2];% tansig=transfer function for layer 1
% logsig=transfer function for layer 2
% purelim=transfer function for output layer
network_l2=newff(x,hidden_layer_l2,{'tansig' 'logsig' 'purelin'},'trainlm');view(network_l2);net_train_l2=train(network_l2,x,y);% simulate the data
simulated_data_l2=sim(net_train_l2,x);plot(x,y,x,simulated_data_l2,'x');
The following error popped up:
Error using network/train (line 272)Output data size does not match net.outputs{2}.size.Error in Sample3 (line 40)net_train_l2=train(network_l2,x,y);
I've browsed through the internet and came to know that I've to supply x*2 matrix to make it work, and currently I'm passing a vector. I'm new to matlab and neural networks and not sure how to make proper input set and output set (x and y).
Any help would be greatly appreciated !!
Best Answer