Neural Networks are convenient when mapping a function which behaves non-linearly. However, for Training and Testing purpose , Data is the most important piece of the puzzle.
The Neural Network Line Follower to be designed uses 8 Line sensing elements where each will return
1 : Line Detected
0 : Line Not Detected
So the possible dataset is the combination of 8 binary units arranged in different pattern leading to a total of
28 = 256 Samples of data.
I wrote the following MATLAB script to create the data for training the Neural Network.
Here:
bin holds the binary input sequence of 8 bits
out holds the output corresponding to the input bin
Such that:
if bin=[1 0 0 0 0 0 0 0] then out = -1 (Line Sensed on far left : Move Left)
The Neural Network Line Follower to be designed uses 8 Line sensing elements where each will return
1 : Line Detected
0 : Line Not Detected
So the possible dataset is the combination of 8 binary units arranged in different pattern leading to a total of
28 = 256 Samples of data.
I wrote the following MATLAB script to create the data for training the Neural Network.
function [bin,out]=DataGen(m)
% Function to Generate Training Data set for training neural network of a
% line follower
%
% [bin,out]=DataGen(number of inputs)
%
% It is a good practice to have an even number of input units for the
% NN Network to be trained
n=(2^m)-1;
bin=decimalToBinaryVector(0:n);
[p,q]=size(bin);
out=zeros(p,1);
bLeft=bin(:,1:(q/2));
bRight=bin(:,((q/2)+1):end);
wL=bi2de(bLeft,'left-msb');
wR=bi2de(bRight,'right-msb');
for i=1:p
if wL(i)>wR(i)
out(i)=-1;
end
if wL(i)<wR(i)
out(i)=1;
end
if wL(i)==wR(i)
out(i)=0;
end
end
end
Here:
bin holds the binary input sequence of 8 bits
out holds the output corresponding to the input bin
Such that:
if bin=[1 0 0 0 0 0 0 0] then out = -1 (Line Sensed on far left : Move Left)
if bin=[0 0 0 0 0 0 1 0] then out = 1 (Line sensed on right : Move Right)
if bin=[0 0 1 0 0 1 0 0] then out = 0 (Line sensed symetrically : Keep Moving Forward)
For a Neural Network, 0 is pretty much a perfection so it allocates a really small value (~0) such that it can be considered as zero.
For a Neural Network, 0 is pretty much a perfection so it allocates a really small value (~0) such that it can be considered as zero.
From the script above with 8 as a parameter via the following syntax:
[bin,out]=DataGen(8);
we get:
bin = 256 X 8 Input Data Matrix
out = 256 X 1 Output Data Matrix
In the screenshot of the varibles, Left Segment shows the input from the sensors while we have the expected output in the blue bounded box on right:
In the screenshot of the varibles, Left Segment shows the input from the sensors while we have the expected output in the blue bounded box on right:
These Data elements are ready to be used as Training Parameters for our Neural Network.
Further Development to be covered by subsequent posts.
Update 7/Sep/16 : Read Part II: Designing Neural Network
Peace Out.
Used:
Matlab 2016a
Further Development to be covered by subsequent posts.
Update 7/Sep/16 : Read Part II: Designing Neural Network
Peace Out.
Used:
Matlab 2016a