Program gives floating point exception with Octave, not in MATLAB

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Program gives floating point exception with Octave, not in MATLAB

0000-Admin(0000)-3

In trying to run the script included below on an DEC AlphaStation, we
get the following error:

Conjugate Gradient Method
maximum number of iterations ---> [20,000]
Error e ---> [1.e-01]
dimension d ---> [100]
number of patterns n ---> [10]

error: floating point exception -- trying to return to prompt

The error occurs in different runs --- sometimes 6, sometimes 9. It
doesn't happen when using MATLAB.

disp('Conjugate Gradient Method')

Nmax = input('maximum number of iterations ---> [20,000]');
if (isempty(Nmax)), Nmax = 20000; end

sfalma = input('Error e ---> [1.e-01]');
if (isempty(sfalma)), sfalma = 1.e-05; end

d = input('dimension d ---> [100]');
if (isempty(d)), d = 100; end

n = input('number of patterns n ---> [10]');
if (isempty(n)), n = 110; end

s=.5;

for index=11:14

disp(index)
fid=fopen("data.txt", "a+")

d=100;
sfalma = 1.e-05;
max = 20000;
npatt = 50*n;
Wk = zeros(d+1,1);
gk = zeros(d+1,1);
dk = zeros(d+1,1);
Y  = zeros(2*npatt,1);
M  = zeros(2*npatt,d+1);
TS = zeros(2*n,d+1);
Q  = zeros(2*npatt,1);
Qt = zeros(2*npatt,1);
sump=0;
sumn=0;
sumt=0;

for runs = 1:10
disp(runs)


falsepos = 0;
falseneg = 0;
Wk = randn(d+1,1)/100;
TS = randn(2*n,d+1);
TS(:,d+1)=ones(2*n,1);

%m1=mean(TS);
%m1(d+1)=-m1*m1'/2;

T  = ones(2*npatt,1);

for i=1:npatt

  k = 2*i-1;
    if ( k < 2*n)
       M(k,:) = TS(k,:);
    else
       k = rem(k,2*n);
       M(2*i-1,:) = TS(k,:);
    endif
   
  M(2*i,:) = randn(1,d+1);  
  T(2*i)   = -1;
endfor

M(:,d+1) = ones(2*npatt,1);



%C = T'*M;
%B = T'*T;
%fk = B - 2*Wk'*C' + Q'*Q;

% Initial Conditions

Q = M*Wk;
Qp= (2./s)*exp(-Q./s)./(1+exp(-Q./s));
Q = (2./(1+exp(-Q./s))-1);
Qt = Qp.*(Q-T);
gk = M'*Qt;
dk = -gk;
Q2 = M*dk;
ak = -(gk'*dk)/(Q2'*Q2);


%Conjugate Algorithm

m = 2;
stop_count = 0;
er=100;
while (m<Nmax & stop_count~=1)
      % disp(m)
      m = m+1;
      Wk = Wk + ak*dk;
      Q = M*Wk;
      Qp= (2./s)*exp(-Q./s)./(1+exp(-Q./s));
      Q = (2./(1+exp(-Q./s))-1);
      gk_1 = gk;
      Qt = Qp.*(Q-T);
      gk = M'*Qt;
%      Q3 = M*gk;
      bk = (gk'*(gk-gk_1))/(gk_1'*gk_1);
%     bk = (Q3'*Q2)/(Q2'*Q2);
      dk = -gk + bk*dk;
      Q2 = M*dk;
      ak = -(gk'*dk)/(Q2'*Q2);
      er_1=er;
      er = sqrt(norm(Q-T)^2/norm(T)^2);
      if (er<sfalma | abs(er-er_1)< 1.e-05)
%      er = max(abs(gk));
%      if (er<sfalma)
          stop_count = 1;
       
      endif
endwhile

Y = M*Wk;
%Y1= M*m1';

for k=1:2*npatt

      if (Y(k) > 0)
            if (rem(k,2)==0)
                 falsepos = falsepos + 1;
            endif
      endif
      if (Y(k) < 0)
            if (rem(k,2)~=0)
                  falseneg = falseneg + 1;
            endif
      endif
endfor

ppos = falsepos*100/npatt;
sumn = sumn + falseneg*100/npatt;



ntimes = 2;
sum=0;
m=1000;
for k = 1:ntimes

Mr = randn(m,d);
Mr(:,d+1) = ones(m,1);
Yr = Mr*Wk;
fpos = 0;

 for i = 1:m
    if (Yr(i) > 0)
       fpos = fpos + 1;
    endif
 endfor

 sum = sum  + fpos;

endfor
 
averfpos = sum/ntimes;
ptest =  averfpos*100/m;

sump = sump + (ppos+ptest)/2;
 
endfor

Epos(index) = sump/runs;
Eneg(index) = sumn/runs;
Etotal(index) = (Epos(index)+Eneg(index))/2;
Erra(index) = .5*(1-erf(.5*sqrt(d/n)));

%Conerror(index) = (Y-T)'*(Y-T);
%Perror(index) = (Y1-T)'*(Y1-T);
%fprintf(fid,'%8.4 %8.4\n',percent1,percent2);

fprintf(fid,"%5d %12.6f %12.6f %12.6f %12.6f\n",n,Epos(index),Eneg(index),Etotal(index),Erra(index))
fclose(fid)
n=n+10;
save data n fid
clear
load data
end


%%%%%%%%%%%%%%%        PLOTS        %%%%%%%%%%%%%%%%%%%%

%load testres
%Eneg
%Epost
%Etotal
%Conerror
%Perror
%n=[50:10:140];
%plot(n,Eneg)
%hold on
%plot(n,Epost)
%plot(n,Etotal)
%xlabel('Number of Patterns')
%ylabel('Errors')
%title('Error curves for d=100. up:Falsepositives, down:Falesnegatives, Total Error')
%cd PLOTS
%print -dmfile Errors100sigmoid05.m
%hold off
%plot(n,Erra*100)
%hold on
%plot(n,Erra*100,'*')
%plot(n,Etotal)
%xlabel('Number of Patterns')
%ylabel('Total Errors')
%title('Total Error curves for d=100. *:Analytical, -:Experimental')
%print -dmfile TErrors100sigmoid05.m
%hold off
%plot(n,Conerror)
%hold on
%plot(n,Perror)
%plot(n,Perror,'*')
%xlabel('Number of Patterns')
%ylabel('Quadratic Errors')
%title('Quadratic Error curves for d=100. *:Plane Error, -:Experimental')
%print -dmfile Equatratic100b.m
%print  Equatratic100
%cd ..


































Reply | Threaded
Open this post in threaded view
|

Program gives floating point exception with Octave, not in MATLAB

John W. Eaton-6
On 16-Jul-1997, 0000-Admin(0000) <[hidden email]> wrote:

| In trying to run the script included below on an DEC AlphaStation, we
| get the following error:
|
| Conjugate Gradient Method
| maximum number of iterations ---> [20,000]
| Error e ---> [1.e-01]
| dimension d ---> [100]
| number of patterns n ---> [10]
|
| error: floating point exception -- trying to return to prompt

This is probably happening because you are generating Inf or NaN
somewhere in your script, and because gcc doesn't fully support IEEE
floating point arithmetic on the DEC Alpha.  The good news is that gcc
2.8.0 should support IEEE floating point arrithmetic on the DEC
Alpha.  The bad news is that no one knows when gcc 2.8.0 will be
released.

| The error occurs in different runs --- sometimes 6, sometimes 9. It
| doesn't happen when using MATLAB.

It probably occurs in different iterations because you are using data
generated by randn.

jwe