My neural network is getting trained but not yielding correct answers?plz help

1 view (last 30 days)
This code is written to form a relation between
  • two actuator's movement z1 and z2 with
  • laser points x,y coordinate.
basically aiming for two input,two output network. laser point is input and actuator position is output. i want to provide target to network that my laser needs to be directed to some particular location.The network must provide me actuator coordinates as output.
clear;
clc;
hold off;
format long;
filename = 'neural_network_model.xlsx';
%%input file contains laser coordinates and corresponding z1,z2 value.
point_Datar= xlsread(filename,'A1:Z300');
input =point_Datar(1:300,17:18);
%inputs in column 17,18,these are laser pointers x,y coordinates
ninput=(input(:,1) - min(input(:,1)))./(max(input(:,1)) - min(input(:,1)));
%%normalizing input 1
ninput(:,2)=(input(2) - min(input(2)))./(max(input(2)) - min(input(2)));
%normalizing input 2
input(:,1)-(ninput(:,1)*(max(input(:,1)) - min(input(:,1)))+min(input(:,1)))
%check
z1=point_Datar(1:300,7);
%read output 1,this is actuator 1s z coordinate
nz1=(z1 - min(z1))/(max(z1) - min(z1));
%normalize output 1
z1-(nz1*(max(z1) - min(z1))+min(z1))
%check output1 norm must result zero
z2=point_Datar(1:300,11);
%read output 2,this is actuator 2s z coordinate
nz2=(z2 - min(z2))/(max(z2) - min(z2));
z2-(nz2*(max(z2) - min(z2))+min(z2))
%check
output =[nz1 nz2];
%above line makes the output matrix
net = newff(ninput,output,[15 15],{'tansig','tansig'});
view(net);
net = train(net,ninput,output);
% Iterates gradient type of loop
trained_output= sim(net,ninput);
figure(1);plot(trained_output(:,1),trained_output(:,2),'*g');hold on;
plot(output(:,1),output(:,2),'sr');
input_zero=ninput;
input_zero(300,1)=0.0;
%making input 1 to be zero
input_zero(300,2)=0.0;
%making input 2 to be zero
trained_output1= sim(net,input_zero);
plot(trained_output(:,1),trained_output(:,2),'.r');
%%%check output..my laser lies on a triangular stand,two vertex with actuator and one vertex with ball-socket joint
param1=0.249977909490350;
%empirical value to measure a point inside a triangle
param2=0.500013614834919;
%empirical value to measure a point inside a triangle
a=point_Datar(1,1:3);
%first socket joint
b=[point_Datar(1,5:6) trained_output1(1,1)*(max(z1) - min(z1))+min(z1)]
%for actuator b -x,y are constant values and z is network prediction for actuator 1s position
d=[point_Datar(1,9:10) trained_output1(1,2)*(max(z2) - min(z2))+min(z2)]
%for actuator d-x,y are constant values and z is prediction for actuator 2s position
l=b-a;
%finding pos vector for line ab
m=d-a;
%finding pos vector for line ad
c=a+param1*l+param2*m;
%this gives me laser position on triangle abd
cros=cross(l,m);
%direction normal to ab and ad
syms p;
%line parameter
line=c+p*cros;
%line parameter p,laser is normal to two lines l,m at c
z=vpa(solve(line(3),p));
laserx=vpa(subs(line(1),p,z))
%Theo_X_Laser_point
lasery=vpa(subs(line(2),p,z))
%Theo_Y_Laser_point
%if neural network output is correct laserx and lasery must be zero.
As i make bothinput columns 0,0 for row 1. i get all output columns equal. column 1 value becomes equal to column 2 for all rows.
I dont understant where am i wrong.
Plz spot my error in program or else give me 2 input 2 output network code. Should i process my data in any other way?
  6 Comments
Greg Heath
Greg Heath on 5 Aug 2016
Apparently, you are not concerned about formatting your code so that someone will feel respected enough to help.
STRANGE!!!
sameer d
sameer d on 7 Aug 2016
Sorry for delay.jus now viewed the tutorial.please any neural network expert show some way out of this problem.

Sign in to comment.

Accepted Answer

Greg Heath
Greg Heath on 9 Aug 2016
Your input and target matrices are transposed
Why Hmin=1 instead of 0?
Where did you get Hmax = 50?? Search greg fitnet Hub
I = O = 2
Unecessary weight initialization. That is what configure does
Only use rng once: before outer loop
Have 100 nets. Choose one with smallest h with Rsq >= Rsqgoal
After you succeed
DESIGN THE INVERSE NET:
INPUT = A
TARGET = L
HOPE THIS HELPS
GREG
  3 Comments
Greg Heath
Greg Heath on 13 Aug 2016
Sorry, I wrote my last reply a few minutes ago before seeing this.
Bottom line:
You need to design another net to perform the inverse.
Hope this helps.
Greg

Sign in to comment.

More Answers (2)

Greg Heath
Greg Heath on 26 Jul 2016
Edited: Greg Heath on 26 Jul 2016
Since normalizations and data-divisions are defaults, I really don't understand what you are doing. If you want a 2-input/2-output regression net you should use the CURRENT regression/curve-fitting net FITNET which calls the generic net FEEDFORWARDNET.
What version of MATLAB and NNToolbox do you have?
>> ver
If your versions of MATLAB and the NNToolbox are 2007 or older, you have to use the OBSOLETE regression/curve-fitting net NEWFIT which calls the generic net NEWFF.
Regardless of whether you use NEWFIT or FITNET, Read the relevant documentation and examples obtained from the help and doc commands. Foe example,
help fitnet
doc fitnet
Also, you can reference previous posts in BOTH NEWSGROUP and ANSWERS with search words like
fitnet
greg fitnet
or
newfit
greg newfit
Reply if you need more help.
Greg
  1 Comment
sameer d
sameer d on 27 Jul 2016
Edited: sameer d on 27 Jul 2016
thanks,i would like to elaborate a little more.i train the network with laser lights movement on screen i.e x,y coordinare as input and actuator movement as output z1,z2 for two actuators.this data is obtained by experiment.basically i want actuator movement required to make the laser to reach any desired x,y coordinate on laser screen. The neural network i have used above is getting trainec but not yielding correct result.i have tried to predict actuator movement to reach 0,0 on laser screen.which is not working.ok i wd try with fitnet and come back. Thanks for reply. Based on above explanation if u could suggest some thing.it would be helpful.

Sign in to comment.


Greg Heath
Greg Heath on 28 Jul 2016
L = Lx,Ly laser coordinates input
At= Ax,Ay actuator coordinates target
Ay= Ax,Ay actuator coordinates output
DOCUMENTATION CODE(from help&doc fitnet)
[L,At] = laseractuator_dataset;
net = fitnet(10);
net = train(net,L,At);
view(net)
Ay = net(L);
perf = perform(net,At,Ay)
SIMPLE REVISION FOR "INITIAL" INVESTIGATION
[L,At] = laseractuator_dataset;
plot(L(1),L(2),'k'), hold on
plot(At(1),At(2),'b')
MSE00 = mean(var(At',1)) % REFERENCE MSE
net = fitnet; % H=10 DEFAULT
rng('default') % FOR REPRODUCIBILITY
[ net tr Ay E] = train(net,L,At);
% Ay = net(L); E = At-Ay
plot(Ay(1),Ay(2),'ro-')
Rsq = 1-mse(E)/MSE00
%See training record tr for trn/val/tst details
COMPREHENSIVE FOLLOWUP
Minimize H subject to performance constraint
Rsqtrn <= 0.995
using
net.trainParam.goal = 0.005*MSE00
For zillions of examples search both NEWSGROUP
and ANSWERS using
greg fitnet Hmin Hmax Ntrials
Hope this helps
Thank you for formally accepting my answer
Greg
  17 Comments
sameer d
sameer d on 21 Aug 2016
Thanks BUT NMSE values are also not so impressive.should i try something more
>> min(min((NMSE))) ans = 0.248717823086038 and the best i am getting for dH=8
min(min((NMSE))) ans = 0.24707 ADDITIONALLY
mean(var(t',1))*0.005 ans = 0.943076999999999
I would like to acknowledge you on my masters thesis,please permit me for same.
sameer d
sameer d on 25 Aug 2016
THIS IS THE BEST RESULT I HAVE OBTAINED.THANKS row =
7
col =
4
>> min(min((NMSE)))
ans =
4.775377230289548e-15
>>

Sign in to comment.

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!