Changeset 2136 for trunk/sources/HeuristicLab.Modeling
- Timestamp:
- 07/06/09 17:12:37 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Modeling/3.2
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Modeling/3.2/SimpleEvaluatorBase.cs
r1888 r2136 31 31 32 32 public abstract double Evaluate(double[,] values); 33 34 protected static bool IsAlmost(double x, double y) { 35 return Math.Abs(x - y) < 1.0E-12; 36 } 33 37 } 34 38 } -
trunk/sources/HeuristicLab.Modeling/3.2/SimpleMSEEvaluator.cs
r1888 r2136 16 16 } 17 17 public override double Evaluate(double[,] values) { 18 return Calculate(values); 18 try { 19 return Calculate(values); 20 } 21 catch (ArgumentException) { 22 return double.PositiveInfinity; 23 } 19 24 } 20 25 … … 32 37 } 33 38 } 34 35 double mse = sse / cnt; 36 return mse; 39 if (cnt > 0) { 40 double mse = sse / cnt; 41 return mse; 42 } else { 43 throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf"); 44 } 37 45 } 38 46 } -
trunk/sources/HeuristicLab.Modeling/3.2/SimpleMeanAbsolutePercentageErrorEvaluator.cs
r1888 r2136 38 38 39 39 public override double Evaluate(double[,] values) { 40 return Calculate(values); 40 try { 41 return Calculate(values); 42 } 43 catch (ArgumentException) { 44 return double.PositiveInfinity; 45 } 41 46 } 42 47 … … 55 60 } 56 61 } 57 return errorsSum / n; 62 if (n > 0) { 63 return errorsSum / n; 64 } else throw new ArgumentException("Mean of absolute percentage error is not defined for input vectors of NaN or Inf"); 58 65 } 59 66 } -
trunk/sources/HeuristicLab.Modeling/3.2/SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.cs
r1888 r2136 37 37 38 38 public override double Evaluate(double[,] values) { 39 return Calculate(values); 39 try { 40 return Calculate(values); 41 } 42 catch (ArgumentException) { 43 return double.PositiveInfinity; 44 } 40 45 } 41 46 … … 47 52 for (int i = 0; i < originalValues.Length; i++) originalValues[i] = values[i, 1]; 48 53 double range = Statistics.Range(originalValues); 54 if (double.IsInfinity(range)) throw new ArgumentException("Range of elements in values is infinity"); 55 if (IsAlmost(range, 0.0)) throw new ArgumentException("Range of elements in values is zero"); 49 56 50 57 for (int i = 0; i < values.GetLength(0); i++) { … … 59 66 } 60 67 } 61 return errorsSum / n; 68 if (double.IsInfinity(range) || n == 0) { 69 throw new ArgumentException("Mean of absolute percentage of range error is not defined for input vectors of NaN or Inf"); 70 } else { 71 return errorsSum / n; 72 } 62 73 } 63 74 } -
trunk/sources/HeuristicLab.Modeling/3.2/SimpleR2Evaluator.cs
r1888 r2136 17 17 18 18 public override double Evaluate(double[,] values) { 19 return Calculate(values); 19 try { 20 return Calculate(values); 21 } 22 catch (ArgumentException) { 23 return double.NegativeInfinity; 24 } 20 25 } 21 26 … … 35 40 } 36 41 } 37 targetMean /= cnt;38 42 39 double targetDeviationTotalSumOfSquares = 0; 40 for (int i = 0; i < values.GetLength(0); i++) { 41 double target = values[i, 1]; 42 if (!double.IsNaN(target) && !double.IsInfinity(target)) { 43 target = target - targetMean; 44 target = target * target; 45 targetDeviationTotalSumOfSquares += target; 43 if (cnt > 0) { 44 targetMean /= cnt; 45 46 double targetDeviationTotalSumOfSquares = 0; 47 for (int i = 0; i < values.GetLength(0); i++) { 48 double target = values[i, 1]; 49 if (!double.IsNaN(target) && !double.IsInfinity(target)) { 50 target = target - targetMean; 51 target = target * target; 52 targetDeviationTotalSumOfSquares += target; 53 } 46 54 } 55 double quality = 1 - sse / targetDeviationTotalSumOfSquares; 56 if (quality > 1) 57 throw new InvalidProgramException(); 58 59 return quality; 60 } else { 61 throw new ArgumentException("Coefficient of determination is not defined for input vectors of NaN or Inf"); 47 62 } 48 double quality = 1 - sse / targetDeviationTotalSumOfSquares;49 if (quality > 1)50 throw new InvalidProgramException();51 52 return quality;53 63 } 54 64 } -
trunk/sources/HeuristicLab.Modeling/3.2/SimpleVarianceAccountedForEvaluator.cs
r1888 r2136 43 43 44 44 public override double Evaluate(double[,] values) { 45 return Calculate(values); 45 try { 46 return Calculate(values); 47 } 48 catch (ArgumentException) { 49 return double.NegativeInfinity; 50 } 46 51 } 47 52 … … 64 69 double errorsVariance = Statistics.Variance(errors); 65 70 double originalsVariance = Statistics.Variance(originalTargetVariableValues); 66 double quality = 1 - errorsVariance / originalsVariance; 67 68 return quality; 71 if (IsAlmost(originalsVariance, 0.0)) 72 if (IsAlmost(errorsVariance, 0.0)) { 73 return 1.0; 74 } else { 75 throw new ArgumentException("Variance of original values is zero"); 76 } else { 77 return 1.0 - errorsVariance / originalsVariance; 78 } 69 79 } 70 80 } -
trunk/sources/HeuristicLab.Modeling/3.2/VariableEvaluationImpactCalculator.cs
r2043 r2136 50 50 51 51 protected override double CalculateImpact(double[] referenceValue, double[] newValue) { 52 return SimpleMSEEvaluator.Calculate(CombineOutputs(referenceValue, newValue)); 52 try { 53 return SimpleMSEEvaluator.Calculate(CombineOutputs(referenceValue, newValue)); 54 } 55 catch (ArgumentException) { 56 return double.PositiveInfinity; 57 } 53 58 } 54 59 … … 59 64 protected override double[] PostProcessImpacts(double[] impacts) { 60 65 double mseSum = impacts.Sum(); 61 if ( mseSum == 0.0) mseSum = 1.0;66 if (IsAlmost(mseSum, 0.0)) mseSum = 1.0; 62 67 for (int i = 0; i < impacts.Length; i++) { 63 68 impacts[i] = impacts[i] / mseSum; … … 66 71 } 67 72 73 private bool IsAlmost(double x, double y) { 74 return Math.Abs(x - y) < 1.0E-12; 75 } 76 68 77 protected abstract double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end); 69 78 }
Note: See TracChangeset
for help on using the changeset viewer.