Thursday, April 3, 2008

Matlab's NN Toolbox

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');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

No comments:

 
pre { margin: 5px 20px; border: 1px dashed #666; padding: 5px; background: #f8f8f8; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ }