MATLAB: How to design a typical I-H-O net with Ntrn training examples

hubneural networkneural networksntrials

I have a code as follows :
close all, clear all, clc, plt = 0
load('input1.txt')
%load input
load ('target1.txt')
%normalizing data
input=input1';
target=target1';
input = mapminmax(input);
target = mapminmax(target);
x=input;
t=target;
% x = -2:0.1:2;
% t = sin(pi*x/2);
% [ x, t ] = simpleclass_dataset;
[ I N ] = size(x) % [ 2 1000 ]
[ O N ] = size(t) % [ 4 1000 ]
trueclass = vec2ind(t); %vec2ind Transform vectors to indices.
class1 = find(trueclass==1);
class2 = find(trueclass==2);
class3 = find(trueclass==3);
class4 = find(trueclass==4);
N1 = length(class1) % 243
N2 = length(class2) % 247
N3 = length(class3) % 233
N4 = length(class4) % 277
x1 = x(:,class1);
x2 = x(:,class2);
x3 = x(:,class3);
x4 = x(:,class4);
plt = plt + 1
hold on
plot(x1(1,:),x1(2,:),'ko')
plot(x2(1,:),x2(2,:),'bo')
plot(x3(1,:),x3(2,:),'ro')
plot(x4(1,:),x4(2,:),'go')
Hub = -1+ceil( (0.7*N*O-O)/(I+O+1)) % 399
Hmax = 40 % Hmax << Hub
dH = 4 % Design ~10 candidate nets
Hmin = 2 % I know 0 and 1 are too small
rng(0) % Allows duplicating the rsults
j=0
for h=Hmin:dH:Hmax
j = j+1
net = patternnet(10);
[ net tr y ] = train( net, x, t );
assignedclass = vec2ind(y);
err = assignedclass~=trueclass;
Nerr = sum(err);
PctErr(j,1) = 100*Nerr/N;
end
h = (Hmin:dH:Hmax)';
PctErr = PctErr;
results = [ h PctErr ]
% Improving Results
% net = init(net);
% net = train(net,houseInputs,houseTargets);
% z=sim(net,input)
I would like to know whether I should design a typical I-H-O net with Ntrn training examples for my code ? how to do it and where to add it in the code ?
Nw = (I+1)*H+(H+1)*O exceed the number of training equations
Ntrneq = Ntrn*O
This will occur as long as H <= Hub where Hub is the upperbound
Hub = -1+ceil( (Ntrneq-O) / (I+O+1) )
Based on Ntrneq and Hub I decide on a set of numH candidate values for H
0 <= Hmin:dH:Hmax <= Hmax
numH = numel(Hmin:dH:Hmax)
and the number of weight initializations for each value of H, e.g.,
Ntrials = 10
I have attached my input and target
I also want to know how to use the trained network for one column or row of inputs and get a result to see if it works correctly

Best Answer

You can look up the documentation examples for fitnet and patternnet using commands help and doc
then
you can search for one of my designs in the NEWSGROUP or ANSWERS.