Changeset 12581
 Timestamp:
 07/03/15 14:34:21 (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs
r12012 r12581 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 39 40 protected const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)"; 40 41 protected const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)"; 41 protected const string TrainingMeanErrorResultName = "Mean error (training)"; 42 protected const string TestMeanErrorResultName = "Mean error (test)"; 42 protected const string TrainingRootMeanSquaredErrorResultName = "Root mean squared error (training)"; 43 protected const string TestRootMeanSquaredErrorResultName = "Root mean squared error (test)"; 44 45 // BackwardsCompatibility3.3 46 #region Backwards compatible code, remove with 3.5 47 private const string TrainingMeanErrorResultName = "Mean error (training)"; 48 private const string TestMeanErrorResultName = "Mean error (test)"; 49 #endregion 50 43 51 44 52 protected const string TrainingMeanSquaredErrorResultDescription = "Mean of squared errors of the model on the training partition"; … … 52 60 protected const string TrainingNormalizedMeanSquaredErrorResultDescription = "Normalized mean of squared errors of the model on the training partition"; 53 61 protected const string TestNormalizedMeanSquaredErrorResultDescription = "Normalized mean of squared errors of the model on the test partition"; 54 protected const string Training MeanErrorResultDescription = "Mean oferrors of the model on the training partition";55 protected const string Test MeanErrorResultDescription = "Mean oferrors of the model on the test partition";62 protected const string TrainingRootMeanSquaredErrorResultDescription = "Root mean of squared errors of the model on the training partition"; 63 protected const string TestRootMeanSquaredErrorResultDescription = "Root mean of squared errors of the model on the test partition"; 56 64 57 65 public new IRegressionModel Model { … … 111 119 private set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; } 112 120 } 113 public double TrainingMeanError { 114 get { return ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value; } 115 private set { ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value = value; } 116 } 117 public double TestMeanError { 118 get { return ((DoubleValue)this[TestMeanErrorResultName].Value).Value; } 119 private set { ((DoubleValue)this[TestMeanErrorResultName].Value).Value = value; } 120 } 121 public double TrainingRootMeanSquaredError { 122 get { return ((DoubleValue)this[TrainingRootMeanSquaredErrorResultName].Value).Value; } 123 private set { ((DoubleValue)this[TrainingRootMeanSquaredErrorResultName].Value).Value = value; } 124 } 125 public double TestRootMeanSquaredError { 126 get { return ((DoubleValue)this[TestRootMeanSquaredErrorResultName].Value).Value; } 127 private set { ((DoubleValue)this[TestRootMeanSquaredErrorResultName].Value).Value = value; } 128 } 129 130 // BackwardsCompatibility3.3 131 #region Backwards compatible code, remove with 3.5 132 private double TrainingMeanError { 133 get { 134 if (!ContainsKey(TrainingMeanErrorResultName)) return double.NaN; 135 return ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value; 136 } 137 set { 138 if (ContainsKey(TrainingMeanErrorResultName)) 139 ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value = value; 140 } 141 } 142 private double TestMeanError { 143 get { 144 if (!ContainsKey(TestMeanErrorResultName)) return double.NaN; 145 return ((DoubleValue)this[TestMeanErrorResultName].Value).Value; 146 } 147 set { 148 if (ContainsKey(TestMeanErrorResultName)) 149 ((DoubleValue)this[TestMeanErrorResultName].Value).Value = value; 150 } 151 } 152 #endregion 121 153 #endregion 122 154 … … 138 170 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, TrainingNormalizedMeanSquaredErrorResultDescription, new DoubleValue())); 139 171 Add(new Result(TestNormalizedMeanSquaredErrorResultName, TestNormalizedMeanSquaredErrorResultDescription, new DoubleValue())); 140 Add(new Result(Training MeanErrorResultName, TrainingMeanErrorResultDescription, new DoubleValue()));141 Add(new Result(Test MeanErrorResultName, TestMeanErrorResultDescription, new DoubleValue()));172 Add(new Result(TrainingRootMeanSquaredErrorResultName, TrainingRootMeanSquaredErrorResultDescription, new DoubleValue())); 173 Add(new Result(TestRootMeanSquaredErrorResultName, TestRootMeanSquaredErrorResultDescription, new DoubleValue())); 142 174 } 143 175 … … 145 177 private void AfterDeserialization() { 146 178 // BackwardsCompatibility3.4 147 148 179 #region Backwards compatible code, remove with 3.5 149 150 180 if (!ContainsKey(TrainingMeanAbsoluteErrorResultName)) { 151 181 OnlineCalculatorError errorState; … … 162 192 } 163 193 164 if (!ContainsKey(TrainingMeanErrorResultName)) { 165 OnlineCalculatorError errorState; 166 Add(new Result(TrainingMeanErrorResultName, "Mean of errors of the model on the training partition", new DoubleValue())); 167 double trainingME = OnlineMeanErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState); 168 TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN; 169 } 170 if (!ContainsKey(TestMeanErrorResultName)) { 171 OnlineCalculatorError errorState; 172 Add(new Result(TestMeanErrorResultName, "Mean of errors of the model on the test partition", new DoubleValue())); 173 double testME = OnlineMeanErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState); 174 TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN; 194 if (!ContainsKey(TrainingRootMeanSquaredErrorResultName)) { 195 OnlineCalculatorError errorState; 196 Add(new Result(TrainingRootMeanSquaredErrorResultName, TrainingRootMeanSquaredErrorResultDescription, new DoubleValue())); 197 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState); 198 TrainingRootMeanSquaredError = errorState == OnlineCalculatorError.None ? Math.Sqrt(trainingMSE) : double.NaN; 199 } 200 201 if (!ContainsKey(TestRootMeanSquaredErrorResultName)) { 202 OnlineCalculatorError errorState; 203 Add(new Result(TestRootMeanSquaredErrorResultName, TestRootMeanSquaredErrorResultDescription, new DoubleValue())); 204 double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState); 205 TestRootMeanSquaredError = errorState == OnlineCalculatorError.None ? Math.Sqrt(testMSE) : double.NaN; 175 206 } 176 207 #endregion … … 213 244 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN; 214 245 215 double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 216 TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN; 217 double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 218 TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN; 246 TrainingRootMeanSquaredError = Math.Sqrt(TrainingMeanSquaredError); 247 TestRootMeanSquaredError = Math.Sqrt(TestMeanSquaredError); 248 249 // BackwardsCompatibility3.3 250 #region Backwards compatible code, remove with 3.5 251 if (ContainsKey(TrainingMeanErrorResultName)) { 252 double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 253 TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN; 254 } 255 if (ContainsKey(TestMeanErrorResultName)) { 256 double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 257 TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN; 258 } 259 #endregion 219 260 } 220 261 }
Note: See TracChangeset
for help on using the changeset viewer.