changeset 4886:54b076a24718

[project @ 2004-04-30 04:31:51 by jwe]
author jwe
date Fri, 30 Apr 2004 04:31:51 +0000
parents 28ab079d8f0e
children bbddd4339cf2
files scripts/statistics/base/iqr.m scripts/statistics/base/kurtosis.m scripts/statistics/base/ranks.m scripts/statistics/base/run_count.m scripts/statistics/base/skewness.m scripts/statistics/base/statistics.m scripts/statistics/base/studentize.m
diffstat 7 files changed, 72 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/statistics/base/iqr.m	Fri Apr 30 04:21:33 2004 +0000
+++ b/scripts/statistics/base/iqr.m	Fri Apr 30 04:31:51 2004 +0000
@@ -40,27 +40,28 @@
   sz = size (x);
   nel = numel (x);
   if (nargin != 2)
-    %% Find the first non-singleton dimension
+    ## Find the first non-singleton dimension.
     dim  = 1;
-    while (dim < nd + 1 && sz (dim) == 1)
+    while (dim < nd + 1 && sz(dim) == 1)
       dim = dim + 1;
     endwhile
     if (dim > nd)
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
-	dim < (nd + 1))
+    if (! (isscalar (dim) && dim == round (dim))
+	&& dim > 0
+	&& dim < (nd + 1))
       error ("iqr: dim must be an integer and valid dimension");
     endif
   endif
 
   ## This code is a bit heavy, but is needed until empirical_inv 
   ## takes other than vector arguments.
-  c = sz (dim);
-  sz (dim) = 1;
+  c = sz(dim);
+  sz(dim) = 1;
   y = zeros (sz);
-  stride = prod (sz (1:dim-1));
+  stride = prod (sz(1:dim-1));
   for i = 1 : nel / c;
     offset = i;
     offset2 = 0;
--- a/scripts/statistics/base/kurtosis.m	Fri Apr 30 04:21:33 2004 +0000
+++ b/scripts/statistics/base/kurtosis.m	Fri Apr 30 04:31:51 2004 +0000
@@ -54,17 +54,18 @@
   nd = ndims (x);
   sz = size (x);
   if (nargin != 2)
-    %% Find the first non-singleton dimension
+    ## Find the first non-singleton dimension.
     dim  = 1;
-    while (dim < nd + 1 && sz (dim) == 1)
+    while (dim < nd + 1 && sz(dim) == 1)
       dim = dim + 1;
     endwhile
     if (dim > nd)
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
-	dim < (nd + 1))
+    if (! (isscalar (dim) && dim == round (dim))
+	&& dim > 0
+	&& dim < (nd + 1))
       error ("kurtosis: dim must be an integer and valid dimension");
     endif
   endif
@@ -73,15 +74,15 @@
     error ("kurtosis: x has to be a matrix or a vector");
   endif
 
-  c = sz (dim);
-  sz (dim) = 1;
+  c = sz(dim);
+  sz(dim) = 1;
   idx = ones (1, nd);
-  idx (dim) = c;
+  idx(dim) = c;
   x = x - repmat (mean (x, dim), idx);
   retval = zeros (sz);
   s = std (x, [], dim);
   x = sum(x.^4, dim);
   ind = find (s > 0);
-  retval (ind) = x (ind) ./ (c * s (ind) .^ 4) - 3;
+  retval(ind) = x(ind) ./ (c * s(ind) .^ 4) - 3;
 
 endfunction
--- a/scripts/statistics/base/ranks.m	Fri Apr 30 04:21:33 2004 +0000
+++ b/scripts/statistics/base/ranks.m	Fri Apr 30 04:31:51 2004 +0000
@@ -43,32 +43,33 @@
   nd = ndims (x);
   sz = size (x);
   if (nargin != 2)
-    %% Find the first non-singleton dimension
+    ## Find the first non-singleton dimension.
     dim  = 1;
-    while (dim < nd + 1 && sz (dim) == 1)
+    while (dim < nd + 1 && sz(dim) == 1)
       dim = dim + 1;
     endwhile
     if (dim > nd)
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
-	dim < (nd + 1))
+    if (! (isscalar (dim) && dim == round (dim))
+	&& dim > 0
+	&& dim < (nd + 1))
       error ("ranks: dim must be an integer and valid dimension");
     endif
   endif
 
-  if (sz (dim) == 1)
+  if (sz(dim) == 1)
     y = ones(sz);
   else
     ## The algorithm works only on dim=1, so permute if necesary
     if (dim != 1)
       perm = [1 : nd];
-      perm (1) = dim;
-      perm (dim) = 1;
+      perm(1) = dim;
+      perm(dim) = 1;
       x = permute (x, perm);
     endif
-    sz  = size (x);
+    sz = size (x);
     infvec = -Inf * ones ([1, sz(2 : end)]);
     [xs, y] = sort (x);
     eq_el = find (diff ([xs; infvec]) == 0);
@@ -76,14 +77,13 @@
       [eq_el, y] = sort (y);  
     else
       runs = complement (eq_el+1, eq_el);
-      runs = reshape (y (runs), size (runs)) + 
-             floor (runs ./ sz (1)) * sz(1);
+      runs = reshape (y (runs), size (runs)) + floor (runs ./ sz(1)) * sz(1);
       len = diff (find (diff ([Inf; eq_el; -Inf]) != 1)) + 1;
-      [eq_el, y] = sort (y);  
+      [eq_el, y] = sort (y);
       for i = 1 : length(runs)
-	p = y (runs (i)) + (len (i) - 1) / 2;
-	for j = 0 : len (i) - 1
-	  y (runs (i) + j) = p;
+	p = y(runs(i)) + (len(i) - 1) / 2;
+	for j = 0 : len(i) - 1
+	  y(runs(i) + j) = p;
 	endfor
       endfor
     endif  
--- a/scripts/statistics/base/run_count.m	Fri Apr 30 04:21:33 2004 +0000
+++ b/scripts/statistics/base/run_count.m	Fri Apr 30 04:31:51 2004 +0000
@@ -37,53 +37,54 @@
   nd = ndims (x);
   sz = size (x);
   if (nargin != 3)
-    %% Find the first non-singleton dimension
+    ## Find the first non-singleton dimension.
     dim  = 1;
-    while (dim < nd + 1 && sz (dim) == 1)
+    while (dim < nd + 1 && sz(dim) == 1)
       dim = dim + 1;
     endwhile
     if (dim > nd)
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
-	dim < (nd + 1))
+    if (! (isscalar (dim) && dim == round (dim))
+	&& dim > 0
+	&& dim < (nd + 1))
       error ("run_count: dim must be an integer and valid dimension");
     endif
   endif
 
-  if (! (isscalar (n) && n == round (n)) && n > 0 )
+  if (! (isscalar (n) && n == round (n)) && n > 0)
     error ("run_count: n must be a positive integer");
   endif
   
   nd = ndims (x);
   if (dim != 1)
     perm = [1 : nd];
-    perm (1) = dim;
-    perm (dim) = 1;
+    perm(1) = dim;
+    perm(dim) = 1;
     x = permute (x, perm);
   endif
 
   sz = size (x);
   idx = cell ();
   for i = 1 : nd
-    idx {i} = 1 : sz(i);
+    idx{i} = 1 : sz(i);
   endfor
-  c = sz (1); 
+  c = sz(1); 
   tmp = zeros ([c + 1, sz(2 : end)]);
   infvec = Inf * ones ([1, sz(2 : end)]);
 
   ind = find (diff ([infvec; x; -infvec]) < 0);
-  tmp (ind (2 : end) - 1) = diff (ind);
-  tmp = tmp (idx {:});
+  tmp(ind(2:end) - 1) = diff(ind);
+  tmp = tmp(idx{:});
 
-  sz (1) = n;
+  sz(1) = n;
   retval = zeros (sz);
-  for k=1 : (n-1)
-    idx {1} = k;
-    retval (idx {:}) = sum (tmp == k);
+  for k = 1 : (n-1)
+    idx{1} = k;
+    retval(idx{:}) = sum (tmp == k);
   endfor
-  idx {1} = n;
+  idx{1} = n;
   retval (idx {:}) = sum (tmp >= n);
 
   if (dim != 1)
--- a/scripts/statistics/base/skewness.m	Fri Apr 30 04:21:33 2004 +0000
+++ b/scripts/statistics/base/skewness.m	Fri Apr 30 04:31:51 2004 +0000
@@ -53,17 +53,18 @@
   nd = ndims (x);
   sz = size (x);
   if (nargin != 2)
-    %% Find the first non-singleton dimension
+    ## Find the first non-singleton dimension.
     dim  = 1;
-    while (dim < nd + 1 && sz (dim) == 1)
+    while (dim < nd + 1 && sz(dim) == 1)
       dim = dim + 1;
     endwhile
     if (dim > nd)
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
-	dim < (nd + 1))
+    if (! (isscalar (dim) && dim == round (dim))
+	&& dim > 0
+	&& dim < (nd + 1))
       error ("skewness: dim must be an integer and valid dimension");
     endif
   endif
@@ -72,15 +73,15 @@
     error ("skewness: x has to be a matrix or a vector");
   endif
 
-  c = sz (dim);
+  c = sz(dim);
   idx = ones (1, nd);
   idx (dim) = c;
   x = x - repmat (mean (x, dim), idx);
-  sz (dim) = 1;
+  sz(dim) = 1;
   retval = zeros (sz);
   s = std (x, [], dim);
   ind = find (s > 0);
   x = sum (x .^ 3, dim);
-  retval (ind) = x (ind) ./ (c * s (ind) .^ 3);
+  retval(ind) = x(ind) ./ (c * s(ind) .^ 3);
   
 endfunction
--- a/scripts/statistics/base/statistics.m	Fri Apr 30 04:21:33 2004 +0000
+++ b/scripts/statistics/base/statistics.m	Fri Apr 30 04:31:51 2004 +0000
@@ -39,30 +39,31 @@
   sz = size (X);
   nel = numel (X);
   if (nargin != 2)
-    %% Find the first non-singleton dimension
+    ## Find the first non-singleton dimension.
     dim  = 1;
-    while (dim < nd + 1 && sz (dim) == 1)
+    while (dim < nd + 1 && sz(dim) == 1)
       dim = dim + 1;
     endwhile
     if (dim > nd)
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
-	dim < (nd + 1))
+    if (! (isscalar (dim) && dim == round (dim))
+	&& dim > 0
+	&& dim < (nd + 1))
       error ("statistics: dim must be an integer and valid dimension");
     endif
   endif
   
-  if (! ismatrix (X) || sz (dim) < 2)
+  if (! ismatrix (X) || sz(dim) < 2)
     error ("statistics: invalid argument");
   endif    
 
   ## This code is a bit heavy, but is needed until empirical_inv 
   ## takes other than vector arguments.
-  c = sz (dim);
-  stride = prod (sz (1:dim-1));
-  sz (dim) = 3;
+  c = sz(dim);
+  stride = prod (sz(1:dim-1));
+  sz(dim) = 3;
   emp_inv = zeros (sz);
   for i = 1 : nel / c;
     offset = i;
--- a/scripts/statistics/base/studentize.m	Fri Apr 30 04:21:33 2004 +0000
+++ b/scripts/statistics/base/studentize.m	Fri Apr 30 04:31:51 2004 +0000
@@ -39,17 +39,18 @@
   nd = ndims (x);
   sz = size (x);
   if (nargin != 2)
-    %% Find the first non-singleton dimension
+    ## Find the first non-singleton dimension.
     dim  = 1;
-    while (dim < nd + 1 && sz (dim) == 1)
+    while (dim < nd + 1 && sz(dim) == 1)
       dim = dim + 1;
     endwhile
     if (dim > nd)
       dim = 1;
     endif
   else
-    if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && 
-	dim < (nd + 1))
+    if (! (isscalar (dim) && dim == round (dim))
+	&& dim > 0
+	&& dim < (nd + 1))
       error ("studentize: dim must be an integer and valid dimension");
     endif
   endif
@@ -58,9 +59,9 @@
     error ("studentize: x must be a vector or a matrix");
   endif
 
-  c = sz (dim);
+  c = sz(dim);
   idx = ones (1, nd);
-  idx (dim) = c;
+  idx(dim) = c;
   t = x - repmat (mean (x, dim), idx);
   t = t ./ repmat (max (cat (dim, std(t, [], dim), ! any (t, dim)), [], dim), idx);