Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.5.0/ALGLIB-2.5.0/chisquaredistr.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/chisquaredistr.cs
r3839 r4068 26 26 *************************************************************************/ 27 27 28 using System;29 28 30 namespace alglib 31 { 32 public class chisquaredistr 33 { 34 /************************************************************************* 35 Chi-square distribution 29 namespace alglib { 30 public class chisquaredistr { 31 /************************************************************************* 32 Chi-square distribution 36 33 37 38 39 34 Returns the area under the left hand tail (from 0 to x) 35 of the Chi square probability density function with 36 v degrees of freedom. 40 37 41 38 42 43 44 45 46 47 48 39 x 40 - 41 1 | | v/2-1 -t/2 42 P( x | v ) = ----------- | t e dt 43 v/2 - | | 44 2 | (v/2) - 45 0 49 46 50 47 where x is the Chi-square variable. 51 48 52 53 49 The incomplete gamma integral is used, according to the 50 formula 54 51 55 52 y = chdtr( v, x ) = igam( v/2.0, x/2.0 ). 56 53 57 54 The arguments must both be positive. 58 55 59 56 ACCURACY: 60 57 61 58 See incomplete gamma function 62 59 63 60 64 Cephes Math Library Release 2.8: June, 2000 65 Copyright 1984, 1987, 2000 by Stephen L. Moshier 66 *************************************************************************/ 67 public static double chisquaredistribution(double v, 68 double x) 69 { 70 double result = 0; 61 Cephes Math Library Release 2.8: June, 2000 62 Copyright 1984, 1987, 2000 by Stephen L. Moshier 63 *************************************************************************/ 64 public static double chisquaredistribution(double v, 65 double x) { 66 double result = 0; 71 67 72 System.Diagnostics.Debug.Assert((double)(x)>=(double)(0) & (double)(v)>=(double)(1), "Domain error in ChiSquareDistribution");73 result = igammaf.incompletegamma(v/2.0, x/2.0);74 75 68 System.Diagnostics.Debug.Assert((double)(x) >= (double)(0) & (double)(v) >= (double)(1), "Domain error in ChiSquareDistribution"); 69 result = igammaf.incompletegamma(v / 2.0, x / 2.0); 70 return result; 71 } 76 72 77 73 78 79 74 /************************************************************************* 75 Complemented Chi-square distribution 80 76 81 82 83 77 Returns the area under the right hand tail (from x to 78 infinity) of the Chi square probability density function 79 with v degrees of freedom: 84 80 85 86 87 88 89 90 91 81 inf. 82 - 83 1 | | v/2-1 -t/2 84 P( x | v ) = ----------- | t e dt 85 v/2 - | | 86 2 | (v/2) - 87 x 92 88 93 89 where x is the Chi-square variable. 94 90 95 96 91 The incomplete gamma integral is used, according to the 92 formula 97 93 98 94 y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ). 99 95 100 96 The arguments must both be positive. 101 97 102 98 ACCURACY: 103 99 104 100 See incomplete gamma function 105 101 106 Cephes Math Library Release 2.8: June, 2000 107 Copyright 1984, 1987, 2000 by Stephen L. Moshier 108 *************************************************************************/ 109 public static double chisquarecdistribution(double v, 110 double x) 111 { 112 double result = 0; 102 Cephes Math Library Release 2.8: June, 2000 103 Copyright 1984, 1987, 2000 by Stephen L. Moshier 104 *************************************************************************/ 105 public static double chisquarecdistribution(double v, 106 double x) { 107 double result = 0; 113 108 114 System.Diagnostics.Debug.Assert((double)(x)>=(double)(0) & (double)(v)>=(double)(1), "Domain error in ChiSquareDistributionC");115 result = igammaf.incompletegammac(v/2.0, x/2.0);116 117 109 System.Diagnostics.Debug.Assert((double)(x) >= (double)(0) & (double)(v) >= (double)(1), "Domain error in ChiSquareDistributionC"); 110 result = igammaf.incompletegammac(v / 2.0, x / 2.0); 111 return result; 112 } 118 113 119 114 120 121 115 /************************************************************************* 116 Inverse of complemented Chi-square distribution 122 117 123 124 125 118 Finds the Chi-square argument x such that the integral 119 from x to infinity of the Chi-square density is equal 120 to the given cumulative probability y. 126 121 127 128 122 This is accomplished using the inverse gamma integral 123 function and the relation 129 124 130 125 x/2 = igami( df/2, y ); 131 126 132 127 ACCURACY: 133 128 134 129 See inverse incomplete gamma function 135 130 136 131 137 Cephes Math Library Release 2.8: June, 2000 138 Copyright 1984, 1987, 2000 by Stephen L. Moshier 139 *************************************************************************/ 140 public static double invchisquaredistribution(double v, 141 double y) 142 { 143 double result = 0; 132 Cephes Math Library Release 2.8: June, 2000 133 Copyright 1984, 1987, 2000 by Stephen L. Moshier 134 *************************************************************************/ 135 public static double invchisquaredistribution(double v, 136 double y) { 137 double result = 0; 144 138 145 System.Diagnostics.Debug.Assert((double)(y)>=(double)(0) & (double)(y)<=(double)(1) & (double)(v)>=(double)(1), "Domain error in InvChiSquareDistribution"); 146 result = 2*igammaf.invincompletegammac(0.5*v, y); 147 return result; 148 } 139 System.Diagnostics.Debug.Assert((double)(y) >= (double)(0) & (double)(y) <= (double)(1) & (double)(v) >= (double)(1), "Domain error in InvChiSquareDistribution"); 140 result = 2 * igammaf.invincompletegammac(0.5 * v, y); 141 return result; 149 142 } 143 } 150 144 }
Note: See TracChangeset
for help on using the changeset viewer.