Mercurial > hg > octave-terminal
changeset 8976:22a7e4690742
adjust some stats funcs
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 13 Mar 2009 20:52:33 +0100 |
parents | 2e9af3363669 |
children | f464119ec165 |
files | scripts/ChangeLog scripts/statistics/base/mean.m scripts/statistics/base/meansq.m |
diffstat | 3 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2009-03-13 Jaroslav Hajek <highegg@gmail.com> + + * statistics/base/mean.m: Simplify. + * statistics/base/meansq.m: Optimize. + 2009-03-13 Jaroslav Hajek <highegg@gmail.com> * general/repmat.m: Use subscript pairs rather than forming Kronecker
--- a/scripts/statistics/base/mean.m +++ b/scripts/statistics/base/mean.m @@ -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);
--- a/scripts/statistics/base/meansq.m +++ b/scripts/statistics/base/meansq.m @@ -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 <Kurt.Hornik@wu-wien.ac.at> ## 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