output in neural network

53 views (last 30 days)
niranjan sane
niranjan sane on 10 Apr 2012
hello all, i have a query i have written a code in matlab which forecast daily water demand but whenever i run the code it gives different results how to fix the results in a particular band also tell me if my code is correct. plz do rep if and tell me if i have to make any corrections in the code i have tried using learning function as traindgm instead of trainlm which learning function is better in both?????
% two inputs neurons as average humidity and water demand of previous day and one neuron in output layer as weekly water demand.
% t=forecasted water demand
% s=actual water demand
%Traing data-7years
%Previous waterdemand
%Output water demand
%Testing data-1 year
%Previous day waterdemand
%output for comparison
%Input data preprocessing
%Create neural network
net=newff(minmax(pn),[10 1],{'tansig','purelin'},'trainlm');
%Train neural network
net=train (net,pn,tn);
%Simulate neural network with test samples
%Post Processing
%Plot between Actual and predicted values
%Plot between Actual and predicted values
hold on;
% Current plot held
ylabel('Water Demand(MLD)');
title('Comparison between neural network output and actual water demand')
legend('forecasted water demand','Actual water Demand');
hold off;
%Plot Regression

Answers (1)

Eike on 10 Apr 2012
1. I am unable to find any documentation on the function newff and what it does. I would be pleased if someone could show me the relevant parts of the documentation...?
2. It is correct for NNs to produce different output for the same input if they are trained separately. This is due to the fact that the initial weights of the neurons are chosen randomly each time. Therefore, the output of your script will be a different NN each time you run it. I think there is a possibility to assign specific initial weights, though.
3. In your code, you do the input shifting by hand. There are tools provided by the NN toolbox to ease that process. Normally, you would do something like the following:
% external input series: humidity
externalInputSeries = tonndata(data(1:end, 5), false, false);
% target (and feedback input!) series: water demand
targetSeries = tonndata(data(1:end, 8), false, false);
% the water demand of the previous day is used as an input
feedbackDelay = 1;
% the average humidity of the previous day is used as an external input
inputDelay = 1;
% use 10 Neurons in the network
hiddenLayerSize = 10;
% create a NARX net
net = narxnet(inputDelays, feedbackDelays, hiddenLayerSize);
% Prepare the Data for Training and Simulation
[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'time'; % Divide up every value
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Choose a Training Function
% For a list of all training functions type: help nntrain
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Train the Network
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
% % Test the Network
outputs = net(inputs,inputStates,layerStates);
% show a graphical representation of the NN
I do not guarantee that all of the above code is correct, but I've recently solved a similar problem and the above approach worked for me. In my opinion it is nicer than yours since it automates all handling of the test data set.
You can get some inspiration on what is possible by using the graphical NN tool and creating code from it.
Greetings and good luck,

Community Treasure Hunt

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

Start Hunting!

Translated by