[Quantproject-developers] QuantProject/b1_ADT/Statistics NormalDistribution.cs,1.3,1.4
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-06-02 18:11:47
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Statistics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22873/b1_ADT/Statistics Modified Files: NormalDistribution.cs Log Message: Fixed bug in the constructor method for the normal distribution class (the standard deviation must be > 0; otherwise an exception is raised) In addition, new exceptions are now raised in some methods of the class, for gaining more control on the code Index: NormalDistribution.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Statistics/NormalDistribution.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NormalDistribution.cs 14 Apr 2005 18:28:24 -0000 1.3 --- NormalDistribution.cs 2 Jun 2005 18:11:37 -0000 1.4 *************** *** 43,47 **** public NormalDistribution(double average, double stdDeviation) { ! if(stdDeviation < 0) throw new Exception("Standard deviation must be > 0!"); --- 43,47 ---- public NormalDistribution(double average, double stdDeviation) { ! if(stdDeviation <= 0) throw new Exception("Standard deviation must be > 0!"); *************** *** 60,64 **** public double GetProbabilityDensityValue(double x) { ! double y; y = Math.Pow(Math.E,(-Math.Pow(x-this.average,2) /(2*this.stdDeviation*this.stdDeviation))) --- 60,67 ---- public double GetProbabilityDensityValue(double x) { ! if(Double.IsInfinity(x) || Double.IsNaN(x)) ! throw new Exception("Density value of x is not computable!"); ! ! double y = 0; y = Math.Pow(Math.E,(-Math.Pow(x-this.average,2) /(2*this.stdDeviation*this.stdDeviation))) *************** *** 74,78 **** public double GetProbability(double y) { ! return this.GetProbability(-this.infinity, y); } --- 77,83 ---- public double GetProbability(double y) { ! if(Double.IsInfinity(y) || Double.IsNaN(y)) ! throw new Exception("Prob(Y<y) is not computable!"); ! return this.GetProbability(-this.infinity, y); } *************** *** 83,89 **** public double GetProbability(double a, double b) { ! return CalculusApproximation.GetArea((IPdfDefiner)this,a,b, ! this.numOfIntervalsForPDFIntegralApproximation); } --- 88,98 ---- public double GetProbability(double a, double b) { ! if( Double.IsInfinity(a) || Double.IsNaN(a) || ! Double.IsInfinity(b) || Double.IsNaN(b) ) ! throw new Exception("Prob(a<Y<b) is not computable!"); ! ! return CalculusApproximation.GetArea((IPdfDefiner)this,a,b, ! this.numOfIntervalsForPDFIntegralApproximation); } |