Neural Network Input Size and Data Issue - HELP

23 views (last 30 days)
Hi,
I am trying to code a feed forward neural network to predict future significant wave heights given known previous wave height values.
I have two inputs to my network. These are the wave heights over a year for two weather buoys. One input for my network is the wave heights over a year for one weather buoy (8744 data values), and the other input is the wave height values over one year for the second buoy (again 8744 data values).
I am coming up with the error 'Number of inputs does not match net.numInputs.' Can someone help spot my mistake please?
I am not sure what value I should be using in 'net.inputs{1}.size'.
My code is as follows:
%Data Selection
X = xlsread('2014_comp.xlsx', 'F5:F8748');
Y = xlsread('2014_comp.xlsx', 'L5:L8748');
%Network Architecture
net = feedforwardnet; % create feed forward network
net.numInputs = 2; % set number of inputs
net.inputs{1}.size = 1; % set size of input 1
net.inputs{2}.size = 1; % set size of input 2
net.numLayers = 1; % add 1 layer to network
net.layers{1}.size = 10; % assign number of neurons in layer
net.inputConnect(1) = 1; % connect input 1 to layer 1
net.inputConnect(2) = 1; % connect input 2 to layer 1
net.biasConnect(1) = 1; % connect bias to layer 1
net.biases{1}.learnFcn = 'learnp'; % set bias learning function
net.biases{1}.initFcn = 'initzero'; % set bias init function
net.outputConnect(1) = 1; %connect layer 1 to output
net.layers{1}.transferFcn = 'tansig'; % set layer transfer function to hyperbolic tangent sigmoid
net.inputWeights{1}.initFcn = 'initzero'; % set input wieghts init function
net.inputWeights{1}.learnFcn = 'learnp'; % set input weight learning function
net.initFcn = 'initlay'; % set network init function
net.trainFcn = 'trainrp'; % set network training function
net.performFcn = 'mse'; % set network performance evaluation function
%Training/Testing/Validation Ratio
net.divideParam.trainRatio = 0.66; % set proportion of data for training
net.divideParam.valRatio = 0.17; % set proportion of data for validation
net.divideParam.testRatio = 0.17; % set proportion of data for testing
view(net)
%Network Training
net = train(net,X); %Train the network
Thanks, James

Accepted Answer

Greg Heath
Greg Heath on 11 Feb 2016
You are making this harder than it is. For the 1st time through all you have to specify is
1. Type of network
a fitnet for regression on curve-fitting
b. patternnet for classification or pattern-recognition
c. timedelaynet, narnet or narxnet for timeseries prediction
(fitnet and patternnet are special cases of feedforwardnet which never
has to be called explicitly)
2. input % size(input) = [ I N } for N I-dimensional Inputs
3. target % size(target) = [ O N ] for N O-dimensional Output targets
4. Ntrials: The number of candidate designs with different random data
divisions and random initial weights.
Then modify the code in the help and/or doc documentation. For example, use the commands
help fitnet
and
doc fitnet
to obtain code for fitnet. Put this code in a loop for ntrial = 1: Ntrials for different random data divisions and random initial weights.
This is the simplest code that I would use:
[ x t ] = simplefit_dataset;
vart = var(t,1)% Reference MSE
net = fitnet;
rng('default') % Needed for design duplication
for i = 1:Ntrials
net = configure(net,x,t);
[ net tr y e ] = train(net,x,t);
NMSE(i,1) = mse(e)/ vart; % Normalized MSE
end
output = NMSE
All 10 designs will be terrific because this is a simple data set. For other data I usually try to find the minimum number of hidden nodes (H, fitnet(H)) that will yield NMSE <= 0.01 ( i.e., the net successfully models 99% of the target variance)
Hope this helps.
Thank you for formally accepting my answer
Greg

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!