Mercurial > hg > octave-lojdl
changeset 4778:567c8e2d2438
[project @ 2004-02-17 00:35:43 by jwe]
author | jwe |
---|---|
date | Tue, 17 Feb 2004 00:35:43 +0000 |
parents | 279c255672ee |
children | f105000ab25c |
files | scripts/ChangeLog scripts/statistics/distributions/discrete_inv.m |
diffstat | 2 files changed, 21 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2004-02-16 Glenn Golden <gdg@zplane.com> + + * statistics/distributions/discrete_inv.m: + Reduce memory requirements. + 2004-02-16 John W. Eaton <jwe@bevo.che.wisc.edu> * plot/__errcomm__.m: Fix thinko in previous change.
--- a/scripts/statistics/distributions/discrete_inv.m +++ b/scripts/statistics/distributions/discrete_inv.m @@ -46,9 +46,12 @@ n = r * c; x = reshape (x, 1, n); m = length (v); - [v, ind] = sort (v); + v = sort (v); s = reshape (cumsum (p / sum (p)), m, 1); + ## Allow storage allocated for P to be reclaimed. + p = []; + inv = NaN * ones (n, 1); if (any (k = find (x == 0))) inv(k) = -Inf * ones (1, length (k)); @@ -56,11 +59,20 @@ if (any (k = find (x == 1))) inv(k) = v(m) * ones (1, length (k)); endif + if (any (k = find ((x > 0) & (x < 1)))) n = length (k); - ## --FIXME-- - ## This does not work! - inv(k) = v(sum ((ones (m, 1) * x(k)) > (s * ones (1, n))) + 1); + + ## The following loop is a space/time tradeoff in favor of space, + ## since the dataset may be large. + ## + ## Vectorized code is: + ## + ## inv(k) = v(sum ((ones (m, 1) * x(k)) > (s * ones (1, n))) + 1); + + for q = 1:n + inv(q) = v(sum (x(q) > s) + 1); + endfor endif inv = reshape (inv, r, c);