#region License Information
/* HeuristicLab
* Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Data;
using HeuristicLab.Optimization;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Problems.DataAnalysis {
[StorableClass]
public abstract class TimeSeriesPrognosisSolutionBase : RegressionSolutionBase, ITimeSeriesPrognosisSolution {
#region result names
protected const string TrainingDirectionalSymmetryResultName = "Average directional symmetry (training)";
protected const string TestDirectionalSymmetryResultName = "Average directional symmetry (test)";
protected const string TrainingWeightedDirectionalSymmetryResultName = "Average weighted directional symmetry (training)";
protected const string TestWeightedDirectionalSymmetryResultName = "Average weighted directional symmetry (test)";
protected const string TrainingTheilsUStatisticAR1ResultName = "Theil's U2 (AR1) (training)";
protected const string TestTheilsUStatisticLastResultName = "Theil's U2 (AR1) (test)";
protected const string TrainingTheilsUStatisticMeanResultName = "Theil's U2 (mean) (training)";
protected const string TestTheilsUStatisticMeanResultName = "Theil's U2 (mean) (test)";
protected const string TrainingTheilsUStatisticMovingAverageResultName = "Theil's U2 (moving average) (training)";
protected const string TestTheilsUStatisticMovingAverageResultName = "Theil's U2 (moving average) (test)";
protected const string PrognosisTrainingMeanSquaredErrorResultName = "Prognosis " + TrainingMeanSquaredErrorResultName;
protected const string PrognosisTestMeanSquaredErrorResultName = "Prognosis " + TestMeanSquaredErrorResultName;
protected const string PrognosisTrainingMeanAbsoluteErrorResultName = "Prognosis " + TrainingMeanAbsoluteErrorResultName;
protected const string PrognosisTestMeanAbsoluteErrorResultName = "Prognosis " + TestMeanAbsoluteErrorResultName;
protected const string PrognosisTrainingSquaredCorrelationResultName = "Prognosis " + TrainingSquaredCorrelationResultName;
protected const string PrognosisTestSquaredCorrelationResultName = "Prognosis " + TestSquaredCorrelationResultName;
protected const string PrognosisTrainingRelativeErrorResultName = "Prognosis " + TrainingRelativeErrorResultName;
protected const string PrognosisTestRelativeErrorResultName = "Prognosis " + TestRelativeErrorResultName;
protected const string PrognosisTrainingNormalizedMeanSquaredErrorResultName = "Prognosis " + TrainingNormalizedMeanSquaredErrorResultName;
protected const string PrognosisTestNormalizedMeanSquaredErrorResultName = "Prognosis " + TestNormalizedMeanSquaredErrorResultName;
protected const string PrognosisTrainingMeanErrorResultName = "Prognosis " + TrainingMeanErrorResultName;
protected const string PrognosisTestMeanErrorResultName = "Prognosis " + TestMeanErrorResultName;
protected const string PrognosisTrainingDirectionalSymmetryResultName = "Prognosis " + TrainingDirectionalSymmetryResultName;
protected const string PrognosisTestDirectionalSymmetryResultName = "Prognosis " + TestDirectionalSymmetryResultName;
protected const string PrognosisTrainingWeightedDirectionalSymmetryResultName = "Prognosis " + TrainingWeightedDirectionalSymmetryResultName;
protected const string PrognosisTestWeightedDirectionalSymmetryResultName = "Prognosis " + TestWeightedDirectionalSymmetryResultName;
protected const string PrognosisTrainingTheilsUStatisticAR1ResultName = "Prognosis " + TrainingTheilsUStatisticAR1ResultName;
protected const string PrognosisTestTheilsUStatisticAR1ResultName = "Prognosis " + TestTheilsUStatisticLastResultName;
protected const string PrognosisTrainingTheilsUStatisticMeanResultName = "Prognosis " + TrainingTheilsUStatisticMeanResultName;
protected const string PrognosisTestTheilsUStatisticMeanResultName = "Prognosis " + TestTheilsUStatisticMeanResultName;
protected const string PrognosisTrainingTheilsUStatisticMovingAverageResultName = "Prognosis " + TrainingTheilsUStatisticMovingAverageResultName;
protected const string PrognosisTestTheilsUStatisticMovingAverageResultName = "Prognosis " + TestTheilsUStatisticMovingAverageResultName;
#endregion
#region result descriptions
protected const string TrainingDirectionalSymmetryResultDescription = "The average directional symmetry of the forecasts of the model on the training partition";
protected const string TestDirectionalSymmetryResultDescription = "The average directional symmetry of the forecasts of the model on the test partition";
protected const string TrainingWeightedDirectionalSymmetryResultDescription = "The average weighted directional symmetry of the forecasts of the model on the training partition";
protected const string TestWeightedDirectionalSymmetryResultDescription = "The average weighted directional symmetry of the forecasts of the model on the test partition";
protected const string TrainingTheilsUStatisticAR1ResultDescription = "The Theil's U statistic (reference: AR1 model) of the forecasts of the model on the training partition";
protected const string TestTheilsUStatisticAR1ResultDescription = "The Theil's U statistic (reference: AR1 model) of the forecasts of the model on the test partition";
protected const string TrainingTheilsUStatisticMeanResultDescription = "The Theil's U statistic (reference: mean model) of the forecasts of the model on the training partition";
protected const string TestTheilsUStatisticMeanResultDescription = "The Theil's U statistic (reference: mean value) of the forecasts of the model on the test partition";
protected const string TrainingTheilsUStatisticMovingAverageResultDescription = "The Theil's U statistic (reference: moving average model) of the forecasts of the model on the training partition";
protected const string TestTheilsUStatisticMovingAverageResultDescription = "The Theil's U statistic (reference: moving average model) of the forecasts of the model on the test partition";
protected const string PrognosisTrainingMeanSquaredErrorResultDescription = TrainingMeanSquaredErrorResultDescription;
protected const string PrognosisTestMeanSquaredErrorResultDescription = TestMeanSquaredErrorResultDescription;
protected const string PrognosisTrainingMeanAbsoluteErrorResultDescription = TrainingMeanAbsoluteErrorResultDescription;
protected const string PrognosisTestMeanAbsoluteErrorResultDescription = TestMeanAbsoluteErrorResultDescription;
protected const string PrognosisTrainingSquaredCorrelationResultDescription = TrainingSquaredCorrelationResultDescription;
protected const string PrognosisTestSquaredCorrelationResultDescription = TestSquaredCorrelationResultDescription;
protected const string PrognosisTrainingRelativeErrorResultDescription = TrainingRelativeErrorResultDescription;
protected const string PrognosisTestRelativeErrorResultDescription = TestRelativeErrorResultDescription;
protected const string PrognosisTrainingNormalizedMeanSquaredErrorResultDescription = TrainingNormalizedMeanSquaredErrorResultDescription;
protected const string PrognosisTestNormalizedMeanSquaredErrorResultDescription = TestNormalizedMeanSquaredErrorResultDescription;
protected const string PrognosisTrainingMeanErrorResultDescription = TrainingMeanErrorResultDescription;
protected const string PrognosisTestMeanErrorResultDescription = TestMeanErrorResultDescription;
protected const string PrognosisTrainingDirectionalSymmetryResultDescription = TrainingDirectionalSymmetryResultDescription;
protected const string PrognosisTestDirectionalSymmetryResultDescription = TestDirectionalSymmetryResultDescription;
protected const string PrognosisTrainingWeightedDirectionalSymmetryResultDescription = TrainingWeightedDirectionalSymmetryResultDescription;
protected const string PrognosisTestWeightedDirectionalSymmetryResultDescription = TestWeightedDirectionalSymmetryResultDescription;
protected const string PrognosisTrainingTheilsUStatisticAR1ResultDescription = TrainingTheilsUStatisticAR1ResultDescription;
protected const string PrognosisTestTheilsUStatisticAR1ResultDescription = TestTheilsUStatisticAR1ResultDescription;
protected const string PrognosisTrainingTheilsUStatisticMeanResultDescription = TrainingTheilsUStatisticMeanResultDescription;
protected const string PrognosisTestTheilsUStatisticMeanResultDescription = TestTheilsUStatisticMeanResultDescription;
protected const string PrognosisTrainingTheilsUStatisticMovingAverageResultDescription = TrainingTheilsUStatisticMovingAverageResultDescription;
protected const string PrognosisTestTheilsUStatisticMovingAverageResultDescription = TestTheilsUStatisticMovingAverageResultDescription;
#endregion
public new ITimeSeriesPrognosisModel Model {
get { return (ITimeSeriesPrognosisModel)base.Model; }
protected set { base.Model = value; }
}
public new ITimeSeriesPrognosisProblemData ProblemData {
get { return (ITimeSeriesPrognosisProblemData)base.ProblemData; }
set { base.ProblemData = value; }
}
public abstract IEnumerable> GetPrognosedValues(IEnumerable rows, IEnumerable horizon);
#region Results
public double TrainingDirectionalSymmetry {
get { return ((DoubleValue)this[TrainingDirectionalSymmetryResultName].Value).Value; }
private set { ((DoubleValue)this[TrainingDirectionalSymmetryResultName].Value).Value = value; }
}
public double TestDirectionalSymmetry {
get { return ((DoubleValue)this[TestDirectionalSymmetryResultName].Value).Value; }
private set { ((DoubleValue)this[TestDirectionalSymmetryResultName].Value).Value = value; }
}
public double TrainingWeightedDirectionalSymmetry {
get { return ((DoubleValue)this[TrainingWeightedDirectionalSymmetryResultName].Value).Value; }
private set { ((DoubleValue)this[TrainingWeightedDirectionalSymmetryResultName].Value).Value = value; }
}
public double TestWeightedDirectionalSymmetry {
get { return ((DoubleValue)this[TestWeightedDirectionalSymmetryResultName].Value).Value; }
private set { ((DoubleValue)this[TestWeightedDirectionalSymmetryResultName].Value).Value = value; }
}
public double TrainingTheilsUStatisticAR1 {
get { return ((DoubleValue)this[TrainingTheilsUStatisticAR1ResultName].Value).Value; }
private set { ((DoubleValue)this[TrainingTheilsUStatisticAR1ResultName].Value).Value = value; }
}
public double TestTheilsUStatisticAR1 {
get { return ((DoubleValue)this[TestTheilsUStatisticLastResultName].Value).Value; }
private set { ((DoubleValue)this[TestTheilsUStatisticLastResultName].Value).Value = value; }
}
public double TrainingTheilsUStatisticMean {
get { return ((DoubleValue)this[TrainingTheilsUStatisticMeanResultName].Value).Value; }
private set { ((DoubleValue)this[TrainingTheilsUStatisticMeanResultName].Value).Value = value; }
}
public double TestTheilsUStatisticMean {
get { return ((DoubleValue)this[TestTheilsUStatisticMeanResultName].Value).Value; }
private set { ((DoubleValue)this[TestTheilsUStatisticMeanResultName].Value).Value = value; }
}
public double TrainingTheilsUStatisticMovingAverage {
get { return ((DoubleValue)this[TrainingTheilsUStatisticMovingAverageResultName].Value).Value; }
private set { ((DoubleValue)this[TrainingTheilsUStatisticMovingAverageResultName].Value).Value = value; }
}
public double TestTheilsUStatisticMovingAverage {
get { return ((DoubleValue)this[TestTheilsUStatisticMovingAverageResultName].Value).Value; }
private set { ((DoubleValue)this[TestTheilsUStatisticMovingAverageResultName].Value).Value = value; }
}
//prognosis results for different horizons
public double PrognosisTrainingMeanSquaredError {
get {
if (!ContainsKey(PrognosisTrainingMeanSquaredErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingMeanSquaredErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingMeanSquaredErrorResultName)) Add(new Result(PrognosisTrainingMeanSquaredErrorResultName, PrognosisTrainingMeanSquaredErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingMeanSquaredErrorResultName].Value).Value = value;
}
}
public double PrognosisTestMeanSquaredError {
get {
if (!ContainsKey(PrognosisTestMeanSquaredErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestMeanSquaredErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestMeanSquaredErrorResultName)) Add(new Result(PrognosisTestMeanSquaredErrorResultName, PrognosisTestMeanSquaredErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestMeanSquaredErrorResultName].Value).Value = value;
}
}
public double PrognosisTrainingMeanAbsoluteError {
get {
if (!ContainsKey(PrognosisTrainingMeanAbsoluteErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingMeanAbsoluteErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingMeanAbsoluteErrorResultName)) Add(new Result(PrognosisTrainingMeanAbsoluteErrorResultName, PrognosisTrainingMeanAbsoluteErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingMeanAbsoluteErrorResultName].Value).Value = value;
}
}
public double PrognosisTestMeanAbsoluteError {
get {
if (!ContainsKey(PrognosisTestMeanAbsoluteErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestMeanAbsoluteErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestMeanAbsoluteErrorResultName)) Add(new Result(PrognosisTestMeanAbsoluteErrorResultName, PrognosisTestMeanAbsoluteErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestMeanAbsoluteErrorResultName].Value).Value = value;
}
}
public double PrognosisTrainingRSquared {
get {
if (!ContainsKey(PrognosisTrainingSquaredCorrelationResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingSquaredCorrelationResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingSquaredCorrelationResultName)) Add(new Result(PrognosisTrainingSquaredCorrelationResultName, PrognosisTrainingSquaredCorrelationResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingSquaredCorrelationResultName].Value).Value = value;
}
}
public double PrognosisTestRSquared {
get {
if (!ContainsKey(PrognosisTestSquaredCorrelationResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestSquaredCorrelationResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestSquaredCorrelationResultName)) Add(new Result(PrognosisTestSquaredCorrelationResultName, PrognosisTestSquaredCorrelationResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestSquaredCorrelationResultName].Value).Value = value;
}
}
public double PrognosisTrainingRelativeError {
get {
if (!ContainsKey(PrognosisTrainingRelativeErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingRelativeErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingRelativeErrorResultName)) Add(new Result(PrognosisTrainingRelativeErrorResultName, PrognosisTrainingRelativeErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingRelativeErrorResultName].Value).Value = value;
}
}
public double PrognosisTestRelativeError {
get {
if (!ContainsKey(PrognosisTestRelativeErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestRelativeErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestRelativeErrorResultName)) Add(new Result(PrognosisTestRelativeErrorResultName, PrognosisTestRelativeErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestRelativeErrorResultName].Value).Value = value;
}
}
public double PrognosisTrainingNormalizedMeanSquaredError {
get {
if (!ContainsKey(PrognosisTrainingNormalizedMeanSquaredErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingNormalizedMeanSquaredErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingNormalizedMeanSquaredErrorResultName)) Add(new Result(PrognosisTrainingNormalizedMeanSquaredErrorResultName, PrognosisTrainingNormalizedMeanSquaredErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingNormalizedMeanSquaredErrorResultName].Value).Value = value;
}
}
public double PrognosisTestNormalizedMeanSquaredError {
get {
if (!ContainsKey(PrognosisTestNormalizedMeanSquaredErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestNormalizedMeanSquaredErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestNormalizedMeanSquaredErrorResultName)) Add(new Result(PrognosisTestNormalizedMeanSquaredErrorResultName, PrognosisTestNormalizedMeanSquaredErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestNormalizedMeanSquaredErrorResultName].Value).Value = value;
}
}
public double PrognosisTrainingMeanError {
get {
if (!ContainsKey(PrognosisTrainingMeanErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingMeanErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingMeanErrorResultName)) Add(new Result(PrognosisTrainingMeanErrorResultName, PrognosisTrainingMeanErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingMeanErrorResultName].Value).Value = value;
}
}
public double PrognosisTestMeanError {
get {
if (!ContainsKey(PrognosisTestMeanErrorResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestMeanErrorResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestMeanErrorResultName)) Add(new Result(PrognosisTestMeanErrorResultName, PrognosisTestMeanErrorResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestMeanErrorResultName].Value).Value = value;
}
}
public double PrognosisTrainingDirectionalSymmetry {
get {
if (!ContainsKey(PrognosisTrainingDirectionalSymmetryResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingDirectionalSymmetryResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingDirectionalSymmetryResultName)) Add(new Result(PrognosisTrainingDirectionalSymmetryResultName, PrognosisTrainingDirectionalSymmetryResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingDirectionalSymmetryResultName].Value).Value = value;
}
}
public double PrognosisTestDirectionalSymmetry {
get {
if (!ContainsKey(PrognosisTestDirectionalSymmetryResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestDirectionalSymmetryResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestDirectionalSymmetryResultName)) Add(new Result(PrognosisTestDirectionalSymmetryResultName, PrognosisTestDirectionalSymmetryResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestDirectionalSymmetryResultName].Value).Value = value;
}
}
public double PrognosisTrainingWeightedDirectionalSymmetry {
get {
if (!ContainsKey(PrognosisTrainingWeightedDirectionalSymmetryResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingWeightedDirectionalSymmetryResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingWeightedDirectionalSymmetryResultName)) Add(new Result(PrognosisTrainingWeightedDirectionalSymmetryResultName, PrognosisTrainingWeightedDirectionalSymmetryResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingWeightedDirectionalSymmetryResultName].Value).Value = value;
}
}
public double PrognosisTestWeightedDirectionalSymmetry {
get {
if (!ContainsKey(PrognosisTestWeightedDirectionalSymmetryResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestWeightedDirectionalSymmetryResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestWeightedDirectionalSymmetryResultName)) Add(new Result(PrognosisTestWeightedDirectionalSymmetryResultName, PrognosisTestWeightedDirectionalSymmetryResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestWeightedDirectionalSymmetryResultName].Value).Value = value;
}
}
public double PrognosisTrainingTheilsUStatisticAR1 {
get {
if (!ContainsKey(PrognosisTrainingTheilsUStatisticAR1ResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingTheilsUStatisticAR1ResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingTheilsUStatisticAR1ResultName)) Add(new Result(PrognosisTrainingTheilsUStatisticAR1ResultName, PrognosisTrainingTheilsUStatisticAR1ResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingTheilsUStatisticAR1ResultName].Value).Value = value;
}
}
public double PrognosisTestTheilsUStatisticAR1 {
get {
if (!ContainsKey(PrognosisTestTheilsUStatisticAR1ResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestTheilsUStatisticAR1ResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestTheilsUStatisticAR1ResultName)) Add(new Result(PrognosisTestTheilsUStatisticAR1ResultName, PrognosisTestTheilsUStatisticAR1ResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestTheilsUStatisticAR1ResultName].Value).Value = value;
}
}
public double PrognosisTrainingTheilsUStatisticMean {
get {
if (!ContainsKey(PrognosisTrainingTheilsUStatisticMeanResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingTheilsUStatisticMeanResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingTheilsUStatisticMeanResultName)) Add(new Result(PrognosisTrainingTheilsUStatisticMeanResultName, PrognosisTrainingTheilsUStatisticMeanResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingTheilsUStatisticMeanResultName].Value).Value = value;
}
}
public double PrognosisTestTheilsUStatisticMean {
get {
if (!ContainsKey(PrognosisTestTheilsUStatisticMeanResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestTheilsUStatisticMeanResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestTheilsUStatisticMeanResultName)) Add(new Result(PrognosisTestTheilsUStatisticMeanResultName, PrognosisTestTheilsUStatisticMeanResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestTheilsUStatisticMeanResultName].Value).Value = value;
}
}
public double PrognosisTrainingTheilsUStatisticMovingAverage {
get {
if (!ContainsKey(PrognosisTrainingTheilsUStatisticMovingAverageResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTrainingTheilsUStatisticMovingAverageResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTrainingTheilsUStatisticMovingAverageResultName)) Add(new Result(PrognosisTrainingTheilsUStatisticMovingAverageResultName, PrognosisTrainingTheilsUStatisticMovingAverageResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTrainingTheilsUStatisticMovingAverageResultName].Value).Value = value;
}
}
public double PrognosisTestTheilsUStatisticMovingAverage {
get {
if (!ContainsKey(PrognosisTestTheilsUStatisticMovingAverageResultName)) return double.NaN;
return ((DoubleValue)this[PrognosisTestTheilsUStatisticMovingAverageResultName].Value).Value;
}
private set {
if (!ContainsKey(PrognosisTestTheilsUStatisticMovingAverageResultName)) Add(new Result(PrognosisTestTheilsUStatisticMovingAverageResultName, PrognosisTestTheilsUStatisticMovingAverageResultDescription, new DoubleValue()));
((DoubleValue)this[PrognosisTestTheilsUStatisticMovingAverageResultName].Value).Value = value;
}
}
#endregion
public override IEnumerable EstimatedValues {
get { return GetEstimatedValues(Enumerable.Range(0, ProblemData.Dataset.Rows)); }
}
public override IEnumerable EstimatedTrainingValues {
get { return GetEstimatedValues(ProblemData.TrainingIndices); }
}
public override IEnumerable EstimatedTestValues {
get { return GetEstimatedValues(ProblemData.TestIndices); }
}
public override IEnumerable GetEstimatedValues(IEnumerable rows) {
return Model.GetEstimatedValues(ProblemData.Dataset, rows);
}
[StorableConstructor]
protected TimeSeriesPrognosisSolutionBase(bool deserializing) : base(deserializing) { }
protected TimeSeriesPrognosisSolutionBase(TimeSeriesPrognosisSolutionBase original, Cloner cloner) : base(original, cloner) { }
protected TimeSeriesPrognosisSolutionBase(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData)
: base(model, problemData) {
Add(new Result(TrainingDirectionalSymmetryResultName, TrainingDirectionalSymmetryResultDescription, new DoubleValue()));
Add(new Result(TestDirectionalSymmetryResultName, TestDirectionalSymmetryResultDescription, new DoubleValue()));
Add(new Result(TrainingWeightedDirectionalSymmetryResultName, TrainingWeightedDirectionalSymmetryResultDescription, new DoubleValue()));
Add(new Result(TestWeightedDirectionalSymmetryResultName, TestWeightedDirectionalSymmetryResultDescription, new DoubleValue()));
Add(new Result(TrainingTheilsUStatisticAR1ResultName, TrainingTheilsUStatisticAR1ResultDescription, new DoubleValue()));
Add(new Result(TestTheilsUStatisticLastResultName, TestTheilsUStatisticAR1ResultDescription, new DoubleValue()));
Add(new Result(TrainingTheilsUStatisticMeanResultName, TrainingTheilsUStatisticMeanResultDescription, new DoubleValue()));
Add(new Result(TestTheilsUStatisticMeanResultName, TestTheilsUStatisticMeanResultDescription, new DoubleValue()));
Add(new Result(TrainingTheilsUStatisticMovingAverageResultName, TrainingTheilsUStatisticMovingAverageResultDescription, new DoubleValue()));
Add(new Result(TestTheilsUStatisticMovingAverageResultName, TestTheilsUStatisticMovingAverageResultDescription, new DoubleValue()));
}
protected override void RecalculateResults() {
base.RecalculateResults();
CalculateTimeSeriesResults();
CalculateTimeSeriesResults(ProblemData.TrainingHorizon, ProblemData.TestHorizon);
}
private void CalculateTimeSeriesResults() {
OnlineCalculatorError errorState;
double trainingMean = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average();
var meanModel = new ConstantTimeSeriesPrognosisModel(trainingMean);
double alpha, beta;
IEnumerable trainingStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Select(r => r - 1).Where(r => r > 0)).ToList();
OnlineLinearScalingParameterCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Where(x => x > 0)), trainingStartValues, out alpha, out beta, out errorState);
var AR1model = new TimeSeriesPrognosisAutoRegressiveModel(ProblemData.TargetVariable, new double[] { beta }, alpha);
//MA model
const int movingAverageWindowSize = 10;
var movingAverageModel = new TimeSeriesPrognosisMovingAverageModel(movingAverageWindowSize, ProblemData.TargetVariable);
#region Calculate training quality measures
IEnumerable trainingTargetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToList();
IEnumerable trainingEstimatedValues = EstimatedTrainingValues.ToList();
IEnumerable trainingMeanModelPredictions = meanModel.GetEstimatedValues(ProblemData.Dataset, ProblemData.TrainingIndices).ToList();
IEnumerable trainingAR1ModelPredictions = AR1model.GetEstimatedValues(ProblemData.Dataset, ProblemData.TrainingIndices).ToList();
IEnumerable trainingMovingAverageModelPredictions = movingAverageModel.GetEstimatedValues(ProblemData.Dataset, ProblemData.TrainingIndices).ToList();
TrainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(trainingTargetValues.First(), trainingTargetValues, trainingEstimatedValues, out errorState);
TrainingDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TrainingDirectionalSymmetry : 0.0;
TrainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(trainingTargetValues.First(), trainingTargetValues, trainingEstimatedValues, out errorState);
TrainingWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TrainingWeightedDirectionalSymmetry : 0.0;
TrainingTheilsUStatisticAR1 = OnlineTheilsUStatisticCalculator.Calculate(trainingTargetValues.First(), trainingTargetValues, trainingAR1ModelPredictions, trainingEstimatedValues, out errorState);
TrainingTheilsUStatisticAR1 = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticAR1 : double.PositiveInfinity;
TrainingTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(trainingTargetValues.First(), trainingTargetValues, trainingMeanModelPredictions, trainingEstimatedValues, out errorState);
TrainingTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticMean : double.PositiveInfinity;
TrainingTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(trainingTargetValues.First(), trainingTargetValues, trainingMovingAverageModelPredictions, trainingEstimatedValues, out errorState);
TrainingTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticMovingAverage : double.PositiveInfinity;
#endregion
#region Calculate test quality measures
IEnumerable testTargetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices).ToList();
IEnumerable testEstimatedValues = EstimatedTestValues.ToList();
IEnumerable testMeanModelPredictions = meanModel.GetEstimatedValues(ProblemData.Dataset, ProblemData.TestIndices).ToList();
IEnumerable testAR1ModelPredictions = AR1model.GetEstimatedValues(ProblemData.Dataset, ProblemData.TestIndices).ToList();
IEnumerable testMovingAverageModelPredictions = movingAverageModel.GetEstimatedValues(ProblemData.Dataset, ProblemData.TestIndices).ToList();
TestDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(testTargetValues.First(), testTargetValues, testEstimatedValues, out errorState);
TestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TestDirectionalSymmetry : 0.0;
TestWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(testTargetValues.First(), testTargetValues, testEstimatedValues, out errorState);
TestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TestWeightedDirectionalSymmetry : 0.0;
TestTheilsUStatisticAR1 = OnlineTheilsUStatisticCalculator.Calculate(testTargetValues.First(), testTargetValues, testAR1ModelPredictions, testEstimatedValues, out errorState);
TestTheilsUStatisticAR1 = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticAR1 : double.PositiveInfinity;
TestTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(testTargetValues.First(), testTargetValues, testMeanModelPredictions, testEstimatedValues, out errorState);
TestTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticMean : double.PositiveInfinity;
TestTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(testTargetValues.First(), testTargetValues, testMovingAverageModelPredictions, testEstimatedValues, out errorState);
TestTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticMovingAverage : double.PositiveInfinity;
#endregion
}
private void CalculateTimeSeriesResults(int trainingHorizon, int testHorizon) {
OnlineCalculatorError errorState;
//mean model
double trainingMean = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average();
var meanModel = new ConstantTimeSeriesPrognosisModel(trainingMean);
//AR1 model
double alpha, beta;
IEnumerable trainingStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Select(r => r - 1).Where(r => r > 0)).ToList();
OnlineLinearScalingParameterCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Where(x => x > 0)), trainingStartValues, out alpha, out beta, out errorState);
var AR1model = new TimeSeriesPrognosisAutoRegressiveModel(ProblemData.TargetVariable, new double[] { beta }, alpha);
//MA model
const int movingAverageWindowSize = 10;
var MovingAverageModel = new TimeSeriesPrognosisMovingAverageModel(movingAverageWindowSize, ProblemData.TargetVariable);
#region Calculate training quality measures
if (trainingHorizon != 1) {
var trainingHorizions = ProblemData.TrainingIndices.Select(r => Math.Min(trainingHorizon, ProblemData.TrainingPartition.End - r)).ToList();
IEnumerable> trainingTargetValues = ProblemData.TrainingIndices.Zip(trainingHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList();
IEnumerable> trainingEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions).ToList();
IEnumerable> trainingMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions).ToList();
IEnumerable> trainingAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions).ToList();
IEnumerable> trainingMovingAverageModelPredictions = MovingAverageModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions).ToList();
IEnumerable originalTrainingValues = trainingTargetValues.SelectMany(x => x).ToList();
IEnumerable estimatedTrainingValues = trainingEstimatedValues.SelectMany(x => x).ToList();
double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
PrognosisTrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMSE : double.NaN;
double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
PrognosisTrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN;
double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
PrognosisTrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
PrognosisTrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN;
double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
PrognosisTrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNMSE : double.NaN;
double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
PrognosisTrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN;
PrognosisTrainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingEstimatedValues, out errorState);
PrognosisTrainingDirectionalSymmetry = errorState == OnlineCalculatorError.None ? PrognosisTrainingDirectionalSymmetry : 0.0;
PrognosisTrainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingEstimatedValues, out errorState);
PrognosisTrainingWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? PrognosisTrainingWeightedDirectionalSymmetry : 0.0;
PrognosisTrainingTheilsUStatisticAR1 = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingAR1ModelPredictions, trainingEstimatedValues, out errorState);
PrognosisTrainingTheilsUStatisticAR1 = errorState == OnlineCalculatorError.None ? PrognosisTrainingTheilsUStatisticAR1 : double.PositiveInfinity;
PrognosisTrainingTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingMeanModelPredictions, trainingEstimatedValues, out errorState);
PrognosisTrainingTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? PrognosisTrainingTheilsUStatisticMean : double.PositiveInfinity;
PrognosisTrainingTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingMovingAverageModelPredictions, trainingEstimatedValues, out errorState);
PrognosisTrainingTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? PrognosisTrainingTheilsUStatisticMovingAverage : double.PositiveInfinity;
}
#endregion
#region Calculate test quality measures
if (testHorizon != 1) {
var testHorizions = ProblemData.TestIndices.Select(r => Math.Min(testHorizon, ProblemData.TestPartition.End - r)).ToList();
IEnumerable> testTargetValues = ProblemData.TestIndices.Zip(testHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList();
IEnumerable> testEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions).ToList();
IEnumerable testStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices.Select(r => r - 1).Where(r => r > 0)).ToList();
IEnumerable> testMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions).ToList();
IEnumerable> testAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions).ToList();
IEnumerable> testMovingAverageModelPredictions = MovingAverageModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions).ToList();
IEnumerable originalTestValues = testTargetValues.SelectMany(x => x).ToList();
IEnumerable estimatedTestValues = testEstimatedValues.SelectMany(x => x).ToList();
double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
PrognosisTestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN;
double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
PrognosisTestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;
double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
PrognosisTestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
PrognosisTestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN;
double testNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
PrognosisTestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN;
double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
PrognosisTestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN;
PrognosisTestDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(testStartValues, testTargetValues, testEstimatedValues, out errorState);
PrognosisTestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? PrognosisTestDirectionalSymmetry : 0.0;
PrognosisTestWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(testStartValues, testTargetValues, testEstimatedValues, out errorState);
PrognosisTestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? PrognosisTestWeightedDirectionalSymmetry : 0.0;
PrognosisTestTheilsUStatisticAR1 = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testAR1ModelPredictions, testEstimatedValues, out errorState);
PrognosisTestTheilsUStatisticAR1 = errorState == OnlineCalculatorError.None ? PrognosisTestTheilsUStatisticAR1 : double.PositiveInfinity;
PrognosisTestTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testMeanModelPredictions, testEstimatedValues, out errorState);
PrognosisTestTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? PrognosisTestTheilsUStatisticMean : double.PositiveInfinity;
PrognosisTestTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testMovingAverageModelPredictions, testEstimatedValues, out errorState);
PrognosisTestTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? PrognosisTestTheilsUStatisticMovingAverage : double.PositiveInfinity;
}
#endregion
}
}
}