# HG changeset patch # User jwe # Date 1076978143 0 # Node ID 567c8e2d2438b69cba86d0135a53fd6710206d08 # Parent 279c255672eeb81590d2da7c10379db43ed4f246 [project @ 2004-02-17 00:35:43 by jwe] diff -r 279c255672ee -r 567c8e2d2438 scripts/ChangeLog --- a/scripts/ChangeLog Fri Feb 01 20:55:43 2008 -0500 +++ b/scripts/ChangeLog Tue Feb 17 00:35:43 2004 +0000 @@ -1,3 +1,8 @@ +2004-02-16 Glenn Golden + + * statistics/distributions/discrete_inv.m: + Reduce memory requirements. + 2004-02-16 John W. Eaton * plot/__errcomm__.m: Fix thinko in previous change. diff -r 279c255672ee -r 567c8e2d2438 scripts/statistics/distributions/discrete_inv.m --- a/scripts/statistics/distributions/discrete_inv.m Fri Feb 01 20:55:43 2008 -0500 +++ b/scripts/statistics/distributions/discrete_inv.m Tue Feb 17 00:35:43 2004 +0000 @@ -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);