% Training nonlinear layers (general_trainbp.m).
clf;
figure(gcf)
setfsize(500,200);
echo on
clc
% INITFF - Initializes a feed-forward network.
% TRAINBP - Trains a feed-forward network with backpropagation.
% SIMUFF - Simulates a feed-forward network.
% PATTERN ASSOCIATION WITH A LINEAR NEURON:
% Using the above functions a neuron is trained
% to respond to specific inputs with target outputs.
pause % Strike any key to continue...
clc
% DEFINING A VECTOR ASSOCATION PROBLEM
% ====================================
% P defines four 2-element input vectors (column vectors):
load screen.dat ;
P = screen';
% T defines the associated 1-element targets (column vectors):
load TS.dat ;
T = TS';
pause % Strike any key to design the network...
clc
% DESIGN THE NETWORK
% ==================
% INITFF is used to initialize the weights and biases for
% the LOGSIG neuron.
%
[W1,b1,W2,b2] = initff(P,8,'logsig',T,'purelin')
clc
% TRAINING THE NETWORK
% ====================
% TBP1 uses backpropagation to train 1-layer networks.
df = 10 ; % Frequency of display.
me = 100 ; % Maximum number of epochs to train.
eg = 0.01 ; % Sum-squared error goal.
lr = 0.0001 ; % Learning rate.
tp = [ df me eg lr ] ;
% Training begins...please wait...
[W1,b1,W2,b2,ep,tr] = trainbp(W1,b1,'logsig',W2,b2,'purelin',P,T,tp);
% ...and finishes.
% TRAINBP has returned new weight and bias values, the number
% of epochs trained EP, and a record of training errors TR.
pause % Strike any key to see a plot of errors...
clc
% PLOTTING THE ERROR CURVE
% ========================
% Here the errors are plotted with respect to training epochs:
ploterr(tr,eg);
pause % Strike any key to use the classifier...
clc
% USING THE PATTERN ASSOCIATOR
% ============================
% We can now test the associator with the origonal
% inputs and see if it returns the target.
B = simuff(P,W1,b1,'logsig',W2,b2,'purelin')
A = round(B)
T
E = T - A
errors=sum(abs(E))
pause % strike any key to go on
load applns.dat;
PA=applns';
AA=round(simuff(PA,W1,b1,'logsig',W2,b2,'purelin'));
save predict2.dat AA -ascii
echo off
disp('End of general_trainbp.m')
This page hosted by
Get your own Free Home Page