changeset 1060:30adec23a478 octave-forge

more efficient use of complex data
author schloegl
date Sat, 27 Sep 2003 09:45:12 +0000
parents 7ea0e53e0f4a
children c214d14684eb
files extra/NaN/kurtosis.m extra/NaN/meansq.m extra/NaN/nanstd.m extra/NaN/rms.m extra/NaN/sem.m extra/NaN/skewness.m extra/NaN/statistic.m
diffstat 7 files changed, 46 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/kurtosis.m	Sat Sep 27 00:08:09 2003 +0000
+++ b/extra/NaN/kurtosis.m	Sat Sep 27 09:45:12 2003 +0000
@@ -34,8 +34,9 @@
 %    along with this program; if not, write to the Free Software
 %    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-%	Version 1.28;	10 Oct 2002
-%	CopyLeft (C) 2000-2002 by Alois Schloegl <a.schloegl@ieee.org>	
+%	Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
+%	$Revision$
+%	$Id$
 
 
 if nargin==1,
@@ -46,7 +47,7 @@
 [R.SUM,R.N,R.SSQ] = sumskipnan(i,DIM);	% sum
 
 R.MEAN 	= R.SUM./R.N;			% mean 
-R.SSQ0	= R.SSQ-R.SUM.*R.MEAN;		% sum square of mean removed
+R.SSQ0	= R.SSQ - real(R.SUM).*real(R.MEAN) - imag(R.SUM).*imag(R.MEAN);	% sum square with mean removed
 
 %if flag_implicit_unbiased_estim;    %% ------- unbiased estimates ----------- 
     n1 	= max(R.N-1,0);			% in case of n=0 and n=1, the (biased) variance, STD and SEM are INF
--- a/extra/NaN/meansq.m	Sat Sep 27 00:08:09 2003 +0000
+++ b/extra/NaN/meansq.m	Sat Sep 27 09:45:12 2003 +0000
@@ -33,15 +33,19 @@
 
 % original Copyright by:  KH <Kurt.Hornik@ci.tuwien.ac.at>
 %
-%	Copyright (C) 2000-2002 by  Alois Schloegl   <a.schloegl@ieee.org>	
+%	Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
+%	$Revision$
+%	$Id$
 
 
+x = real(i).^2+imag(i).^2;
+
 if nargin<2,
-        DIM=min(find(size(i)>1));
-        if isempty(DIM), DIM=1; end;
+	[o,N] = sumskipnan(x);
+else
+	[o,N] = sumskipnan(x,DIM);
 end;
 
-[tmp,N,o] = sumskipnan(i,DIM);
 o = o./N;
 
    
\ No newline at end of file
--- a/extra/NaN/nanstd.m	Sat Sep 27 00:08:09 2003 +0000
+++ b/extra/NaN/nanstd.m	Sat Sep 27 09:45:12 2003 +0000
@@ -27,9 +27,9 @@
 %    along with this program; if not, write to the Free Software
 %    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+%    Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
 %	$Revision$
 %	$Id$
-%    Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
 
 
 if nargin>1
@@ -38,10 +38,8 @@
         [s,n,y] = sumskipnan(i);
 end;
 
-m = s./n;	% mean
-y = (y-s.*m);   % n * (summed squares with removed mean)
-
-n = max(n-1,0);	
-y = sqrt(y./n);	% normalize
+y = y.*n - real(s).^2 - imag(s).^2;   % n*n * (summed squares with removed mean)
+
+y = sqrt(y./(n.*max(n-1,0)));	% normalize
 
 
--- a/extra/NaN/rms.m	Sat Sep 27 00:08:09 2003 +0000
+++ b/extra/NaN/rms.m	Sat Sep 27 09:45:12 2003 +0000
@@ -1,5 +1,7 @@
 function o=rms(i,DIM)
 % RMS calculates the root mean square
+%   can deal with complex data. 
+%
 % y = rms(x,DIM)
 %
 % DIM	dimension
@@ -31,15 +33,19 @@
 %    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-% Copyright (c) 2001-2002 by Alois Schloegl <a.schloegl@ieee.org>	
+%	Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
+%	$Revision$
+%	$Id$
 
 
+i = real(i).^2 + imag(i).^2;
+
 if nargin<2,
-        DIM=min(find(size(i)>1));
-        if isempty(DIM), DIM=1; end;
+	[o,N] = sumskipnan(i);
+else
+	[o,N] = sumskipnan(i,DIM);
 end;
 
-[tmp,N,o] = sumskipnan(i,DIM);
 o = sqrt(o./N);
    
    
\ No newline at end of file
--- a/extra/NaN/sem.m	Sat Sep 27 00:08:09 2003 +0000
+++ b/extra/NaN/sem.m	Sat Sep 27 09:45:12 2003 +0000
@@ -5,6 +5,7 @@
 %   calculates the standard error (SE) in dimension DIM
 %   the default DIM is the first non-single dimension
 %   M returns the mean. 
+%   Can deal with complex data, too. 
 %
 % DIM	dimension
 %	1: SEM of columns
@@ -33,24 +34,16 @@
 %    along with this program; if not, write to the Free Software
 %    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-%    Copyright (C) 2000-2002 by  Alois Schloegl <a.schloegl@ieee.org>	
+%	Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
+%	$Revision$
+%	$Id$
 
 
-% check input arguments 
-if nargin==1,
-        DIM=0;
-elseif nargin==2,
-        if ~isnumeric(DIM),
-                DIM=0;
-        end
-else
-        fprintf(2,'Error SEM: invalid number of arguments\n usage: v=var(x [,DIM])\n');
+if nargin>1,
+	[tmp,N,SSQ] = sumskipnan(x,DIM);
+else    
+	[tmp,N,SSQ] = sumskipnan(x);
 end
-if ~DIM;
-        DIM=min(find(size(x)>1));
-        if isempty(DIM), DIM=1; end;
-end;
 
-[Y,N,SSQ] = sumskipnan(x,DIM);
-M  = Y./N;
-SE = sqrt((SSQ-Y.*M)./(N.*(N-1))); 
+tmp = real(tmp).^2 + imag(tmp).^2;	% squared sum 
+SE = sqrt((SSQ.*N-tmp)./(N.*N.*(N-1))); 
--- a/extra/NaN/skewness.m	Sat Sep 27 00:08:09 2003 +0000
+++ b/extra/NaN/skewness.m	Sat Sep 27 09:45:12 2003 +0000
@@ -34,8 +34,9 @@
 %    along with this program; if not, write to the Free Software
 %    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-%	Version 1.28;	10 Oct 2002
-%	CopyLeft (C) 2000-2002 by Alois Schloegl <a.schloegl@ieee.org>	
+%	Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
+%	$Revision$
+%	$Id$
 
 
 % check input arguments 
@@ -48,7 +49,7 @@
 [R.SUM,R.N,R.SSQ] = sumskipnan(i,DIM);	% sum
 
 R.MEAN 	= R.SUM./R.N;			% mean 
-R.SSQ0	= R.SSQ-R.SUM.*R.MEAN;		% sum square of mean removed
+R.SSQ0	= R.SSQ - real(R.SUM).*real(R.MEAN) - imag(R.SUM).*imag(R.MEAN); % sum square with mean removed
 
 %if flag_implicit_unbiased_estim;    %% ------- unbiased estimates ----------- 
     n1 	= max(R.N-1,0);			% in case of n=0 and n=1, the (biased) variance, STD and SEM are INF
--- a/extra/NaN/statistic.m	Sat Sep 27 00:08:09 2003 +0000
+++ b/extra/NaN/statistic.m	Sat Sep 27 09:45:12 2003 +0000
@@ -54,13 +54,10 @@
 %    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-%    	Version 1.27  Date: 12 Sep 2002
-%	Copyright (C) 2000-2002 by Alois Schloegl  <a.schloegl@ieee.org>	
-
-% .changelog
-% 05.07.2002 attempt to make STAT Level 4, 
-% 		however DIM argument difficult to implement for Median, Quantiles
-% 15.08.2002 replace strncmp by strcmp
+%	Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
+%	$Revision$
+%	$Id$
+
 
 if nargin==1,
         DIM=[];
@@ -87,7 +84,8 @@
 R.MEAN 	= R.SUM./R.N;			% mean 
 R.MSQ  	= R.SSQ./R.N;;			% mean square
 R.RMS  	= sqrt(R.MSQ);			% root mean square
-R.SSQ0	= R.SSQ-R.SUM.*R.MEAN;		% sum square of mean removed
+%R.SSQ0	= R.SSQ-R.SUM.*R.MEAN;		% sum square of mean removed
+R.SSQ0	= R.SSQ - real(R.SUM).*real(R.MEAN) - imag(R.SUM).*imag(R.MEAN);	% sum square of mean removed
 
 %if flag_implicit_unbiased_estim;    %% ------- unbiased estimates ----------- 
     n1 	= max(R.N-1,0);			% in case of n=0 and n=1, the (biased) variance, STD and SEM are INF