I'm getting started with building an artificial neural network and testing it with a simple example (see code below).
I'm trying to get the artificial neural network (using fitnet) to predict that the function is y=a*5+b.*c+7*c. The neural network is successfully trained. However, when I try using the function:
y = b2 + LW*tanh(b1+IW*x)
followed by a reverse mapminmax, I do not obtain the correct value.
In the code below, I have tried defining
X = [0.5, 0.5, 0.5]
The output is (y2 is obtained by using the reverse mapminmax, y1 is using sim(net,x), and y1compare is the actual output target):
y2 = 9.5759y1 = 6.2795y1compare = 6.2500
My entire code is below:
clcclear alla=rand(1,1000);b=rand(1,1000);c=rand(1,1000);n=rand(1,1000)*0.05;y=a*5+b.*c+7*c+n;I=[a; b; c];O=y;% Create network for curve fitting
hiddenLayerSize = 10; % Number of intermediate network neurons
net = fitnet(hiddenLayerSize);% Setting the pre and post process data
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};% Setting the sample size
net.divideFcn = 'dividerand'; % Split random data
net.divideMode = 'sample';net.divideParam.trainRatio = 70/100;net.divideParam.valRatio = 15/100;net.divideParam.testRatio = 15/100;net=train(net,I,O);% syms p q r real
% X = [p,q,r]';
X = [0.5 0.5 0.5]';b1 = net.b{1}b2 = net.b{2}IW = net.IW{1,1};LW = net.LW{2,1};[tn, tsettings] = mapminmax(O);tsettingsyn = b2 + LW * tanh(b2 + (IW * X))y2 = mapminmax.reverse(yn,tsettings)y1 = sim(net,X)y1compare = X(1)*5+X(2).*X(3)+7*X(3)
Thanks in advance!
Best Answer