Mercurial > octave-nkf
comparison scripts/statistics/distributions/gaminv.m @ 19867:9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Try to trim long lines to < 80 chars.
Use '##' for single line comments.
Use '(...)' around tests for if/elseif/switch/while.
Abut cell indexing operator '{' next to variable.
Abut array indexing operator '(' next to variable.
Use space between negation operator '!' and following expression.
Use two newlines between endfunction and start of %!test or %!demo code.
Remove unnecessary parens grouping between short-circuit operators.
Remove stray extra spaces (typos) between variables and assignment operators.
Remove stray extra spaces from ends of lines.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 23 Feb 2015 14:54:39 -0800 |
parents | 4197fc428c7d |
children | d9341b422488 |
comparison
equal
deleted
inserted
replaced
19866:a1acca0c2216 | 19867:9fc020886ae9 |
---|---|
31 | 31 |
32 if (nargin != 3) | 32 if (nargin != 3) |
33 print_usage (); | 33 print_usage (); |
34 endif | 34 endif |
35 | 35 |
36 if (!isscalar (a) || !isscalar (b)) | 36 if (! isscalar (a) || ! isscalar (b)) |
37 [retval, x, a, b] = common_size (x, a, b); | 37 [retval, x, a, b] = common_size (x, a, b); |
38 if (retval > 0) | 38 if (retval > 0) |
39 error ("gaminv: X, A, and B must be of common size or scalars"); | 39 error ("gaminv: X, A, and B must be of common size or scalars"); |
40 endif | 40 endif |
41 endif | 41 endif |
57 k = (x == 1) & (a > 0) & (a < Inf) & (b > 0) & (b < Inf); | 57 k = (x == 1) & (a > 0) & (a < Inf) & (b > 0) & (b < Inf); |
58 inv(k) = Inf; | 58 inv(k) = Inf; |
59 | 59 |
60 k = find ((x > 0) & (x < 1) & (a > 0) & (a < Inf) & (b > 0) & (b < Inf)); | 60 k = find ((x > 0) & (x < 1) & (a > 0) & (a < Inf) & (b > 0) & (b < Inf)); |
61 if (any (k)) | 61 if (any (k)) |
62 if (!isscalar (a) || !isscalar (b)) | 62 if (! isscalar (a) || ! isscalar (b)) |
63 a = a(k); | 63 a = a(k); |
64 b = b(k); | 64 b = b(k); |
65 y = a .* b; | 65 y = a .* b; |
66 else | 66 else |
67 y = a * b * ones (size (k)); | 67 y = a * b * ones (size (k)); |
83 for i = 1 : 100 | 83 for i = 1 : 100 |
84 h = (gamcdf (y_old, a, b) - x) ./ gampdf (y_old, a, b); | 84 h = (gamcdf (y_old, a, b) - x) ./ gampdf (y_old, a, b); |
85 y_new = y_old - h; | 85 y_new = y_old - h; |
86 ind = find (y_new <= myeps); | 86 ind = find (y_new <= myeps); |
87 if (any (ind)) | 87 if (any (ind)) |
88 y_new (ind) = y_old (ind) / 10; | 88 y_new(ind) = y_old(ind) / 10; |
89 h = y_old - y_new; | 89 h = y_old - y_new; |
90 endif | 90 endif |
91 if (max (abs (h)) < sqrt (myeps)) | 91 if (max (abs (h)) < sqrt (myeps)) |
92 break; | 92 break; |
93 endif | 93 endif |
107 %!assert (gaminv (x, ones (1,5), 1), [NaN 0 1 Inf NaN], eps) | 107 %!assert (gaminv (x, ones (1,5), 1), [NaN 0 1 Inf NaN], eps) |
108 %!assert (gaminv (x, [1 -Inf NaN Inf 1], 1), [NaN NaN NaN NaN NaN]) | 108 %!assert (gaminv (x, [1 -Inf NaN Inf 1], 1), [NaN NaN NaN NaN NaN]) |
109 %!assert (gaminv (x, 1, [1 -Inf NaN Inf 1]), [NaN NaN NaN NaN NaN]) | 109 %!assert (gaminv (x, 1, [1 -Inf NaN Inf 1]), [NaN NaN NaN NaN NaN]) |
110 %!assert (gaminv ([x(1:2) NaN x(4:5)], 1, 1), [NaN 0 NaN Inf NaN]) | 110 %!assert (gaminv ([x(1:2) NaN x(4:5)], 1, 1), [NaN 0 NaN Inf NaN]) |
111 | 111 |
112 %% Test class of input preserved | 112 ## Test class of input preserved |
113 %!assert (gaminv ([x, NaN], 1, 1), [NaN 0 1 Inf NaN NaN], eps) | 113 %!assert (gaminv ([x, NaN], 1, 1), [NaN 0 1 Inf NaN NaN], eps) |
114 %!assert (gaminv (single ([x, NaN]), 1, 1), single ([NaN 0 1 Inf NaN NaN]), eps ("single")) | 114 %!assert (gaminv (single ([x, NaN]), 1, 1), single ([NaN 0 1 Inf NaN NaN]), eps ("single")) |
115 %!assert (gaminv ([x, NaN], single (1), 1), single ([NaN 0 1 Inf NaN NaN]), eps ("single")) | 115 %!assert (gaminv ([x, NaN], single (1), 1), single ([NaN 0 1 Inf NaN NaN]), eps ("single")) |
116 %!assert (gaminv ([x, NaN], 1, single (1)), single ([NaN 0 1 Inf NaN NaN]), eps ("single")) | 116 %!assert (gaminv ([x, NaN], 1, single (1)), single ([NaN 0 1 Inf NaN NaN]), eps ("single")) |
117 | 117 |
118 %% Test input validation | 118 ## Test input validation |
119 %!error gaminv () | 119 %!error gaminv () |
120 %!error gaminv (1) | 120 %!error gaminv (1) |
121 %!error gaminv (1,2) | 121 %!error gaminv (1,2) |
122 %!error gaminv (1,2,3,4) | 122 %!error gaminv (1,2,3,4) |
123 %!error gaminv (ones (3), ones (2), ones (2)) | 123 %!error gaminv (ones (3), ones (2), ones (2)) |