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 = 0load('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 + 1hold onplot(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=0for 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;endh = (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 = 0load('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) % 243N2 = length(class2) % 247N3 = length(class3) % 233N4 = length(class4) % 277x1 = x(:,class1);x2 = x(:,class2);x3 = x(:,class3);x4 = x(:,class4);plt = plt + 1hold onplot(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)) % 399Hmax = 40 % Hmax << Hub dH = 4 % Design ~10 candidate netsHmin = 2 % I know 0 and 1 are too small rng(0) % Allows duplicating the rsultsj=0for 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;endh = (Hmin:dH:Hmax)'; PctErr = PctErr;results = [ h PctErr ]
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