Following program demonstrates the use of a Feed-forward network in Matlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab Example 1
% Learning XOR function using a MLP
% Create a FFN
net = newff([0 1; 0 1], [2 1], {'logsig', 'logsig'},'traingd');
%Training patterns
P = [0 0 1 1; 0 1 0 1];
T = [0 1 1 0];
% Training parameters
net.trainParam.show = 100;
net.trainParam.lr = 0.8;
net.trainParam.epochs = 3000;
net.trainParam.goal = 1e5;
%Train the network
[net,tr] = train(net, P, T);
% Test the network
Y = sim(net, P)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Following program demonstrates the use of RBFN in matlab to learn a nonlinear function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB EXAMPLE 2
% Radial Basis Function Network (RBFN)
clear all;
% Data set for training
x = [0:4:200];
yd = sqrt(x);
spread = 20;
% Create a RBF network
net = newrb(x, yd, 1e-5,20);
%test data
P = [0:0.01:200];
T = sqrt(P);
T1 = sim(net, P);
%mean square error
mse(T1-T)
figure(2)
plot(P,T,'r', P, T1, 'b--');
legend('Desired output', 'Actual Output');
xlabel('Input');
ylabel('Output');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment