Hi i found this code somewhere with little info with it. it's suppose to be a backpropagation neural network code. but it seem to be lacking of something like weight and bias. is the code correct? is it test-while-train backpropagation neural network? thanks
% --- Executes on button press in pushbutton6.
%~~~~~~~~~~~[L1 L2 1];first hidden layer,second & output layer~~~~~
layer = [11 15 1];
myepochs = 30;
attemption = 1; %i;
mytfn = {'tansig' 'tansig' 'purelin'};
%~~~~~~load data~~~~~~~~~~~~~~~~~~~~~~~
m = xlsread('D:\MATLAB\datatrain.csv');
%~~~~~~convert the data in Matrix form~~~~
[row,col] = size(m);
P = m(1:row,1:10)';
T1 = m(1:row, col)'; % target data for training...last column
net = newff([minmax(P)],layer,mytfn,'trainlm'); %nnet
net.trainParam.epochs = myepochs; % how many time newff will repeat the training
net.trainParam.showWindow = true;
net.trainParam.showCommandLine = true;
net = train(net,P,T1); % start training newff with input P and target T1
Y = sim(net,P); % training
save 'net7' net;
% --- Executes on button press in pushbutton4.
%~~~~~~load data~~~~~~~~~~~~~~~~~~~~~~~
mt = xlsread('D:\MATLAB\datatest.csv');
%~~~~~~convert the data in Matrix form~~~~
[row1,col1] = size(mt);
Pt= mt(1:row1,1:10)';
Tt = mt(1:row1, col1)';
load 'net7' -mat;
Yt= sim(net,Pt);
%~~~~~~~final result of the neural network~~~~~~~~
[r,c]=size(Yt);
result=Yt(c);
if result>0.7
error=1-result;
set(handles.edit39,'String','yes')
set(handles.edit40,'String',num2str(error))
set(handles.edit41,'String','Completed')
data1=[num2str(result) ];
fid = fopen('D:\MATLAB\record.csv','a+');
fprintf(fid,[data1,'\n']);
fclose(fid);
else
set(handles.edit39,'String','no')
set(handles.edit40,'String',num2str(result))
set(handles.edit41,'String','Completed')
data1=[num2str(result) ];
fid = fopen('D:\MATLAB\record.csv','a+');
fprintf(fid,[data1,'\n']);
fclose(fid);
end
The code is correct. Neural network weights and biases are stored inside net
structure, you can access them via net.IW
and net.LW
structures. Biases are stored inside net.b
. This code train a network using inputs P
and targets T1
, splitting them in training, testing and validations subsets used during training. Check the documentation for further information about training procedure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.