Mercurial > octave-nkf
comparison scripts/statistics/distributions/discrete_inv.m @ 4778:567c8e2d2438
[project @ 2004-02-17 00:35:43 by jwe]
author | jwe |
---|---|
date | Tue, 17 Feb 2004 00:35:43 +0000 |
parents | 22bd65326ec1 |
children | 265d566cc770 |
comparison
equal
deleted
inserted
replaced
4777:279c255672ee | 4778:567c8e2d2438 |
---|---|
44 endif | 44 endif |
45 | 45 |
46 n = r * c; | 46 n = r * c; |
47 x = reshape (x, 1, n); | 47 x = reshape (x, 1, n); |
48 m = length (v); | 48 m = length (v); |
49 [v, ind] = sort (v); | 49 v = sort (v); |
50 s = reshape (cumsum (p / sum (p)), m, 1); | 50 s = reshape (cumsum (p / sum (p)), m, 1); |
51 | |
52 ## Allow storage allocated for P to be reclaimed. | |
53 p = []; | |
51 | 54 |
52 inv = NaN * ones (n, 1); | 55 inv = NaN * ones (n, 1); |
53 if (any (k = find (x == 0))) | 56 if (any (k = find (x == 0))) |
54 inv(k) = -Inf * ones (1, length (k)); | 57 inv(k) = -Inf * ones (1, length (k)); |
55 endif | 58 endif |
56 if (any (k = find (x == 1))) | 59 if (any (k = find (x == 1))) |
57 inv(k) = v(m) * ones (1, length (k)); | 60 inv(k) = v(m) * ones (1, length (k)); |
58 endif | 61 endif |
62 | |
59 if (any (k = find ((x > 0) & (x < 1)))) | 63 if (any (k = find ((x > 0) & (x < 1)))) |
60 n = length (k); | 64 n = length (k); |
61 ## --FIXME-- | 65 |
62 ## This does not work! | 66 ## The following loop is a space/time tradeoff in favor of space, |
63 inv(k) = v(sum ((ones (m, 1) * x(k)) > (s * ones (1, n))) + 1); | 67 ## since the dataset may be large. |
68 ## | |
69 ## Vectorized code is: | |
70 ## | |
71 ## inv(k) = v(sum ((ones (m, 1) * x(k)) > (s * ones (1, n))) + 1); | |
72 | |
73 for q = 1:n | |
74 inv(q) = v(sum (x(q) > s) + 1); | |
75 endfor | |
64 endif | 76 endif |
65 | 77 |
66 inv = reshape (inv, r, c); | 78 inv = reshape (inv, r, c); |
67 | 79 |
68 endfunction | 80 endfunction |