1 | /*************************************************************************
|
---|
2 | Cephes Math Library Release 2.8: June, 2000
|
---|
3 | Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
|
---|
4 |
|
---|
5 | Contributors:
|
---|
6 | * Sergey Bochkanov (ALGLIB project). Translation from C to
|
---|
7 | pseudocode.
|
---|
8 |
|
---|
9 | See subroutines comments for additional copyrights.
|
---|
10 |
|
---|
11 | >>> SOURCE LICENSE >>>
|
---|
12 | This program is free software; you can redistribute it and/or modify
|
---|
13 | it under the terms of the GNU General Public License as published by
|
---|
14 | the Free Software Foundation (www.fsf.org); either version 2 of the
|
---|
15 | License, or (at your option) any later version.
|
---|
16 |
|
---|
17 | This program is distributed in the hope that it will be useful,
|
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | GNU General Public License for more details.
|
---|
21 |
|
---|
22 | A copy of the GNU General Public License is available at
|
---|
23 | http://www.fsf.org/licensing/licenses
|
---|
24 |
|
---|
25 | >>> END OF LICENSE >>>
|
---|
26 | *************************************************************************/
|
---|
27 |
|
---|
28 | using System;
|
---|
29 |
|
---|
30 | namespace alglib
|
---|
31 | {
|
---|
32 | public class poissondistr
|
---|
33 | {
|
---|
34 | /*************************************************************************
|
---|
35 | Poisson distribution
|
---|
36 |
|
---|
37 | Returns the sum of the first k+1 terms of the Poisson
|
---|
38 | distribution:
|
---|
39 |
|
---|
40 | k j
|
---|
41 | -- -m m
|
---|
42 | > e --
|
---|
43 | -- j!
|
---|
44 | j=0
|
---|
45 |
|
---|
46 | The terms are not summed directly; instead the incomplete
|
---|
47 | gamma integral is employed, according to the relation
|
---|
48 |
|
---|
49 | y = pdtr( k, m ) = igamc( k+1, m ).
|
---|
50 |
|
---|
51 | The arguments must both be positive.
|
---|
52 | ACCURACY:
|
---|
53 |
|
---|
54 | See incomplete gamma function
|
---|
55 |
|
---|
56 | Cephes Math Library Release 2.8: June, 2000
|
---|
57 | Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
|
---|
58 | *************************************************************************/
|
---|
59 | public static double poissondistribution(int k,
|
---|
60 | double m)
|
---|
61 | {
|
---|
62 | double result = 0;
|
---|
63 |
|
---|
64 | System.Diagnostics.Debug.Assert(k>=0 & (double)(m)>(double)(0), "Domain error in PoissonDistribution");
|
---|
65 | result = igammaf.incompletegammac(k+1, m);
|
---|
66 | return result;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | /*************************************************************************
|
---|
71 | Complemented Poisson distribution
|
---|
72 |
|
---|
73 | Returns the sum of the terms k+1 to infinity of the Poisson
|
---|
74 | distribution:
|
---|
75 |
|
---|
76 | inf. j
|
---|
77 | -- -m m
|
---|
78 | > e --
|
---|
79 | -- j!
|
---|
80 | j=k+1
|
---|
81 |
|
---|
82 | The terms are not summed directly; instead the incomplete
|
---|
83 | gamma integral is employed, according to the formula
|
---|
84 |
|
---|
85 | y = pdtrc( k, m ) = igam( k+1, m ).
|
---|
86 |
|
---|
87 | The arguments must both be positive.
|
---|
88 |
|
---|
89 | ACCURACY:
|
---|
90 |
|
---|
91 | See incomplete gamma function
|
---|
92 |
|
---|
93 | Cephes Math Library Release 2.8: June, 2000
|
---|
94 | Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
|
---|
95 | *************************************************************************/
|
---|
96 | public static double poissoncdistribution(int k,
|
---|
97 | double m)
|
---|
98 | {
|
---|
99 | double result = 0;
|
---|
100 |
|
---|
101 | System.Diagnostics.Debug.Assert(k>=0 & (double)(m)>(double)(0), "Domain error in PoissonDistributionC");
|
---|
102 | result = igammaf.incompletegamma(k+1, m);
|
---|
103 | return result;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | /*************************************************************************
|
---|
108 | Inverse Poisson distribution
|
---|
109 |
|
---|
110 | Finds the Poisson variable x such that the integral
|
---|
111 | from 0 to x of the Poisson density is equal to the
|
---|
112 | given probability y.
|
---|
113 |
|
---|
114 | This is accomplished using the inverse gamma integral
|
---|
115 | function and the relation
|
---|
116 |
|
---|
117 | m = igami( k+1, y ).
|
---|
118 |
|
---|
119 | ACCURACY:
|
---|
120 |
|
---|
121 | See inverse incomplete gamma function
|
---|
122 |
|
---|
123 | Cephes Math Library Release 2.8: June, 2000
|
---|
124 | Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
|
---|
125 | *************************************************************************/
|
---|
126 | public static double invpoissondistribution(int k,
|
---|
127 | double y)
|
---|
128 | {
|
---|
129 | double result = 0;
|
---|
130 |
|
---|
131 | System.Diagnostics.Debug.Assert(k>=0 & (double)(y)>=(double)(0) & (double)(y)<(double)(1), "Domain error in InvPoissonDistribution");
|
---|
132 | result = igammaf.invincompletegammac(k+1, y);
|
---|
133 | return result;
|
---|
134 | }
|
---|
135 | }
|
---|
136 | }
|
---|