MATLAB Answers

Improve NN performance and prediction error

1 view (last 30 days)
Ande Mandoyi
Ande Mandoyi on 11 Sep 2020
Commented: Ande Mandoyi on 12 Sep 2020
I've been stuck on a homework question for a while now. 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.
My code is as follows. I get keep getting large prediction errors for unkknown dataset "input". Please help
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
%feed-forward neural network with one hidden layer
%hidden layer has 10 hidden neurons
%10000 epochs training cycles, stops training when the...
%error is less or equal to 1e-25/ after 10000 epochs
%hidden neurons use a tan sigmoid activation function
%output neurons use a linear activation function
%learning rate = 0.01
%Levenberg-Marquad back-propogation is used
net = newff(minmax(x),[10 1],{'tansig','purelin'},'trainlm');
net.trainparam.epochs = 10000;
net.trainparam.goal = 1e-25; = 0.02;
net = train(net,x,y);
input1 = -5:0.1:5; %first input
input2 = 0:0.05:5; %2nd input
input = [input1;input2];
ynet = net(input);
plot(y-ynet) %error series plot
title('Error series plot')

Answers (0)

Community Treasure Hunt

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

Start Hunting!