Mercurial > octave-nkf
annotate scripts/statistics/distributions/poissinv.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 1740012184f9 |
children | 19b9f17d22af |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Kurt Hornik |
5410 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5410 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5410 | 18 |
19 ## -*- texinfo -*- | |
5411 | 20 ## @deftypefn {Function File} {} poissinv (@var{x}, @var{lambda}) |
5410 | 21 ## For each component of @var{x}, compute the quantile (the inverse of |
22 ## the CDF) at @var{x} of the Poisson distribution with parameter | |
23 ## @var{lambda}. | |
24 ## @end deftypefn | |
25 | |
5428 | 26 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 27 ## Description: Quantile function of the Poisson distribution |
28 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
29 function inv = poissinv (x, lambda) |
5410 | 30 |
31 if (nargin != 2) | |
6046 | 32 print_usage (); |
5410 | 33 endif |
34 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
35 if (!isscalar (lambda)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
36 [retval, x, lambda] = common_size (x, lambda); |
5410 | 37 if (retval > 0) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
38 error ("poissinv: X and LAMBDA must be of common size or scalar"); |
5410 | 39 endif |
40 endif | |
41 | |
42 inv = zeros (size (x)); | |
43 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
44 k = find ((x < 0) | (x > 1) | isnan (x) | !(lambda > 0)); |
5410 | 45 if (any (k)) |
46 inv(k) = NaN; | |
47 endif | |
48 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
49 k = find ((x == 1) & (lambda > 0)); |
5410 | 50 if (any (k)) |
51 inv(k) = Inf; | |
52 endif | |
53 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
54 k = find ((x > 0) & (x < 1) & (lambda > 0)); |
5410 | 55 if (any (k)) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
56 if (isscalar (lambda)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
57 cdf = exp (-lambda) * ones (size (k)); |
5410 | 58 else |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
59 cdf = exp (-lambda(k)); |
5410 | 60 endif |
61 while (1) | |
62 m = find (cdf < x(k)); | |
63 if (any (m)) | |
64 inv(k(m)) = inv(k(m)) + 1; | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
65 if (isscalar (lambda)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
66 cdf(m) = cdf(m) + poisspdf (inv(k(m)), lambda); |
10549 | 67 else |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
68 cdf(m) = cdf(m) + poisspdf (inv(k(m)), lambda(k(m))); |
10549 | 69 endif |
5410 | 70 else |
71 break; | |
72 endif | |
73 endwhile | |
74 endif | |
75 | |
76 endfunction |