Mercurial > hg > octave-nkf
changeset 20820:4e307c55a2b5
Use isempty () rather than any () for faster code in inverse statistical distributions.
betainv.m, binoinv.m, gaminv.m, poissinv.m: Use '! isempty (k)' rather than
'any (k)' for faster code.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 11 Oct 2015 21:09:41 -0700 |
parents | d6d04088ac9e |
children | 395140e53656 |
files | scripts/statistics/distributions/betainv.m scripts/statistics/distributions/binoinv.m scripts/statistics/distributions/gaminv.m scripts/statistics/distributions/poissinv.m |
diffstat | 4 files changed, 9 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/statistics/distributions/betainv.m +++ b/scripts/statistics/distributions/betainv.m @@ -56,7 +56,7 @@ inv(k) = 1; k = find ((x > 0) & (x < 1) & (a > 0) & (b > 0)); - if (any (k)) + if (! isempty (k)) if (! isscalar (a) || ! isscalar (b)) a = a(k); b = b(k);
--- a/scripts/statistics/distributions/binoinv.m +++ b/scripts/statistics/distributions/binoinv.m @@ -55,7 +55,7 @@ k = find ((x >= 0) & (x <= 1) & (n >= 0) & (n == fix (n) & (p >= 0) & (p <= 1))); - if (any (k)) + if (! isempty (k)) x = x(k); if (isscalar (n) && isscalar (p)) [inv(k), unfinished] = scalar_binoinv (x(:), n, p);
--- a/scripts/statistics/distributions/gaminv.m +++ b/scripts/statistics/distributions/gaminv.m @@ -58,7 +58,7 @@ inv(k) = Inf; k = find ((x > 0) & (x < 1) & (a > 0) & (a < Inf) & (b > 0) & (b < Inf)); - if (any (k)) + if (! isempty (k)) if (! isscalar (a) || ! isscalar (b)) a = a(k); b = b(k);
--- a/scripts/statistics/distributions/poissinv.m +++ b/scripts/statistics/distributions/poissinv.m @@ -61,9 +61,8 @@ inv(k) = Inf; k = (x > 0) & (x < 1) & (lambda > 0); - - limit = 20; # After 'limit' iterations, use approx - if (! isempty (k)) + if (any (k(:))) + limit = 20; # After 'limit' iterations, use approx if (isscalar (lambda)) cdf = [(cumsum (poisspdf (0:limit-1,lambda))), 2]; y = x(:); # force to column @@ -75,11 +74,11 @@ cdf = exp (-lambda(kk)); for i = 1:limit m = find (cdf < x(kk)); - if (any (m)) + if (isempty (m)) + break; + else inv(kk(m)) += 1; cdf(m) += poisspdf (i, lambda(kk(m))); - else - break; endif endfor endif @@ -186,6 +185,7 @@ y = lambda(k) .* r + log (sqrt (2*r.*((1-r) + r.*t)) ./ abs (r-1)) ./ t; inv(k) = floor (y - 0.0218 ./ (y + 0.065 * lambda(k))); endif + endfunction