# HG changeset patch # User Jaroslav Hajek # Date 1236973953 -3600 # Node ID 22a7e46907427f0df5f23917414b129e96ebf025 # Parent 2e9af33636694e611a08e4f00c70c13491d180b7 adjust some stats funcs diff -r 2e9af3363669 -r 22a7e4690742 scripts/ChangeLog --- a/scripts/ChangeLog Fri Mar 13 16:47:50 2009 +0100 +++ b/scripts/ChangeLog Fri Mar 13 20:52:33 2009 +0100 @@ -1,3 +1,8 @@ +2009-03-13 Jaroslav Hajek + + * statistics/base/mean.m: Simplify. + * statistics/base/meansq.m: Optimize. + 2009-03-13 Jaroslav Hajek * general/repmat.m: Use subscript pairs rather than forming Kronecker diff -r 2e9af3363669 -r 22a7e4690742 scripts/statistics/base/mean.m --- a/scripts/statistics/base/mean.m Fri Mar 13 16:47:50 2009 +0100 +++ b/scripts/statistics/base/mean.m Fri Mar 13 20:52:33 2009 +0100 @@ -106,10 +106,8 @@ if (strcmp (opt, "a")) y = sum (x, dim) / n; elseif (strcmp (opt, "g")) - x(x <= 0) = NaN; - y = exp (sum (log (x), dim) / n); + y = prod (x, dim) .^ (1/n); elseif (strcmp (opt, "h")) - x(x == 0) = NaN; y = n ./ sum (1 ./ x, dim); else error ("mean: option `%s' not recognized", opt); diff -r 2e9af3363669 -r 22a7e4690742 scripts/statistics/base/meansq.m --- a/scripts/statistics/base/meansq.m Fri Mar 13 16:47:50 2009 +0100 +++ b/scripts/statistics/base/meansq.m Fri Mar 13 20:52:33 2009 +0100 @@ -1,5 +1,6 @@ ## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005, 2006, ## 2007 Kurt Hornik +## Copyright (C) 2009 Jaroslav Hajek ## ## This file is part of Octave. ## @@ -29,12 +30,21 @@ ## Author: KH ## Description: Compute mean square -function y = meansq (x, varargin) +function y = meansq (x, dim) if (nargin != 1 && nargin != 2) print_usage (); endif - y = mean (x.^2, varargin{:}); + if (nargin < 2) + t = find (size (x) != 1); + if (isempty (t)) + dim = 1; + else + dim = t(1); + endif + endif + + y = sumsq (x, dim) / size (x, dim); endfunction