multi layer digit recognition
16 views (last 30 days)
Show older comments
i am working on simple codes in matlab for neural networks
i need matlab code for network to recognize numbers 0 to 9 {binary numbers recognition}...and training and testing of network by multi layer perceptron.
those are my input
%perceptron digit recognition
clc
%datas
%Original inputs
d0=[0;1;1;1;0;1;0;0;0;1;1;0;0;0;1;1;1;0;0;0;1;1;0;0;0;1;0;0;0;1;0;1;1;1;0];
d1=[0;0;1;0;0;0;1;1;0;0;0;0;1;0;0;0;0;1;0;0;0;0;1;0;0;0;0;1;0;0;0;1;1;1;0];
d2=[1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1];
d3=[1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1];
d4=[0;0;0;1;0;0;0;1;1;0;0;1;0;1;0;1;0;0;1;0;1;1;1;1;1;0;0;0;1;0;0;0;0;1;0];
d5=[1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;0;0;0;0;1;1;0;0;0;1;1;1;1;1;1];
d6=[1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;0;0;0;0;1;1;0;0;0;1;1;1;1;1;1];
d7=[1;1;1;1;1;0;0;0;0;1;0;0;0;1;0;0;0;1;0;0;0;1;0;0;0;0;1;0;0;0;0;1;0;0;0];
d8=[1;1;1;1;1;1;0;0;0;1;1;0;0;0;1;1;1;1;1;1;1;0;0;0;1;1;0;0;0;1;1;1;1;1;1];
d9=[1;1;1;1;1;1;0;0;0;1;1;0;0;0;1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1];
% Added bias
b=1;
d0=[1;1;1;1;1;1;0;0;0;1;1;0;0;0;1;1;1;0;0;0;1;1;0;0;0;1;0;0;0;1;0;1;1;1;0;b];
d1=[0;0;1;0;0;0;1;1;0;0;0;0;1;0;0;0;0;1;0;0;0;0;1;0;0;0;0;1;0;0;0;1;1;1;0;b];
d2=[1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;b];
d3=[1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1;b];
d4=[0;0;0;1;0;0;0;1;1;0;0;1;0;1;0;1;0;0;1;0;1;1;1;1;1;0;0;0;1;0;0;0;0;1;0;b];
d5=[1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1;b];
d6=[1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1;0;0;0;1;1;0;0;0;1;1;1;1;1;1;b];
d7=[1;1;1;1;1;0;0;0;0;1;0;0;0;1;0;0;0;1;0;0;0;1;0;0;0;0;1;0;0;0;0;1;0;0;0;b];
d8=[1;1;1;1;1;1;0;0;0;1;1;0;0;0;1;1;1;1;1;1;1;0;0;0;1;1;0;0;0;1;1;1;1;1;1;b];
d9=[1;1;1;1;1;1;0;0;0;1;1;0;0;0;1;1;1;1;1;1;0;0;0;0;1;0;0;0;0;1;1;1;1;1;1;b];
2 Comments
Greg Heath
on 9 Apr 2012
I am confused. Please explain exactly what the inputs and targets are. What are the dimensions of the input and target matrices?
Greg
Accepted Answer
Greg Heath
on 12 Apr 2012
yahya m about 6 hours ago
>UNFORTUNATELY i dont have good experience in NN because iam new... but for inputs ok and for training i am looking for matlab code for NN IN THE FORM OF
>p = [d0; d1; d2; d3 ; d4 ; d5 ; d6 ; d7 ; d8 ; d9]';
INCORRECT. REMOVE THE SEMICOLON TO SEE WHAT THAT GIVES YOU. THEN COMPARE WITH WHAT I HAVE WRITTEN PREVIOUSLY.
>t = eye(10);
>PR = zeros(36,10);
>PR(:,10) = 1;
INCORRECT. DELETE PR
class = vec2ind(t)
>net = newp(PR,3,'hardlim');
NO. USE NEWFF, NEWFIT or PATTERNNET
net = newff(p,t,H); % H = number of hidden nodes.
help/doc newff
>net.trainParam.epochs = 10;
NO. USE ALL AVAILABLE DEFAULTS. IF ANY DEFAULT IS FOUND TO BE INSUFFICIENT, CHANGE IT AND RERUN.
>net = train(net, p, t);
>a = sim(net, d')
NO. WHAT IS d'???
a = sim(net,p);
classa = vec2ind(a)
Nerr = sum(classa ~= class) % NUMBER OF CLASSIFICATION ERRORS
>LOOK FOR NEWP I NEED THE CODE OF THIS TYPE TO BE ENTRRED IN MATLAB IN ORDER TO EXAMINE THE NETWOR ABILITY TO RECOGNIZE THE DIGITS.
NO. DEPENDING ON THE TOOLBOX VERSION:
help newff
doc newff
help fitnet % REPLACED NEWFF IN LATEST VERSIONS OF TOOLBOX
doc fitnet
help patternet % NEW. SPECIALIZED FOR PATTERN RECOGNITION AND CLASSIFICATION.
doc patternnet
SEE THE CLASSIFICATION DEMOS IN THE TOOLBOX.
Hope this helps.
Greg
0 Comments
More Answers (1)
Greg Heath
on 11 Apr 2012
%You don't need all of those semicolons to represent a column vector. Just transpose the corresponding row vector.
x = [ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 ]; % Input Matrix
t = eye(10); % Target Matrix
[ I N ] = size(x) % = [ 35 10 ]
[ O N ] = size(t) % = [ 10 10 ]
Neq = N*O % = 100 No. of training equations
% For an I-H-O MLP with H hidden nodes, the number of unknown weights (includes biases) is
%Nw = (I+1)*O+(H+1)*O
% For training to convergence without regularization or validation stopping, Neq >= Nw which yields the following upper bound on H:
Hub = floor((Neq-O)/(I+O+1)) % = 1
% Therefore H = 0 (Linear Classifier) and H = 1 could be used if they perform well enough. However, to mitigate measurement error, noise and interference on nontrainingdata, it is desired that H << Hub. Obviously, there is not enough data here for that.
% Common solutions when there is only one data example per class
1. Add enough noisy versions of the input vectors to increase N enough so that Neq >> Nw (i.e., H << Hub) for any given value of H.
2. Use additional noisy vectors so that N is large enough to yield reasonable numbers of vectors for training, validation and test subsets. Then enable validation stopping which does not require H << Hub.
3. Use regularization (help/doc trainbr) which also does not require H << Hub.
Very often I search over a hidden node outer loop H = Hmin:dH:Hmax with a random weight initialization inner loop (weighttrial = 1:10) to find the smallest value of H that will yield acceptable results.
Look at the several classification demos in the Neural network Toolbox.
Hope this helps.
Greg
2 Comments
Greg Heath
on 11 Apr 2012
I don't understand the purpose of the "add bias" version. This results in a constant row that is ignored by the training programs.
If you are adding it because you want a bias term in the hidden node input, DON'T ... it is always automatically included.
Hope this helps.
Greg
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!