Prev: parsing a string
Next: uitable: change column width
From: Hugh on 3 Dec 2009 13:23 Hi there, I get the following error when I run some optimisation code. I assume the error stems from the fact that the matrix is singular/badly scaled. z = 1 Maximum number of function evaluations exceeded. Increase OPTIONS.MaxFunEvals. Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. > In PW at 22 In CurveGroups at 68 ??? Error using ==> svd Input to SVD must not contain NaN or Inf. Error in ==> pinv at 29 [U,S,V] = svd(A,0); Error in ==> PW at 24 stderr=sqrt(diag((u'*u)/(length(Y)-4)*pinv(G'*G))); Error in ==> CurveGroups at 68 y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9)); That's one thing but is there anyway to get the code to skip this result and carry on to the next set of optimisation parameters? The full code is shown below: %% datafitting parameters tic; clc close all clear screen %data= dlmread('yield.txt','\t'); data= dlmread('yield2.txt','\t'); ydata=data(2,:); xdata=data(1,:); %ydata=data(2:end,:); %ydata=data(2,:); %k=size(ydata); %for i=1:k(1) % xdata(i,:)=data(1,:); % end %x=eyes(2:end,:);oi %xdata=data(1,:); xdata2=[2 5 10 30]; %ydata2=[4.3 4.94 5.52 5.95]; ydata2=[4.21 4.6725 5.2375 5.715]; xdata3=data(1,:); ydata3=data(2,:); %c0 = [1.0 2 3 4];% starting values %c0 = [1.0 1 1]; %lbn = [-Inf -Inf -Inf -Inf -Inf -Inf]; % lower bound %ubn = [Inf Inf Inf Inf Inf Inf]; % upper bound options = optimset('LargeScale','off','MaxFunEvals',10000000,'TolFun',1e-5,'MaxIter',1000000); z=0; Res=cell(180,9); for (i=0.01:5.01:25.1) for (j=0.01:5.01:25.1) for (k=0.01:1.01:5.01) tic; c0 = [5.95 1 1 1 i j 0.9 k 0.9 ]; %c0 = [1 1 1 1 1 0.1+i 0.9 0.9 0.9]; %c0 = [4.103594575 21.37812216 -66.97062464 0.079861881 1.81897068 -6.547214299 15.17678637 1.675525953 11.67454445]; %lbn = [-Inf -Inf -Inf -Inf i-0.00000001 j-0.00000001 -Inf k-0.00000001 -Inf]; % lower bound %ubn = [Inf Inf Inf Inf i+0.00000001 j+0.00000001 Inf k+0.00000001 Inf]; lbn=[]; ubn=[]; z=z+1 % datafitting %[cn,error]=lsqcurvefit(@PrimePerm,c0,xdata,ydata,lbn,ubn,options); %[cn,error]=lsqcurvefit(@PrimePerm2,c0,xdata,ydata,lbn,ubn,options); %[cn,error]=lsqcurvefit(@PrimePerm3,c0,xdata3,ydata3,lbn,ubn,options); [cn,error,diff,exitf,optdata]=lsqcurvefit(@PrimePerm3,c0,xdata,ydata,lbn,ubn,options); y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9)); params = y'; %params= [cn(1) cn(2) cn(3) cn(4) ]; params=[params cn(5) cn(6) cn(7) cn(8) cn(9)]; y=CRM(xdata3,params); error2=(y-ydata3).^2; error2 = sum(error2); %Res(1,:) = [cn params error error2]; toc % Res(1,:) = [c0 cn params y error error2 toc]; % Res2(1,:) = [exitf]; % Res3(1,:) = [optdata.firstorderopt]; % Res4(1,:) = [optdata.iterations]; % Res5(1,:) = [optdata.funcCount]; % Res6(1,:) = [optdata.cgiterations]; % Res7(z,:) = [optdata.algorithm]; % Res8(z,:) = [optdata.message]; % Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6]; Inpts(z,:) = [c0 cn params y error error2 toc]; Res{z,1} = exitf; Res{z,2} = optdata.firstorderopt; Res{z,3} = optdata.iterations; Res{z,4} = optdata.funcCount; %Res6(1,:) = [optdata.cgiterations]; Res{z,5} = optdata.stepsize; Res{z,6} = optdata.algorithm; Res{z,7} = optdata.message; %Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6]; end end end %optim=find(Res{:,43}==min(Res{:,43})); toc;
From: Greg Heath on 3 Dec 2009 14:03 On Dec 3, 1:23 pm, "Hugh " <h_a_patie...(a)hotmail.com> wrote: > Hi there, > > I get the following error when I run some optimisation code. I assume the error stems from the fact that the matrix is singular/badly scaled. > > z = > > 1 > > Maximum number of function evaluations exceeded. Increase OPTIONS.MaxFunEvals. > Warning: Matrix is singular, close to singular or badly scaled. > Results may be inaccurate. RCOND = NaN.> In PW at 22 > > In CurveGroups at 68 > ??? Error using ==> svd > Input to SVD must not contain NaN or Inf. > > Error in ==> pinv at 29 > [U,S,V] = svd(A,0); > > Error in ==> PW at 24 > stderr=sqrt(diag((u'*u)/(length(Y)-4)*pinv(G'*G))); > > Error in ==> CurveGroups at 68 > y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9)); > > That's one thing but is there anyway to get the code to skip this result and carry on to the next set of optimisation parameters? > > The full code is shown below: > > %% datafitting parameters > tic; > clc > close all > clear screen > %data= dlmread('yield.txt','\t'); > data= dlmread('yield2.txt','\t'); > > ydata=data(2,:); > xdata=data(1,:); > > %ydata=data(2:end,:); > > %ydata=data(2,:); > > %k=size(ydata); > > %for i=1:k(1) > % xdata(i,:)=data(1,:); > % end > > %x=eyes(2:end,:);oi > > %xdata=data(1,:); > xdata2=[2 5 10 30]; > %ydata2=[4.3 4.94 5.52 5.95]; > ydata2=[4.21 4.6725 5.2375 5.715]; > > xdata3=data(1,:); > ydata3=data(2,:); > %c0 = [1.0 2 3 4];% starting values > > %c0 = [1.0 1 1]; > %lbn = [-Inf -Inf -Inf -Inf -Inf -Inf]; % lower bound > %ubn = [Inf Inf Inf Inf Inf Inf]; % upper bound > > options = optimset('LargeScale','off','MaxFunEvals',10000000,'TolFun',1e-5,'MaxIter',1000000); > > z=0; > Res=cell(180,9); > > for (i=0.01:5.01:25.1) > > for (j=0.01:5.01:25.1) > > for (k=0.01:1.01:5.01) > tic; > > c0 = [5.95 1 1 1 i j 0.9 k 0.9 ]; > %c0 = [1 1 1 1 1 0.1+i 0.9 0.9 0.9]; > %c0 = [4.103594575 21.37812216 -66.97062464 0..079861881 1.81897068 -6.547214299 15.17678637 1.675525953 11.67454445]; > > %lbn = [-Inf -Inf -Inf -Inf i-0.00000001 j-0.00000001 -Inf k-0.00000001 -Inf]; % lower bound > %ubn = [Inf Inf Inf Inf i+0.00000001 j+0.00000001 Inf k+0.00000001 Inf]; > lbn=[]; > ubn=[]; > > z=z+1 > % datafitting > %[cn,error]=lsqcurvefit(@PrimePerm,c0,xdata,ydata,lbn,ubn,options); > %[cn,error]=lsqcurvefit(@PrimePerm2,c0,xdata,ydata,lbn,ubn,options); > > %[cn,error]=lsqcurvefit(@PrimePerm3,c0,xdata3,ydata3,lbn,ubn,options); > [cn,error,diff,exitf,optdata]=lsqcurvefit(@PrimePerm3,c0,xdata,ydata,lbn,ubn,options); > > y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9)); > params = y'; > %params= [cn(1) cn(2) cn(3) cn(4) ]; > params=[params cn(5) cn(6) cn(7) cn(8) cn(9)]; > y=CRM(xdata3,params); > error2=(y-ydata3).^2; > error2 = sum(error2); > > %Res(1,:) = [cn params error error2]; > > toc > > % Res(1,:) = [c0 cn params y error error2 toc]; > % Res2(1,:) = [exitf]; > % Res3(1,:) = [optdata.firstorderopt]; > % Res4(1,:) = [optdata.iterations]; > % Res5(1,:) = [optdata.funcCount]; > % Res6(1,:) = [optdata.cgiterations]; > % Res7(z,:) = [optdata.algorithm]; > % Res8(z,:) = [optdata.message]; > % Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6]; > > Inpts(z,:) = [c0 cn params y error error2 toc]; > Res{z,1} = exitf; > Res{z,2} = optdata.firstorderopt; > Res{z,3} = optdata.iterations; > Res{z,4} = optdata.funcCount; > %Res6(1,:) = [optdata.cgiterations]; > Res{z,5} = optdata.stepsize; > Res{z,6} = optdata.algorithm; > Res{z,7} = optdata.message; > %Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6]; > > end > end > end > > %optim=find(Res{:,43}==min(Res{:,43})); > > toc; Try replacing +/1 inf with large numerical values. Hope this helps. Greg
From: Greg Heath on 3 Dec 2009 14:04 On Dec 3, 2:03 pm, Greg Heath <he...(a)alumni.brown.edu> wrote: > On Dec 3, 1:23 pm, "Hugh " <h_a_patie...(a)hotmail.com> wrote: > > > > > > > Hi there, > > > I get the following error when I run some optimisation code. I assume the error stems from the fact that the matrix is singular/badly scaled. > > > z = > > > 1 > > > Maximum number of function evaluations exceeded. Increase OPTIONS.MaxFunEvals. > > Warning: Matrix is singular, close to singular or badly scaled. > > Results may be inaccurate. RCOND = NaN.> In PW at 22 > > > In CurveGroups at 68 > > ??? Error using ==> svd > > Input to SVD must not contain NaN or Inf. > > > Error in ==> pinv at 29 > > [U,S,V] = svd(A,0); > > > Error in ==> PW at 24 > > stderr=sqrt(diag((u'*u)/(length(Y)-4)*pinv(G'*G))); > > > Error in ==> CurveGroups at 68 > > y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9)); > > > That's one thing but is there anyway to get the code to skip this result and carry on to the next set of optimisation parameters? > > > The full code is shown below: > > > %% datafitting parameters > > tic; > > clc > > close all > > clear screen > > %data= dlmread('yield.txt','\t'); > > data= dlmread('yield2.txt','\t'); > > > ydata=data(2,:); > > xdata=data(1,:); > > > %ydata=data(2:end,:); > > > %ydata=data(2,:); > > > %k=size(ydata); > > > %for i=1:k(1) > > % xdata(i,:)=data(1,:); > > % end > > > %x=eyes(2:end,:);oi > > > %xdata=data(1,:); > > xdata2=[2 5 10 30]; > > %ydata2=[4.3 4.94 5.52 5.95]; > > ydata2=[4.21 4.6725 5.2375 5.715]; > > > xdata3=data(1,:); > > ydata3=data(2,:); > > %c0 = [1.0 2 3 4];% starting values > > > %c0 = [1.0 1 1]; > > %lbn = [-Inf -Inf -Inf -Inf -Inf -Inf]; % lower bound > > %ubn = [Inf Inf Inf Inf Inf Inf]; % upper bound > > > options = optimset('LargeScale','off','MaxFunEvals',10000000,'TolFun',1e-5,'MaxIter',1000000); > > > z=0; > > Res=cell(180,9); > > > for (i=0.01:5.01:25.1) > > > for (j=0.01:5.01:25.1) > > > for (k=0.01:1.01:5.01) > > tic; > > > c0 = [5.95 1 1 1 i j 0.9 k 0.9 ]; > > %c0 = [1 1 1 1 1 0.1+i 0.9 0.9 0.9]; > > %c0 = [4.103594575 21.37812216 -66.97062464 0.079861881 1.81897068 -6.547214299 15.17678637 1.675525953 11.67454445]; > > > %lbn = [-Inf -Inf -Inf -Inf i-0.00000001 j-0.00000001 -Inf k-0.00000001 -Inf]; % lower bound > > %ubn = [Inf Inf Inf Inf i+0.00000001 j+0.00000001 Inf k+0.00000001 Inf]; > > lbn=[]; > > ubn=[]; > > > z=z+1 > > % datafitting > > %[cn,error]=lsqcurvefit(@PrimePerm,c0,xdata,ydata,lbn,ubn,options); > > %[cn,error]=lsqcurvefit(@PrimePerm2,c0,xdata,ydata,lbn,ubn,options); > > > %[cn,error]=lsqcurvefit(@PrimePerm3,c0,xdata3,ydata3,lbn,ubn,options); > > [cn,error,diff,exitf,optdata]=lsqcurvefit(@PrimePerm3,c0,xdata,ydata,lbn,ubn,options); > > > y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9)); > > params = y'; > > %params= [cn(1) cn(2) cn(3) cn(4) ]; > > params=[params cn(5) cn(6) cn(7) cn(8) cn(9)]; > > y=CRM(xdata3,params); > > error2=(y-ydata3).^2; > > error2 = sum(error2); > > > %Res(1,:) = [cn params error error2]; > > > toc > > > % Res(1,:) = [c0 cn params y error error2 toc]; > > % Res2(1,:) = [exitf]; > > % Res3(1,:) = [optdata.firstorderopt]; > > % Res4(1,:) = [optdata.iterations]; > > % Res5(1,:) = [optdata.funcCount]; > > % Res6(1,:) = [optdata.cgiterations]; > > % Res7(z,:) = [optdata.algorithm]; > > % Res8(z,:) = [optdata.message]; > > % Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6]; > > > Inpts(z,:) = [c0 cn params y error error2 toc]; > > Res{z,1} = exitf; > > Res{z,2} = optdata.firstorderopt; > > Res{z,3} = optdata.iterations; > > Res{z,4} = optdata.funcCount; > > %Res6(1,:) = [optdata.cgiterations]; > > Res{z,5} = optdata.stepsize; > > Res{z,6} = optdata.algorithm; > > Res{z,7} = optdata.message; > > %Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6]; > > > end > > end > > end > > > %optim=find(Res{:,43}==min(Res{:,43})); > > > toc; > > Try replacing +/1 inf with large numerical values. +/- inf Hope this helps. Greg- Hide quoted text - > > - Show quoted text -
From: Hugh on 9 Dec 2009 14:00 Greg Heath <heath(a)alumni.brown.edu> wrote in message <1041a733-c6b6-4228-8513-adec56e019dc(a)p32g2000vbi.googlegroups.com>... > On Dec 3, 1:23?pm, "Hugh " <h_a_patie...(a)hotmail.com> wrote: > > Hi there, > > > > I get the following error when I run some optimisation code. I assume the error stems from the fact that the matrix is singular/badly scaled. > > > > z = > > > > ? ? ?1 > > > > Maximum number of function evaluations exceeded. Increase OPTIONS.MaxFunEvals. > > Warning: Matrix is singular, close to singular or badly scaled. > > ? ? ? ? ?Results may be inaccurate. RCOND = NaN.> In PW at 22 > > > > ? In CurveGroups at 68 > > ??? Error using ==> svd > > Input to SVD must not contain NaN or Inf. > > > > Error in ==> pinv at 29 > > ? ?[U,S,V] = svd(A,0); > > > > Error in ==> PW at 24 > > ? ? ? ? ?stderr=sqrt(diag((u'*u)/(length(Y)-4)*pinv(G'*G))); > > > > Error in ==> CurveGroups at 68 > > y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9)); > > > > That's one thing but is there anyway to get the code to skip this result and carry on to the next set of optimisation parameters? > > > > The full code is shown below: > > > > %% datafitting parameters > > tic; > > clc > > close all > > clear screen > > %data= dlmread('yield.txt','\t'); > > data= dlmread('yield2.txt','\t'); > > > > ydata=data(2,:); > > xdata=data(1,:); > > > > %ydata=data(2:end,:); > > > > %ydata=data(2,:); > > > > %k=size(ydata); > > > > %for i=1:k(1) > > ?% ? ? xdata(i,:)=data(1,:); > > ?% end > > > > %x=eyes(2:end,:);oi > > > > %xdata=data(1,:); > > xdata2=[2 5 10 30]; > > %ydata2=[4.3 4.94 5.52 5.95]; > > ydata2=[4.21 4.6725 5.2375 5.715]; > > > > xdata3=data(1,:); > > ydata3=data(2,:); > > %c0 = [1.0 2 3 4];% starting values > > > > %c0 = [1.0 1 1]; > > %lbn = [-Inf -Inf -Inf -Inf -Inf -Inf]; ? ? ? ? ? ? ? ? ? ? ?% lower bound > > %ubn = [Inf Inf Inf Inf Inf Inf]; ? ? ? ? ? ? ? ? ? ? ?% upper bound > > > > options = optimset('LargeScale','off','MaxFunEvals',10000000,'TolFun',1e-5,'MaxIter',?1000000); > > > > z=0; > > Res=cell(180,9); > > > > for (i=0.01:5.01:25.1) > > > > ? ? for (j=0.01:5.01:25.1) > > > > ? ? ? ? ?for (k=0.01:1.01:5.01) > > tic; ? ? ? ? ? > > > > c0 = [5.95 1 1 1 i j 0.9 k 0.9 ]; > > %c0 = [1 1 1 1 1 0.1+i 0.9 0.9 0.9]; > > %c0 = [4.103594575 ? ? ?21.37812216 ? ? -66.97062464 ? ?0.079861881 ? ? 1.81897068 ? ? ?-6.547214299 ? ?15.17678637 ? ? 1.675525953 ? ? 11.67454445]; > > > > %lbn = [-Inf -Inf -Inf -Inf i-0.00000001 j-0.00000001 -Inf k-0.00000001 -Inf]; ? ? ? ? ? ? ? ? ? ? ?% lower bound > > %ubn = [Inf Inf Inf Inf i+0.00000001 j+0.00000001 Inf k+0.00000001 Inf]; > > lbn=[]; > > ubn=[]; > > > > z=z+1 > > % datafitting > > %[cn,error]=lsqcurvefit(@PrimePerm,c0,xdata,ydata,lbn,ubn,options); > > %[cn,error]=lsqcurvefit(@PrimePerm2,c0,xdata,ydata,lbn,ubn,options); > > > > %[cn,error]=lsqcurvefit(@PrimePerm3,c0,xdata3,ydata3,lbn,ubn,options); > > [cn,error,diff,exitf,optdata]=lsqcurvefit(@PrimePerm3,c0,xdata,ydata,lbn,ub?n,options); > > > > y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9)); > > params = y'; > > %params= [cn(1) cn(2) cn(3) cn(4) ]; > > params=[params cn(5) cn(6) cn(7) cn(8) cn(9)]; > > y=CRM(xdata3,params); > > error2=(y-ydata3).^2; > > error2 = sum(error2); > > > > %Res(1,:) = [cn params error error2]; > > > > ?toc ? ? > > > > % Res(1,:) = [c0 cn params y error error2 toc]; > > % Res2(1,:) = [exitf]; > > % Res3(1,:) = [optdata.firstorderopt]; > > % Res4(1,:) = [optdata.iterations]; > > % Res5(1,:) = [optdata.funcCount]; > > % Res6(1,:) = [optdata.cgiterations]; > > % Res7(z,:) = [optdata.algorithm]; > > % Res8(z,:) = [optdata.message]; > > % Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6]; > > > > ?Inpts(z,:) = [c0 cn params y error error2 toc]; > > ?Res{z,1} = exitf; > > ?Res{z,2} = optdata.firstorderopt; > > ?Res{z,3} = optdata.iterations; > > ?Res{z,4} = optdata.funcCount; > > ?%Res6(1,:) = [optdata.cgiterations]; > > ?Res{z,5} = optdata.stepsize; > > ?Res{z,6} = optdata.algorithm; > > ?Res{z,7} = optdata.message; > > ?%Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6]; > > > > ? ? ? ? ?end > > ? ? end > > end > > > > %optim=find(Res{:,43}==min(Res{:,43})); > > > > toc; > > Try replacing +/1 inf with large numerical values. > > Hope this helps. > > Greg Ok so canI use this function to test for Inf: http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/staticboolisinfdoublex.html In which case where does the c++ header file get used? If not is there another function I can use to test for the appearance of Inf values? Also what would be a suitable large number to replace Inf with when I find it? Can I check to see what type of variable is being used for example double and then just put the highest legitimate value for that type of variable. If so how do I test what type a given varoable has and how do I find out what the maximum value for they type is??
|
Pages: 1 Prev: parsing a string Next: uitable: change column width |