Changeset 6643
- Timestamp:
- 08/08/11 17:47:46 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r6589 r6643 139 139 <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" /> 140 140 <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" /> 141 <Compile Include="OnlineCalculators\OnlineMeanAbsoluteErrorCalculator.cs" /> 141 142 <Compile Include="OnlineCalculators\OnlineLinearScalingParameterCalculator.cs" /> 142 143 <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationModel.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs
r6589 r6643 32 32 private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)"; 33 33 private const string TestMeanSquaredErrorResultName = "Mean squared error (test)"; 34 private const string TrainingMeanAbsoluteErrorResultName = "Mean absolute error (training)"; 35 private const string TestMeanAbsoluteErrorResultName = "Mean absolute error (test)"; 34 36 private const string TrainingSquaredCorrelationResultName = "Pearson's R² (training)"; 35 37 private const string TestSquaredCorrelationResultName = "Pearson's R² (test)"; … … 62 64 get { return ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value; } 63 65 private set { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; } 66 } 67 public double TrainingMeanAbsoluteError { 68 get { return ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value; } 69 private set { ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value = value; } 70 } 71 public double TestMeanAbsoluteError { 72 get { return ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value; } 73 private set { ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value = value; } 64 74 } 65 75 public double TrainingRSquared { … … 98 108 Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue())); 99 109 Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue())); 110 Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue())); 111 Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue())); 100 112 Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue())); 101 113 Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue())); … … 104 116 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue())); 105 117 Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue())); 118 } 119 120 [StorableHook(HookType.AfterDeserialization)] 121 private void AfterDeserialization() { 122 // BackwardsCompatibility3.4 123 124 #region Backwards compatible code, remove with 3.5 125 126 if (!ContainsKey(TrainingMeanAbsoluteErrorResultName)) { 127 OnlineCalculatorError errorState; 128 Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue())); 129 double trainingMAE = OnlineMeanSquaredErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes), out errorState); 130 TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN; 131 } 132 133 if (!ContainsKey(TestMeanAbsoluteErrorResultName)) { 134 OnlineCalculatorError errorState; 135 Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue())); 136 double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes), out errorState); 137 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN; 138 } 139 #endregion 106 140 } 107 141 … … 117 151 double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 118 152 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 153 154 double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 155 TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN; 156 double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 157 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN; 119 158 120 159 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionSolution.cs
r6588 r6643 33 33 double TrainingMeanSquaredError { get; } 34 34 double TestMeanSquaredError { get; } 35 double TrainingMeanAbsoluteError { get; } 36 double TestMeanAbsoluteError { get; } 35 37 double TrainingRSquared { get; } 36 38 double TestRSquared { get; } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs
r6641 r6643 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis { 26 public class OnlineMean SquaredErrorCalculator : IOnlineCalculator {26 public class OnlineMeanAbsoluteErrorCalculator : IOnlineCalculator { 27 27 28 private double s se;28 private double sae; 29 29 private int n; 30 public double Mean SquaredError {30 public double MeanAbsoluteError { 31 31 get { 32 return n > 0 ? s se / n : 0.0;32 return n > 0 ? sae / n : 0.0; 33 33 } 34 34 } 35 35 36 public OnlineMean SquaredErrorCalculator() {36 public OnlineMeanAbsoluteErrorCalculator() { 37 37 Reset(); 38 38 } … … 44 44 } 45 45 public double Value { 46 get { return Mean SquaredError; }46 get { return MeanAbsoluteError; } 47 47 } 48 48 public void Reset() { 49 49 n = 0; 50 s se = 0.0;50 sae = 0.0; 51 51 errorState = OnlineCalculatorError.InsufficientElementsAdded; 52 52 } … … 58 58 } else { 59 59 double error = estimated - original; 60 s se += error * error;60 sae += Math.Abs(error); 61 61 n++; 62 62 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 … … 68 68 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 69 69 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 70 OnlineMean SquaredErrorCalculator mseCalculator = new OnlineMeanSquaredErrorCalculator();70 OnlineMeanAbsoluteErrorCalculator maeCalculator = new OnlineMeanAbsoluteErrorCalculator(); 71 71 72 72 // always move forward both enumerators (do not use short-circuit evaluation!) … … 74 74 double estimated = secondEnumerator.Current; 75 75 double original = firstEnumerator.Current; 76 m seCalculator.Add(original, estimated);77 if (m seCalculator.ErrorState != OnlineCalculatorError.None) break;76 maeCalculator.Add(original, estimated); 77 if (maeCalculator.ErrorState != OnlineCalculatorError.None) break; 78 78 } 79 79 80 80 // check if both enumerators are at the end to make sure both enumerations have the same length 81 if (m seCalculator.ErrorState == OnlineCalculatorError.None &&81 if (maeCalculator.ErrorState == OnlineCalculatorError.None && 82 82 (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) { 83 83 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 84 84 } else { 85 errorState = m seCalculator.ErrorState;86 return m seCalculator.MeanSquaredError;85 errorState = maeCalculator.ErrorState; 86 return maeCalculator.MeanAbsoluteError; 87 87 } 88 88 }
Note: See TracChangeset
for help on using the changeset viewer.