MATLAB: No Big Difference using newpr or patternnet and epochs reduction

Deep Learning Toolboxinputneural networkneural networkstargettrueclass

I have used the following code , for my input and target file that I have attached as well , am I correct that newpr is Obsolete from MATLAB 2010 ? but when I replaced the newpr command with
patternnet(10)
there were some changes in number of the epochs , but not in the total results , I would like to ask your help to improve one of these codes to give the best results to the input that I have attached .
so I put the codes I have used here :
First I used this code :
close all, clear all, clc, plt = 0
load('input.txt')
%load input

load ('target.txt')
%normalizing data

input=input';
target=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 = newpr(x,t,h);
[ 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 ]
Then I changed from newpr to patternnet in the same code :
close all, clear all, clc, plt = 0
load('input.txt')
%load input
load ('target.txt')
%normalizing data
input=input';
target=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 ]
2 – Then I also tried to use another code that I found from this post : here
but I was not able to catch all the corrections that were advised by Proff. Heath , so I only used the original code. well there is a difference in confusion , that in the first code , only one of the green squares show a number like 189 / 100% , and only in one of the classes : 2 , not all of the four classes , why is that ?
3 – I also tried to use the sine(x) function by defining x vector and sin(x) , is input and target , but the code did not accept due to having 4 classes.
4 – And another question is , where in the first code , the curve fitting is done ?
5- how much can I rely on
net = init(net);
net = train(net,houseInputs,houseTargets);
and how many times repeat of it after running the code ?
  • As an update I used mapstd after getting the inputs , but then doubted I should use mapminmax or mapstd ?
As an update I used
z=sim(net,input);
but it just created a vector of negative numbers between 1 and -1 , don't know how to use it !?

Best Answer

% No Big Difference using newpr or patternnet and epochs reduction % Asked by farzad on 21 Feb 2015 at 13:32 % Latest activity Edited by farzad about 9 hours ago % % I have used the following code , for my input and target file that I have % attached as well , am I correct that newpr is Obsolete from MATLAB % 2010 ? but when I replaced the newpr command with patternnet(10) % there were some changes in number of the epochs , but not in the total % results , I would like to ask your help to improve one of these codes to % give the best results to the input that I have attached
Since you have the current PATTERNNET, FORGEDABOUD DA obsolete NEWPR.
However, when designing NON-OBSOLETE multiple nets in a for loop, the weights have to be EXPLICITLY initialized before training using CONFIGURE or INIT.
% so I put the codes I have used here :
Hmmm, look familiar (;>) !
SNIP
%Then I changed from newpr to patternnet in the same code :
However, you did not initialize the weights at the top of the inner for loop.
% 2 - Then I also tried to use another code that I found from this post : % here but I was not able to catch all the corrections that were advised % by Proff. Heath , so I only used the original code. well there is a % difference in confusion , that in the first code , only one of the green % squares show a number like 189 / 100% , and only in one of the % classes : 2 , not all of the four classes , why is that ?
Not understandable.
% 3 - I also tried to use the sine(x) function by defining x vector and sin(x) , % is input and target , but the code did not accept due to having 4 classes.
Doesn't make sense: That is regression, NOT classification!
% 4 - And another question is , where in the first code , the curve fitting is % done ?
No curvefitting: it's classification, not regression!
% 5- how much can I rely on % net = init(net); % net = train(net,houseInputs,houseTargets); % and how many times repeat of it after running the code ?
I'd guess somewhere between 10 and 90 per cent, PROVIDED you have the correct range of hidden node values AND you design ~ 10 nets for each value of hidden nodes.
% As an update I used mapstd after getting the inputs , but then doubted I % should use mapminmax or mapstd ?.
The CURRENT nets automatically normalize and unnormalize using the default MAPMINMAX. However, I prefer to use ZSCORE (easier to use than MAPSTD) BEFORE design to modify and/or delete outliers. Then I am too lazy to override MAPMINMAX, so I keep it.
% As an update I used % z=sim(net,input); % % but it just created a vector of negative numbers between 1 and -1 , don't know % how to use it !?
Assuming your classification target matrix had {0,1} unit matrix columns, you have to unnormalize your output and then use vec2ind to obtain the output classes.
The CURRENT syntax replaces SIM with
z = net(input);
Hope this helps.
Thank you for formally accepting my answer
Greg