NN function approximation: What's wrong with my code?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ande Mandoyi
am 8 Sep. 2020
Kommentiert: Ande Mandoyi
am 8 Sep. 2020
I have just started learning neural networks and have been stuck on a homework question for quite a while. the question is as follows:
Design a feed forward multi-layer neural network to approximate the function y=sin(x1)+cos(x2). Here, -5<x1<5 and 0<x2<5. Please use x1 = (rand(1,50)-0.5)*10; x2 = rand(1,50)*5; to get the samples to train the neural network. Finally, please draw the prediction error series y - ynet for the inputs x1=-5:0.1:5 and x2=0:0.05:5.
Here's my code:
x1 = (rand(1,50)-0.5)*10; %training sample one
x2 = rand(1,50)*5; %training sample two
x = [x1;x2];
y=sin(x1)+cos(x2); %targeted output
net = newff(minmax(x),[20 1],{'tansig','purelin'},'trainlm');
net.trainparam.epochs = 10000;
net.trainparam.goal = 1e-25;
net.trainparam.lr = 0.01;
net = train(net,x,y);
input1 = -5:0.1:5;
input2 = 0:0.05:5;
input = [input1;input2];
y=sin(input1)+cos(input2);
ynet = net(input);
plot(y-ynet)
grid
The prediction error I get is very high.
Thanks in advance
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 8 Sep. 2020
If you sort your y and ynet based upon input1, then you can see that the error is especially bad towards the right hand side (input1 close to 5). If you sort based upon input2, then there are multiple not-good places but especially towards input2 close to 5.
If you scatter(x1, x2), then at least for the run I did, the number of random samples close to x1 = 5 or x2 = 5 is not high.
I think you need more training data.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!