Changeset 8750 for branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
- Timestamp:
- 10/05/12 17:57:54 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
r8742 r8750 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 42 41 protected const string TrainingTheilsUStatisticMovingAverageResultName = "Theil's U2 (moving average) (training)"; 43 42 protected const string TestTheilsUStatisticMovingAverageResultName = "Theil's U2 (moving average) (test)"; 44 45 protected const string PrognosisTrainingMeanSquaredErrorResultName = "Prognosis " + TrainingMeanSquaredErrorResultName; 46 protected const string PrognosisTestMeanSquaredErrorResultName = "Prognosis " + TestMeanSquaredErrorResultName; 47 protected const string PrognosisTrainingMeanAbsoluteErrorResultName = "Prognosis " + TrainingMeanAbsoluteErrorResultName; 48 protected const string PrognosisTestMeanAbsoluteErrorResultName = "Prognosis " + TestMeanAbsoluteErrorResultName; 49 protected const string PrognosisTrainingSquaredCorrelationResultName = "Prognosis " + TrainingSquaredCorrelationResultName; 50 protected const string PrognosisTestSquaredCorrelationResultName = "Prognosis " + TestSquaredCorrelationResultName; 51 protected const string PrognosisTrainingRelativeErrorResultName = "Prognosis " + TrainingRelativeErrorResultName; 52 protected const string PrognosisTestRelativeErrorResultName = "Prognosis " + TestRelativeErrorResultName; 53 protected const string PrognosisTrainingNormalizedMeanSquaredErrorResultName = "Prognosis " + TrainingNormalizedMeanSquaredErrorResultName; 54 protected const string PrognosisTestNormalizedMeanSquaredErrorResultName = "Prognosis " + TestNormalizedMeanSquaredErrorResultName; 55 protected const string PrognosisTrainingMeanErrorResultName = "Prognosis " + TrainingMeanErrorResultName; 56 protected const string PrognosisTestMeanErrorResultName = "Prognosis " + TestMeanErrorResultName; 57 58 protected const string PrognosisTrainingDirectionalSymmetryResultName = "Prognosis " + TrainingDirectionalSymmetryResultName; 59 protected const string PrognosisTestDirectionalSymmetryResultName = "Prognosis " + TestDirectionalSymmetryResultName; 60 protected const string PrognosisTrainingWeightedDirectionalSymmetryResultName = "Prognosis " + TrainingWeightedDirectionalSymmetryResultName; 61 protected const string PrognosisTestWeightedDirectionalSymmetryResultName = "Prognosis " + TestWeightedDirectionalSymmetryResultName; 62 protected const string PrognosisTrainingTheilsUStatisticAR1ResultName = "Prognosis " + TrainingTheilsUStatisticAR1ResultName; 63 protected const string PrognosisTestTheilsUStatisticAR1ResultName = "Prognosis " + TestTheilsUStatisticLastResultName; 64 protected const string PrognosisTrainingTheilsUStatisticMeanResultName = "Prognosis " + TrainingTheilsUStatisticMeanResultName; 65 protected const string PrognosisTestTheilsUStatisticMeanResultName = "Prognosis " + TestTheilsUStatisticMeanResultName; 66 protected const string PrognosisTrainingTheilsUStatisticMovingAverageResultName = "Prognosis " + TrainingTheilsUStatisticMovingAverageResultName; 67 protected const string PrognosisTestTheilsUStatisticMovingAverageResultName = "Prognosis " + TestTheilsUStatisticMovingAverageResultName; 43 protected const string TimeSeriesPrognosisResultName = "Prognosis Results"; 68 44 #endregion 69 45 … … 79 55 protected const string TrainingTheilsUStatisticMovingAverageResultDescription = "The Theil's U statistic (reference: moving average model) of the forecasts of the model on the training partition"; 80 56 protected const string TestTheilsUStatisticMovingAverageResultDescription = "The Theil's U statistic (reference: moving average model) of the forecasts of the model on the test partition"; 81 82 protected const string PrognosisTrainingMeanSquaredErrorResultDescription = TrainingMeanSquaredErrorResultDescription; 83 protected const string PrognosisTestMeanSquaredErrorResultDescription = TestMeanSquaredErrorResultDescription; 84 protected const string PrognosisTrainingMeanAbsoluteErrorResultDescription = TrainingMeanAbsoluteErrorResultDescription; 85 protected const string PrognosisTestMeanAbsoluteErrorResultDescription = TestMeanAbsoluteErrorResultDescription; 86 protected const string PrognosisTrainingSquaredCorrelationResultDescription = TrainingSquaredCorrelationResultDescription; 87 protected const string PrognosisTestSquaredCorrelationResultDescription = TestSquaredCorrelationResultDescription; 88 protected const string PrognosisTrainingRelativeErrorResultDescription = TrainingRelativeErrorResultDescription; 89 protected const string PrognosisTestRelativeErrorResultDescription = TestRelativeErrorResultDescription; 90 protected const string PrognosisTrainingNormalizedMeanSquaredErrorResultDescription = TrainingNormalizedMeanSquaredErrorResultDescription; 91 protected const string PrognosisTestNormalizedMeanSquaredErrorResultDescription = TestNormalizedMeanSquaredErrorResultDescription; 92 protected const string PrognosisTrainingMeanErrorResultDescription = TrainingMeanErrorResultDescription; 93 protected const string PrognosisTestMeanErrorResultDescription = TestMeanErrorResultDescription; 94 95 protected const string PrognosisTrainingDirectionalSymmetryResultDescription = TrainingDirectionalSymmetryResultDescription; 96 protected const string PrognosisTestDirectionalSymmetryResultDescription = TestDirectionalSymmetryResultDescription; 97 protected const string PrognosisTrainingWeightedDirectionalSymmetryResultDescription = TrainingWeightedDirectionalSymmetryResultDescription; 98 protected const string PrognosisTestWeightedDirectionalSymmetryResultDescription = TestWeightedDirectionalSymmetryResultDescription; 99 protected const string PrognosisTrainingTheilsUStatisticAR1ResultDescription = TrainingTheilsUStatisticAR1ResultDescription; 100 protected const string PrognosisTestTheilsUStatisticAR1ResultDescription = TestTheilsUStatisticAR1ResultDescription; 101 protected const string PrognosisTrainingTheilsUStatisticMeanResultDescription = TrainingTheilsUStatisticMeanResultDescription; 102 protected const string PrognosisTestTheilsUStatisticMeanResultDescription = TestTheilsUStatisticMeanResultDescription; 103 protected const string PrognosisTrainingTheilsUStatisticMovingAverageResultDescription = TrainingTheilsUStatisticMovingAverageResultDescription; 104 protected const string PrognosisTestTheilsUStatisticMovingAverageResultDescription = TestTheilsUStatisticMovingAverageResultDescription; 57 protected const string TimeSeriesPrognosisResultDescription = "The calculated results of predictions in the future."; 105 58 #endregion 106 59 … … 159 112 } 160 113 161 //prognosis results for different horizons 162 public double PrognosisTrainingMeanSquaredError { 114 public TimeSeriesPrognosisResults TimeSeriesPrognosisResults { 163 115 get { 164 if (!ContainsKey( PrognosisTrainingMeanSquaredErrorResultName)) return double.NaN;165 return ( (DoubleValue)this[PrognosisTrainingMeanSquaredErrorResultName].Value).Value;116 if (!ContainsKey(TimeSeriesPrognosisResultName)) return null; 117 return (TimeSeriesPrognosisResults)this[TimeSeriesPrognosisResultName]; 166 118 } 167 privateset {168 if ( !ContainsKey(PrognosisTrainingMeanSquaredErrorResultName)) Add(new Result(PrognosisTrainingMeanSquaredErrorResultName, PrognosisTrainingMeanSquaredErrorResultDescription, new DoubleValue()));169 ((DoubleValue)this[PrognosisTrainingMeanSquaredErrorResultName].Value).Value = value;119 set { 120 if (ContainsKey(TimeSeriesPrognosisResultName)) Remove(TimeSeriesPrognosisResultName); 121 Add(new Result(TimeSeriesPrognosisResultName, TimeSeriesPrognosisResultDescription, value)); 170 122 } 171 123 } 172 173 public double PrognosisTestMeanSquaredError {174 get {175 if (!ContainsKey(PrognosisTestMeanSquaredErrorResultName)) return double.NaN;176 return ((DoubleValue)this[PrognosisTestMeanSquaredErrorResultName].Value).Value;177 }178 private set {179 if (!ContainsKey(PrognosisTestMeanSquaredErrorResultName)) Add(new Result(PrognosisTestMeanSquaredErrorResultName, PrognosisTestMeanSquaredErrorResultDescription, new DoubleValue()));180 ((DoubleValue)this[PrognosisTestMeanSquaredErrorResultName].Value).Value = value;181 }182 }183 184 public double PrognosisTrainingMeanAbsoluteError {185 get {186 if (!ContainsKey(PrognosisTrainingMeanAbsoluteErrorResultName)) return double.NaN;187 return ((DoubleValue)this[PrognosisTrainingMeanAbsoluteErrorResultName].Value).Value;188 }189 private set {190 if (!ContainsKey(PrognosisTrainingMeanAbsoluteErrorResultName)) Add(new Result(PrognosisTrainingMeanAbsoluteErrorResultName, PrognosisTrainingMeanAbsoluteErrorResultDescription, new DoubleValue()));191 ((DoubleValue)this[PrognosisTrainingMeanAbsoluteErrorResultName].Value).Value = value;192 }193 }194 195 public double PrognosisTestMeanAbsoluteError {196 get {197 if (!ContainsKey(PrognosisTestMeanAbsoluteErrorResultName)) return double.NaN;198 return ((DoubleValue)this[PrognosisTestMeanAbsoluteErrorResultName].Value).Value;199 }200 private set {201 if (!ContainsKey(PrognosisTestMeanAbsoluteErrorResultName)) Add(new Result(PrognosisTestMeanAbsoluteErrorResultName, PrognosisTestMeanAbsoluteErrorResultDescription, new DoubleValue()));202 ((DoubleValue)this[PrognosisTestMeanAbsoluteErrorResultName].Value).Value = value;203 }204 }205 206 public double PrognosisTrainingRSquared {207 get {208 if (!ContainsKey(PrognosisTrainingSquaredCorrelationResultName)) return double.NaN;209 return ((DoubleValue)this[PrognosisTrainingSquaredCorrelationResultName].Value).Value;210 }211 private set {212 if (!ContainsKey(PrognosisTrainingSquaredCorrelationResultName)) Add(new Result(PrognosisTrainingSquaredCorrelationResultName, PrognosisTrainingSquaredCorrelationResultDescription, new DoubleValue()));213 ((DoubleValue)this[PrognosisTrainingSquaredCorrelationResultName].Value).Value = value;214 }215 }216 217 public double PrognosisTestRSquared {218 get {219 if (!ContainsKey(PrognosisTestSquaredCorrelationResultName)) return double.NaN;220 return ((DoubleValue)this[PrognosisTestSquaredCorrelationResultName].Value).Value;221 }222 private set {223 if (!ContainsKey(PrognosisTestSquaredCorrelationResultName)) Add(new Result(PrognosisTestSquaredCorrelationResultName, PrognosisTestSquaredCorrelationResultDescription, new DoubleValue()));224 ((DoubleValue)this[PrognosisTestSquaredCorrelationResultName].Value).Value = value;225 }226 }227 228 public double PrognosisTrainingRelativeError {229 get {230 if (!ContainsKey(PrognosisTrainingRelativeErrorResultName)) return double.NaN;231 return ((DoubleValue)this[PrognosisTrainingRelativeErrorResultName].Value).Value;232 }233 private set {234 if (!ContainsKey(PrognosisTrainingRelativeErrorResultName)) Add(new Result(PrognosisTrainingRelativeErrorResultName, PrognosisTrainingRelativeErrorResultDescription, new DoubleValue()));235 ((DoubleValue)this[PrognosisTrainingRelativeErrorResultName].Value).Value = value;236 }237 }238 239 public double PrognosisTestRelativeError {240 get {241 if (!ContainsKey(PrognosisTestRelativeErrorResultName)) return double.NaN;242 return ((DoubleValue)this[PrognosisTestRelativeErrorResultName].Value).Value;243 }244 private set {245 if (!ContainsKey(PrognosisTestRelativeErrorResultName)) Add(new Result(PrognosisTestRelativeErrorResultName, PrognosisTestRelativeErrorResultDescription, new DoubleValue()));246 ((DoubleValue)this[PrognosisTestRelativeErrorResultName].Value).Value = value;247 }248 }249 250 public double PrognosisTrainingNormalizedMeanSquaredError {251 get {252 if (!ContainsKey(PrognosisTrainingNormalizedMeanSquaredErrorResultName)) return double.NaN;253 return ((DoubleValue)this[PrognosisTrainingNormalizedMeanSquaredErrorResultName].Value).Value;254 }255 private set {256 if (!ContainsKey(PrognosisTrainingNormalizedMeanSquaredErrorResultName)) Add(new Result(PrognosisTrainingNormalizedMeanSquaredErrorResultName, PrognosisTrainingNormalizedMeanSquaredErrorResultDescription, new DoubleValue()));257 ((DoubleValue)this[PrognosisTrainingNormalizedMeanSquaredErrorResultName].Value).Value = value;258 }259 }260 261 public double PrognosisTestNormalizedMeanSquaredError {262 get {263 if (!ContainsKey(PrognosisTestNormalizedMeanSquaredErrorResultName)) return double.NaN;264 return ((DoubleValue)this[PrognosisTestNormalizedMeanSquaredErrorResultName].Value).Value;265 }266 private set {267 if (!ContainsKey(PrognosisTestNormalizedMeanSquaredErrorResultName)) Add(new Result(PrognosisTestNormalizedMeanSquaredErrorResultName, PrognosisTestNormalizedMeanSquaredErrorResultDescription, new DoubleValue()));268 ((DoubleValue)this[PrognosisTestNormalizedMeanSquaredErrorResultName].Value).Value = value;269 }270 }271 272 public double PrognosisTrainingMeanError {273 get {274 if (!ContainsKey(PrognosisTrainingMeanErrorResultName)) return double.NaN;275 return ((DoubleValue)this[PrognosisTrainingMeanErrorResultName].Value).Value;276 }277 private set {278 if (!ContainsKey(PrognosisTrainingMeanErrorResultName)) Add(new Result(PrognosisTrainingMeanErrorResultName, PrognosisTrainingMeanErrorResultDescription, new DoubleValue()));279 ((DoubleValue)this[PrognosisTrainingMeanErrorResultName].Value).Value = value;280 }281 }282 283 public double PrognosisTestMeanError {284 get {285 if (!ContainsKey(PrognosisTestMeanErrorResultName)) return double.NaN;286 return ((DoubleValue)this[PrognosisTestMeanErrorResultName].Value).Value;287 }288 private set {289 if (!ContainsKey(PrognosisTestMeanErrorResultName)) Add(new Result(PrognosisTestMeanErrorResultName, PrognosisTestMeanErrorResultDescription, new DoubleValue()));290 ((DoubleValue)this[PrognosisTestMeanErrorResultName].Value).Value = value;291 }292 }293 294 295 public double PrognosisTrainingDirectionalSymmetry {296 get {297 if (!ContainsKey(PrognosisTrainingDirectionalSymmetryResultName)) return double.NaN;298 return ((DoubleValue)this[PrognosisTrainingDirectionalSymmetryResultName].Value).Value;299 }300 private set {301 if (!ContainsKey(PrognosisTrainingDirectionalSymmetryResultName)) Add(new Result(PrognosisTrainingDirectionalSymmetryResultName, PrognosisTrainingDirectionalSymmetryResultDescription, new DoubleValue()));302 ((DoubleValue)this[PrognosisTrainingDirectionalSymmetryResultName].Value).Value = value;303 }304 }305 public double PrognosisTestDirectionalSymmetry {306 get {307 if (!ContainsKey(PrognosisTestDirectionalSymmetryResultName)) return double.NaN;308 return ((DoubleValue)this[PrognosisTestDirectionalSymmetryResultName].Value).Value;309 }310 private set {311 if (!ContainsKey(PrognosisTestDirectionalSymmetryResultName)) Add(new Result(PrognosisTestDirectionalSymmetryResultName, PrognosisTestDirectionalSymmetryResultDescription, new DoubleValue()));312 ((DoubleValue)this[PrognosisTestDirectionalSymmetryResultName].Value).Value = value;313 }314 }315 public double PrognosisTrainingWeightedDirectionalSymmetry {316 get {317 if (!ContainsKey(PrognosisTrainingWeightedDirectionalSymmetryResultName)) return double.NaN;318 return ((DoubleValue)this[PrognosisTrainingWeightedDirectionalSymmetryResultName].Value).Value;319 }320 private set {321 if (!ContainsKey(PrognosisTrainingWeightedDirectionalSymmetryResultName)) Add(new Result(PrognosisTrainingWeightedDirectionalSymmetryResultName, PrognosisTrainingWeightedDirectionalSymmetryResultDescription, new DoubleValue()));322 ((DoubleValue)this[PrognosisTrainingWeightedDirectionalSymmetryResultName].Value).Value = value;323 }324 }325 public double PrognosisTestWeightedDirectionalSymmetry {326 get {327 if (!ContainsKey(PrognosisTestWeightedDirectionalSymmetryResultName)) return double.NaN;328 return ((DoubleValue)this[PrognosisTestWeightedDirectionalSymmetryResultName].Value).Value;329 }330 private set {331 if (!ContainsKey(PrognosisTestWeightedDirectionalSymmetryResultName)) Add(new Result(PrognosisTestWeightedDirectionalSymmetryResultName, PrognosisTestWeightedDirectionalSymmetryResultDescription, new DoubleValue()));332 ((DoubleValue)this[PrognosisTestWeightedDirectionalSymmetryResultName].Value).Value = value;333 }334 }335 public double PrognosisTrainingTheilsUStatisticAR1 {336 get {337 if (!ContainsKey(PrognosisTrainingTheilsUStatisticAR1ResultName)) return double.NaN;338 return ((DoubleValue)this[PrognosisTrainingTheilsUStatisticAR1ResultName].Value).Value;339 }340 private set {341 if (!ContainsKey(PrognosisTrainingTheilsUStatisticAR1ResultName)) Add(new Result(PrognosisTrainingTheilsUStatisticAR1ResultName, PrognosisTrainingTheilsUStatisticAR1ResultDescription, new DoubleValue()));342 ((DoubleValue)this[PrognosisTrainingTheilsUStatisticAR1ResultName].Value).Value = value;343 }344 }345 public double PrognosisTestTheilsUStatisticAR1 {346 get {347 if (!ContainsKey(PrognosisTestTheilsUStatisticAR1ResultName)) return double.NaN;348 return ((DoubleValue)this[PrognosisTestTheilsUStatisticAR1ResultName].Value).Value;349 }350 private set {351 if (!ContainsKey(PrognosisTestTheilsUStatisticAR1ResultName)) Add(new Result(PrognosisTestTheilsUStatisticAR1ResultName, PrognosisTestTheilsUStatisticAR1ResultDescription, new DoubleValue()));352 ((DoubleValue)this[PrognosisTestTheilsUStatisticAR1ResultName].Value).Value = value;353 }354 }355 public double PrognosisTrainingTheilsUStatisticMean {356 get {357 if (!ContainsKey(PrognosisTrainingTheilsUStatisticMeanResultName)) return double.NaN;358 return ((DoubleValue)this[PrognosisTrainingTheilsUStatisticMeanResultName].Value).Value;359 }360 private set {361 if (!ContainsKey(PrognosisTrainingTheilsUStatisticMeanResultName)) Add(new Result(PrognosisTrainingTheilsUStatisticMeanResultName, PrognosisTrainingTheilsUStatisticMeanResultDescription, new DoubleValue()));362 ((DoubleValue)this[PrognosisTrainingTheilsUStatisticMeanResultName].Value).Value = value;363 }364 }365 public double PrognosisTestTheilsUStatisticMean {366 get {367 if (!ContainsKey(PrognosisTestTheilsUStatisticMeanResultName)) return double.NaN;368 return ((DoubleValue)this[PrognosisTestTheilsUStatisticMeanResultName].Value).Value;369 }370 private set {371 if (!ContainsKey(PrognosisTestTheilsUStatisticMeanResultName)) Add(new Result(PrognosisTestTheilsUStatisticMeanResultName, PrognosisTestTheilsUStatisticMeanResultDescription, new DoubleValue()));372 ((DoubleValue)this[PrognosisTestTheilsUStatisticMeanResultName].Value).Value = value;373 }374 }375 public double PrognosisTrainingTheilsUStatisticMovingAverage {376 get {377 if (!ContainsKey(PrognosisTrainingTheilsUStatisticMovingAverageResultName)) return double.NaN;378 return ((DoubleValue)this[PrognosisTrainingTheilsUStatisticMovingAverageResultName].Value).Value;379 }380 private set {381 if (!ContainsKey(PrognosisTrainingTheilsUStatisticMovingAverageResultName)) Add(new Result(PrognosisTrainingTheilsUStatisticMovingAverageResultName, PrognosisTrainingTheilsUStatisticMovingAverageResultDescription, new DoubleValue()));382 ((DoubleValue)this[PrognosisTrainingTheilsUStatisticMovingAverageResultName].Value).Value = value;383 }384 }385 public double PrognosisTestTheilsUStatisticMovingAverage {386 get {387 if (!ContainsKey(PrognosisTestTheilsUStatisticMovingAverageResultName)) return double.NaN;388 return ((DoubleValue)this[PrognosisTestTheilsUStatisticMovingAverageResultName].Value).Value;389 }390 private set {391 if (!ContainsKey(PrognosisTestTheilsUStatisticMovingAverageResultName)) Add(new Result(PrognosisTestTheilsUStatisticMovingAverageResultName, PrognosisTestTheilsUStatisticMovingAverageResultDescription, new DoubleValue()));392 ((DoubleValue)this[PrognosisTestTheilsUStatisticMovingAverageResultName].Value).Value = value;393 }394 }395 124 #endregion 125 396 126 397 127 public override IEnumerable<double> EstimatedValues { … … 485 215 486 216 protected void CalculateTimeSeriesResults(int trainingHorizon, int testHorizon) { 487 OnlineCalculatorError errorState; 488 //mean model 489 double trainingMean = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average(); 490 var meanModel = new ConstantTimeSeriesPrognosisModel(trainingMean); 491 492 //AR1 model 493 double alpha, beta; 494 IEnumerable<double> trainingStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Select(r => r - 1).Where(r => r > 0)).ToList(); 495 OnlineLinearScalingParameterCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Where(x => x > 0)), trainingStartValues, out alpha, out beta, out errorState); 496 var AR1model = new TimeSeriesPrognosisAutoRegressiveModel(ProblemData.TargetVariable, new double[] { beta }, alpha); 497 498 //MA model 499 const int movingAverageWindowSize = 10; 500 var MovingAverageModel = new TimeSeriesPrognosisMovingAverageModel(movingAverageWindowSize, ProblemData.TargetVariable); 501 502 #region Calculate training quality measures 503 if (trainingHorizon != 1) { 504 var trainingHorizions = ProblemData.TrainingIndices.Select(r => Math.Min(trainingHorizon, ProblemData.TrainingPartition.End - r)).ToList(); 505 IEnumerable<IEnumerable<double>> trainingTargetValues = ProblemData.TrainingIndices.Zip(trainingHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList(); 506 IEnumerable<IEnumerable<double>> trainingEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions).ToList(); 507 IEnumerable<IEnumerable<double>> trainingMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions).ToList(); 508 IEnumerable<IEnumerable<double>> trainingAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions).ToList(); 509 IEnumerable<IEnumerable<double>> trainingMovingAverageModelPredictions = MovingAverageModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions).ToList(); 510 511 IEnumerable<double> originalTrainingValues = trainingTargetValues.SelectMany(x => x).ToList(); 512 IEnumerable<double> estimatedTrainingValues = trainingEstimatedValues.SelectMany(x => x).ToList(); 513 514 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 515 PrognosisTrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMSE : double.NaN; 516 double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 517 PrognosisTrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN; 518 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 519 PrognosisTrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN; 520 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 521 PrognosisTrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN; 522 double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 523 PrognosisTrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNMSE : double.NaN; 524 double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 525 PrognosisTrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN; 526 527 PrognosisTrainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingEstimatedValues, out errorState); 528 PrognosisTrainingDirectionalSymmetry = errorState == OnlineCalculatorError.None ? PrognosisTrainingDirectionalSymmetry : 0.0; 529 PrognosisTrainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingEstimatedValues, out errorState); 530 PrognosisTrainingWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? PrognosisTrainingWeightedDirectionalSymmetry : 0.0; 531 PrognosisTrainingTheilsUStatisticAR1 = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingAR1ModelPredictions, trainingEstimatedValues, out errorState); 532 PrognosisTrainingTheilsUStatisticAR1 = errorState == OnlineCalculatorError.None ? PrognosisTrainingTheilsUStatisticAR1 : double.PositiveInfinity; 533 PrognosisTrainingTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingMeanModelPredictions, trainingEstimatedValues, out errorState); 534 PrognosisTrainingTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? PrognosisTrainingTheilsUStatisticMean : double.PositiveInfinity; 535 PrognosisTrainingTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingMovingAverageModelPredictions, trainingEstimatedValues, out errorState); 536 PrognosisTrainingTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? PrognosisTrainingTheilsUStatisticMovingAverage : double.PositiveInfinity; 537 } 538 539 #endregion 540 541 #region Calculate test quality measures 542 if (testHorizon != 1) { 543 var testHorizions = ProblemData.TestIndices.Select(r => Math.Min(testHorizon, ProblemData.TestPartition.End - r)).ToList(); 544 IEnumerable<IEnumerable<double>> testTargetValues = ProblemData.TestIndices.Zip(testHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList(); 545 IEnumerable<IEnumerable<double>> testEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions).ToList(); 546 IEnumerable<double> testStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices.Select(r => r - 1).Where(r => r > 0)).ToList(); 547 IEnumerable<IEnumerable<double>> testMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions).ToList(); 548 IEnumerable<IEnumerable<double>> testAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions).ToList(); 549 IEnumerable<IEnumerable<double>> testMovingAverageModelPredictions = MovingAverageModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions).ToList(); 550 551 IEnumerable<double> originalTestValues = testTargetValues.SelectMany(x => x).ToList(); 552 IEnumerable<double> estimatedTestValues = testEstimatedValues.SelectMany(x => x).ToList(); 553 554 double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 555 PrognosisTestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 556 double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 557 PrognosisTestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN; 558 double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 559 PrognosisTestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN; 560 double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 561 PrognosisTestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN; 562 double testNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 563 PrognosisTestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN; 564 double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 565 PrognosisTestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN; 566 567 PrognosisTestDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(testStartValues, testTargetValues, testEstimatedValues, out errorState); 568 PrognosisTestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? PrognosisTestDirectionalSymmetry : 0.0; 569 PrognosisTestWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(testStartValues, testTargetValues, testEstimatedValues, out errorState); 570 PrognosisTestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? PrognosisTestWeightedDirectionalSymmetry : 0.0; 571 PrognosisTestTheilsUStatisticAR1 = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testAR1ModelPredictions, testEstimatedValues, out errorState); 572 PrognosisTestTheilsUStatisticAR1 = errorState == OnlineCalculatorError.None ? PrognosisTestTheilsUStatisticAR1 : double.PositiveInfinity; 573 PrognosisTestTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testMeanModelPredictions, testEstimatedValues, out errorState); 574 PrognosisTestTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? PrognosisTestTheilsUStatisticMean : double.PositiveInfinity; 575 PrognosisTestTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testMovingAverageModelPredictions, testEstimatedValues, out errorState); 576 PrognosisTestTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? PrognosisTestTheilsUStatisticMovingAverage : double.PositiveInfinity; 577 } 578 579 #endregion 217 TimeSeriesPrognosisResults = new TimeSeriesPrognosisResults(trainingHorizon, testHorizon, this); 580 218 } 581 219 }
Note: See TracChangeset
for help on using the changeset viewer.