Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.5.0/ALGLIB-2.5.0/fdistr.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.5.0/ALGLIB-2.5.0/fdistr.cs
r3839 r4068 26 26 *************************************************************************/ 27 27 28 using System;29 28 30 namespace alglib 31 { 32 public class fdistr 33 { 34 /************************************************************************* 35 F distribution 29 namespace alglib { 30 public class fdistr { 31 /************************************************************************* 32 F distribution 36 33 37 38 39 40 41 42 43 44 34 Returns the area from zero to x under the F density 35 function (also known as Snedcor's density or the 36 variance ratio density). This is the density 37 of x = (u1/df1)/(u2/df2), where u1 and u2 are random 38 variables having Chi square distributions with df1 39 and df2 degrees of freedom, respectively. 40 The incomplete beta integral is used, according to the 41 formula 45 42 46 43 P(x) = incbet( df1/2, df2/2, (df1*x/(df2 + df1*x) ). 47 44 48 45 49 50 46 The arguments a and b are greater than zero, and x is 47 nonnegative. 51 48 52 49 ACCURACY: 53 50 54 51 Tested at random points (a,b,x). 55 52 56 57 58 59 60 61 53 x a,b Relative error: 54 arithmetic domain domain # trials peak rms 55 IEEE 0,1 0,100 100000 9.8e-15 1.7e-15 56 IEEE 1,5 0,100 100000 6.5e-15 3.5e-16 57 IEEE 0,1 1,10000 100000 2.2e-11 3.3e-12 58 IEEE 1,5 1,10000 100000 1.1e-11 1.7e-13 62 59 63 Cephes Math Library Release 2.8: June, 2000 64 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier 65 *************************************************************************/ 66 public static double fdistribution(int a, 67 int b, 68 double x) 69 { 70 double result = 0; 71 double w = 0; 60 Cephes Math Library Release 2.8: June, 2000 61 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier 62 *************************************************************************/ 63 public static double fdistribution(int a, 64 int b, 65 double x) { 66 double result = 0; 67 double w = 0; 72 68 73 System.Diagnostics.Debug.Assert(a>=1 & b>=1 & (double)(x)>=(double)(0), "Domain error in FDistribution");74 w = a*x;75 w = w/(b+w);76 result = ibetaf.incompletebeta(0.5*a, 0.5*b, w);77 78 69 System.Diagnostics.Debug.Assert(a >= 1 & b >= 1 & (double)(x) >= (double)(0), "Domain error in FDistribution"); 70 w = a * x; 71 w = w / (b + w); 72 result = ibetaf.incompletebeta(0.5 * a, 0.5 * b, w); 73 return result; 74 } 79 75 80 76 81 82 77 /************************************************************************* 78 Complemented F distribution 83 79 84 85 86 80 Returns the area from x to infinity under the F density 81 function (also known as Snedcor's density or the 82 variance ratio density). 87 83 88 84 89 90 91 92 93 94 95 85 inf. 86 - 87 1 | | a-1 b-1 88 1-P(x) = ------ | t (1-t) dt 89 B(a,b) | | 90 - 91 x 96 92 97 93 98 99 94 The incomplete beta integral is used, according to the 95 formula 100 96 101 97 P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ). 102 98 103 99 104 100 ACCURACY: 105 101 106 107 108 109 110 111 112 102 Tested at random points (a,b,x) in the indicated intervals. 103 x a,b Relative error: 104 arithmetic domain domain # trials peak rms 105 IEEE 0,1 1,100 100000 3.7e-14 5.9e-16 106 IEEE 1,5 1,100 100000 8.0e-15 1.6e-15 107 IEEE 0,1 1,10000 100000 1.8e-11 3.5e-13 108 IEEE 1,5 1,10000 100000 2.0e-11 3.0e-12 113 109 114 Cephes Math Library Release 2.8: June, 2000 115 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier 116 *************************************************************************/ 117 public static double fcdistribution(int a, 118 int b, 119 double x) 120 { 121 double result = 0; 122 double w = 0; 110 Cephes Math Library Release 2.8: June, 2000 111 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier 112 *************************************************************************/ 113 public static double fcdistribution(int a, 114 int b, 115 double x) { 116 double result = 0; 117 double w = 0; 123 118 124 System.Diagnostics.Debug.Assert(a>=1 & b>=1 & (double)(x)>=(double)(0), "Domain error in FCDistribution");125 w = b/(b+a*x);126 result = ibetaf.incompletebeta(0.5*b, 0.5*a, w);127 128 119 System.Diagnostics.Debug.Assert(a >= 1 & b >= 1 & (double)(x) >= (double)(0), "Domain error in FCDistribution"); 120 w = b / (b + a * x); 121 result = ibetaf.incompletebeta(0.5 * b, 0.5 * a, w); 122 return result; 123 } 129 124 130 125 131 132 126 /************************************************************************* 127 Inverse of complemented F distribution 133 128 134 135 136 129 Finds the F density argument x such that the integral 130 from x to infinity of the F density is equal to the 131 given probability p. 137 132 138 139 133 This is accomplished using the inverse beta integral 134 function and the relations 140 135 141 142 136 z = incbi( df2/2, df1/2, p ) 137 x = df2 (1-z) / (df1 z). 143 138 144 145 139 Note: the following relations hold for the inverse of 140 the uncomplemented F distribution: 146 141 147 148 142 z = incbi( df1/2, df2/2, p ) 143 x = df2 z / (df1 (1-z)). 149 144 150 145 ACCURACY: 151 146 152 147 Tested at random points (a,b,p). 153 148 154 155 156 157 158 159 160 161 149 a,b Relative error: 150 arithmetic domain # trials peak rms 151 For p between .001 and 1: 152 IEEE 1,100 100000 8.3e-15 4.7e-16 153 IEEE 1,10000 100000 2.1e-11 1.4e-13 154 For p between 10^-6 and 10^-3: 155 IEEE 1,100 50000 1.3e-12 8.4e-15 156 IEEE 1,10000 50000 3.0e-12 4.8e-14 162 157 163 Cephes Math Library Release 2.8: June, 2000 164 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier 165 *************************************************************************/ 166 public static double invfdistribution(int a, 167 int b, 168 double y) 169 { 170 double result = 0; 171 double w = 0; 158 Cephes Math Library Release 2.8: June, 2000 159 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier 160 *************************************************************************/ 161 public static double invfdistribution(int a, 162 int b, 163 double y) { 164 double result = 0; 165 double w = 0; 172 166 173 System.Diagnostics.Debug.Assert(a>=1 & b>=1 & (double)(y)>(double)(0) & (double)(y)<=(double)(1), "Domain error in InvFDistribution"); 174 175 // 176 // Compute probability for x = 0.5 177 // 178 w = ibetaf.incompletebeta(0.5*b, 0.5*a, 0.5); 179 180 // 181 // If that is greater than y, then the solution w < .5 182 // Otherwise, solve at 1-y to remove cancellation in (b - b*w) 183 // 184 if( (double)(w)>(double)(y) | (double)(y)<(double)(0.001) ) 185 { 186 w = ibetaf.invincompletebeta(0.5*b, 0.5*a, y); 187 result = (b-b*w)/(a*w); 188 } 189 else 190 { 191 w = ibetaf.invincompletebeta(0.5*a, 0.5*b, 1.0-y); 192 result = b*w/(a*(1.0-w)); 193 } 194 return result; 195 } 167 System.Diagnostics.Debug.Assert(a >= 1 & b >= 1 & (double)(y) > (double)(0) & (double)(y) <= (double)(1), "Domain error in InvFDistribution"); 168 169 // 170 // Compute probability for x = 0.5 171 // 172 w = ibetaf.incompletebeta(0.5 * b, 0.5 * a, 0.5); 173 174 // 175 // If that is greater than y, then the solution w < .5 176 // Otherwise, solve at 1-y to remove cancellation in (b - b*w) 177 // 178 if ((double)(w) > (double)(y) | (double)(y) < (double)(0.001)) { 179 w = ibetaf.invincompletebeta(0.5 * b, 0.5 * a, y); 180 result = (b - b * w) / (a * w); 181 } else { 182 w = ibetaf.invincompletebeta(0.5 * a, 0.5 * b, 1.0 - y); 183 result = b * w / (a * (1.0 - w)); 184 } 185 return result; 196 186 } 187 } 197 188 }
Note: See TracChangeset
for help on using the changeset viewer.