Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8010


Ignore:
Timestamp:
06/15/12 13:17:07 (12 years ago)
Author:
mkommend
Message:

#1081: Corrected time series solution results and implemented new models.

Location:
branches/HeuristicLab.TimeSeries
Files:
5 added
15 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/Interfaces/ISymbolicTimeSeriesPrognogisExpressionTreeInterpreter.cs

    r7989 r8010  
    2727    string TargetVariable { get; set; }
    2828    IEnumerable<IEnumerable<double>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows, int horizon);
     29    IEnumerable<IEnumerable<double>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizon);
    2930  }
    3031}
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs

    r7998 r8010  
    5454      double quality = Calculate(interpreter, solution,
    5555        EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
    56         ProblemDataParameter.ActualValue,
    57         rows, HorizonParameter.ActualValue.Value, ApplyLinearScaling);
     56        ProblemDataParameter.ActualValue, rows, EvaluationPartitionParameter.ActualValue,
     57        HorizonParameter.ActualValue.Value, ApplyLinearScaling);
    5858      QualityParameter.ActualValue = new DoubleValue(quality);
    5959
     
    6161    }
    6262
    63     public static double Calculate(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows, int horizon, bool applyLinearScaling) {
    64       int horizion2 = problemData.TrainingPartition.End - problemData.TrainingPartition.Start;
    65       IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows.Take(1).Select(r => Enumerable.Range(r, horizion2)).First());
    66       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows.Take(1), horizion2).SelectMany(x => x);
     63    public static double Calculate(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows, IntRange evaluationPartition, int horizon, bool applyLinearScaling) {
     64      var horizions = rows.Select(r => Math.Min(horizon, evaluationPartition.End - r));
     65      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows.Zip(horizions, Enumerable.Range).SelectMany(r => r));
     66      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows, horizions).SelectMany(x => x);
    6767      IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6868      OnlineCalculatorError errorState;
     
    7171      if (applyLinearScaling) {
    7272        var mseCalculator = new OnlineMeanSquaredErrorCalculator();
    73         CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows);
     73        CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows * horizon);
    7474        errorState = mseCalculator.ErrorState;
    7575        mse = mseCalculator.MeanSquaredError;
     
    7979      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    8080      else return mse;
     81
    8182    }
    8283
     
    8687      EstimationLimitsParameter.ExecutionContext = context;
    8788      HorizonParameter.ExecutionContext = context;
     89      EvaluationPartitionParameter.ExecutionContext = context;
    8890
    89       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, HorizonParameter.ActualValue.Value, ApplyLinearScaling);
     91      double mse = Calculate((ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter)SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, EvaluationPartitionParameter.ActualValue, HorizonParameter.ActualValue.Value, ApplyLinearScaling);
    9092
    9193      HorizonParameter.ExecutionContext = null;
    9294      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    9395      EstimationLimitsParameter.ExecutionContext = null;
     96      EvaluationPartitionParameter.ExecutionContext = null;
    9497
    9598      return mse;
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs

    r7989 r8010  
    8686    }
    8787
    88     public IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, int horizon) {
    89       var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows, horizon);
     88    public IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {
     89      var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows, horizons);
    9090      return estimatedValues.Select(predictionPerRow => predictionPerRow.LimitToRange(lowerEstimationLimit, upperEstimationLimit));
    9191    }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisSolution.cs

    r6802 r8010  
    2525using HeuristicLab.Optimization;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2728
    2829namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis {
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/TimeSeriesPrognosisSolutionView.Designer.cs

    r7183 r8010  
    9999      this.horizonTextBox.Size = new System.Drawing.Size(100, 20);
    100100      this.horizonTextBox.TabIndex = 1;
    101       this.horizonTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.horizonTextBox_KeyDown);
    102101      this.horizonTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.horizonTextBox_Validating);
    103102      this.horizonTextBox.Validated += new System.EventHandler(this.horizonTextBox_Validated);
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/TimeSeriesPrognosisSolutionView.cs

    r7989 r8010  
    6161      int val;
    6262      if (int.TryParse(horizonTextBox.Text, out val)) {
    63         e.Cancel = val <= 0 || val >= Content.ProblemData.TrainingPartition.End - Content.ProblemData.TrainingPartition.Start;
     63        //e.Cancel = val <= 0 || val >= Content.ProblemData.TrainingPartition.End - Content.ProblemData.TrainingPartition.Start;
    6464      } else {
    6565        e.Cancel = true;
     
    7272      Content.Horizon = val;
    7373    }
    74 
    75     private void horizonTextBox_KeyDown(object sender, KeyEventArgs e) {
    76       if (e.KeyCode == Keys.Enter) {
    77         e.Handled = true;
    78         this.Focus();
    79       } else {
    80         e.Handled = false;
    81       }
    82     }
    83 
    8474  }
    8575}
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionLineChartView.cs

    r7998 r8010  
    2525using System.Windows.Forms;
    2626using System.Windows.Forms.DataVisualization.Charting;
     27using HeuristicLab.Common;
    2728using HeuristicLab.MainForm;
    2829using HeuristicLab.MainForm.WindowsForms;
     
    7778          this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Points
    7879            .DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(),
    79                         Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size).SelectMany(x => x).ToArray());
     80                        Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingIndizes.Count().ToEnumerable()).First().ToArray());
    8081        } else {
    8182          this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Points
    8283            .DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(),
    83                         Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes, 1).SelectMany(x => x).ToArray());
     84                        Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes, Enumerable.Repeat(1, Content.ProblemData.TrainingIndizes.Count())).SelectMany(x => x).ToArray());
    8485        }
    8586        this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
     
    9596          this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points
    9697            .DataBindXY(Content.ProblemData.TestIndizes.ToArray(),
    97                         Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestPartition.Size).SelectMany(x => x).ToArray());
     98                        Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestIndizes.Count().ToEnumerable()).First().ToArray());
    9899        } else {
    99100          this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points
    100101            .DataBindXY(Content.ProblemData.TestIndizes.ToArray(),
    101                         Content.GetPrognosedValues(Content.ProblemData.TestIndizes, 1).SelectMany(x => x).ToArray());
     102                       Content.GetPrognosedValues(Content.ProblemData.TestIndizes, Enumerable.Repeat(1, Content.ProblemData.TestIndizes.Count())).SelectMany(x => x).ToArray());
    102103        }
    103104        this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Tag = Content;
     
    220221          case PROGNOSEDVALUES_TRAINING_SERIES_NAME:
    221222            indizes = Content.ProblemData.TrainingIndizes.ToArray();
    222             predictedValues = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size).First();
     223            predictedValues = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size.ToEnumerable()).First();
    223224            break;
    224225          case PROGNOSEDVALUES_TEST_SERIES_NAME:
    225226            testPrognosisStart = Content.ProblemData.TestPartition.Start;
    226227            indizes = Content.ProblemData.TestIndizes.ToArray();
    227             predictedValues = Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestPartition.Size).First();
     228            predictedValues = Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestPartition.Size.ToEnumerable()).First();
    228229            break;
    229230        }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionPrognosedValuesView.cs

    r7998 r8010  
    2323using System.Linq;
    2424using System.Windows.Forms;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Data;
    2627using HeuristicLab.Data.Views;
     
    9495
    9596      string[,] values = new string[Content.ProblemData.Dataset.Rows, 4];
    96       var prognosedTraining = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size).First();
    97       var prognosedTest = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TestPartition.Size).First();
     97      var prognosedTraining = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size.ToEnumerable()).First();
     98      var prognosedTest = Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestPartition.Size.ToEnumerable()).First();
    9899      double[] target = Content.ProblemData.Dataset.GetDoubleValues(targetVariable).ToArray();
    99100
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r7886 r8010  
    140140    </Compile>
    141141    <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" />
     142    <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisConstantModel.cs" />
     143    <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisMovingAverageModel.cs" />
     144    <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisAutoRegressiveModel.cs" />
    142145    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblem.cs" />
    143146    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblemData.cs" />
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolution.cs

    r7989 r8010  
    2929  /// </summary>
    3030  [StorableClass]
    31   public abstract class TimeSeriesPrognosisSolution : TimeSeriesPrognosisSolutionBase {
    32 
     31  public class TimeSeriesPrognosisSolution : TimeSeriesPrognosisSolutionBase {
    3332    [StorableConstructor]
    3433    protected TimeSeriesPrognosisSolution(bool deserializing) : base(deserializing) { }
    3534    protected TimeSeriesPrognosisSolution(TimeSeriesPrognosisSolution original, Cloner cloner) : base(original, cloner) { }
    36     protected TimeSeriesPrognosisSolution(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) : base(model, problemData) { }
     35    protected internal TimeSeriesPrognosisSolution(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) : base(model, problemData) { }
    3736
    3837    protected override void RecalculateResults() {
     
    4039    }
    4140
    42     public override IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, int horizon) {
    43       return Model.GetPrognosedValues(ProblemData.Dataset, rows, horizon);
     41    public override IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizons) {
     42      return Model.GetPrognosedValues(ProblemData.Dataset, rows, horizons);
    4443    }
    4544  }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs

    r7989 r8010  
    7474    }
    7575
    76     public abstract IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, int horizon);
     76    public abstract IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizon);
    7777
    7878    #region Results
     
    192192
    193193    protected void CalculateResults() {
    194       string targetVariable = ProblemData.TargetVariable;
    195 
    196       var trainingMseCalculators = new OnlineMeanSquaredErrorCalculator();
    197       var testMseCalculators = new OnlineMeanSquaredErrorCalculator();
    198       var trainingMaeCalculators = new OnlineMeanAbsoluteErrorCalculator();
    199       var testMaeCalculators = new OnlineMeanAbsoluteErrorCalculator();
    200       var trainingRSquaredCalculators = new OnlinePearsonsRSquaredCalculator();
    201       var testRSquaredCalculators = new OnlinePearsonsRSquaredCalculator();
    202       var trainingRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator();
    203       var testRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator();
    204       var trainingNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator();
    205       var testNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator();
    206 
    207       var trainingDsCalculators = new OnlineDirectionalSymmetryCalculator();
    208       var testDsCalculators = new OnlineDirectionalSymmetryCalculator();
    209       var trainingWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator();
    210       var testWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator();
    211       var trainingTheilsULastCalculators = new OnlineTheilsUStatisticCalculator();
    212       var testTheilsULastCalculators = new OnlineTheilsUStatisticCalculator();
    213       var trainingTheilsUMeanCalculators = new OnlineTheilsUStatisticCalculator();
    214       var testTheilsUMeanCalculators = new OnlineTheilsUStatisticCalculator();
    215       var trainingTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator();
    216       var testTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator();
    217 
    218       double mean = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TrainingIndizes).Average();
    219 
    220       foreach (var row in ProblemData.TrainingIndizes) {
    221         if (row + horizon < ProblemData.Dataset.Rows) {
    222           var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(row, horizon)).ToList();
    223           var prognosedContinuation = GetPrognosedValues(new List<int> { row }, horizon).First().ToList();
    224 
    225           int maWindow = 10 * horizon;
    226           var movingAverageContinuation = from h in Enumerable.Range(0, horizon)
    227                                           select (from r in Enumerable.Range(row + h - maWindow, maWindow - h)
    228                                                   where r > 0
    229                                                   select ProblemData.Dataset.GetDoubleValue(targetVariable, r)
    230                                                  ).Average();
    231 
    232           double startValue = ProblemData.Dataset.GetDoubleValue(targetVariable, row - 1);
    233 
    234           trainingDsCalculators.Add(startValue, actualContinuation, prognosedContinuation);
    235           trainingWdsCalculators.Add(startValue, actualContinuation, prognosedContinuation);
    236           trainingTheilsULastCalculators.Add(startValue, actualContinuation, prognosedContinuation);
    237           trainingTheilsUMeanCalculators.Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation);
    238           trainingTheilsUMovingAverageCalculators.Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
    239 
    240           var actualContinuationEnumerator = actualContinuation.GetEnumerator();
    241           var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator();
    242 
    243           while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
    244             trainingMseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    245             trainingMaeCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    246             trainingRelErrorCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    247             trainingRSquaredCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    248             trainingNmseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    249           }
    250           if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext())
    251             throw new ArgumentException("Different number of elements in Actual continuation and prognosed continuation.");
    252         }
    253       }
    254 
    255       mean = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TestIndizes).Average();
    256       foreach (var row in ProblemData.TestIndizes) {
    257         if (row + horizon < ProblemData.Dataset.Rows) {
    258           var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(row, horizon)).ToList();
    259           var prognosedContinuation = GetPrognosedValues(new List<int> { row }, horizon).First().ToList();
    260 
    261           int maWindow = 10 * horizon;
    262           var movingAverageContinuation = from h in Enumerable.Range(0, horizon)
    263                                           select (from r in Enumerable.Range(row + h - maWindow, maWindow - h)
    264                                                   where r > 0
    265                                                   select ProblemData.Dataset.GetDoubleValue(targetVariable, r)
    266                                                  ).Average();
    267 
    268           double startValue = ProblemData.Dataset.GetDoubleValue(targetVariable, row - 1);
    269           testDsCalculators.Add(startValue, actualContinuation, prognosedContinuation);
    270           testWdsCalculators.Add(startValue, actualContinuation, prognosedContinuation);
    271           testTheilsULastCalculators.Add(startValue, actualContinuation, prognosedContinuation);
    272           testTheilsUMeanCalculators.Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation);
    273           testTheilsUMovingAverageCalculators.Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
    274 
    275           var actualContinuationEnumerator = actualContinuation.GetEnumerator();
    276           var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator();
    277           while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
    278             testMseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    279             testMaeCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    280             testRelErrorCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    281             testRSquaredCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    282             testNmseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    283           }
    284           if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext())
    285             throw new ArgumentException("Different number of elements in Actual continuation and prognosed continuation.");
    286         }
    287       }
    288 
    289       TrainingMeanSquaredError = trainingMseCalculators.ErrorState == OnlineCalculatorError.None ? trainingMseCalculators.Value : double.PositiveInfinity;
    290       TestMeanSquaredError = testMseCalculators.ErrorState == OnlineCalculatorError.None ? testMseCalculators.Value : double.PositiveInfinity;
    291       TrainingMeanAbsoluteError = trainingMaeCalculators.ErrorState == OnlineCalculatorError.None ? trainingMaeCalculators.Value : double.PositiveInfinity;
    292       TestMeanAbsoluteError = testMaeCalculators.ErrorState == OnlineCalculatorError.None ? testMaeCalculators.Value : double.PositiveInfinity;
    293       TrainingRelativeError = trainingRelErrorCalculators.ErrorState == OnlineCalculatorError.None ? trainingRelErrorCalculators.Value : double.PositiveInfinity;
    294       TestRelativeError = testRelErrorCalculators.ErrorState == OnlineCalculatorError.None ? testRelErrorCalculators.Value : double.PositiveInfinity;
    295       TrainingRSquared = trainingRSquaredCalculators.ErrorState == OnlineCalculatorError.None ? trainingRSquaredCalculators.Value : 0.0;
    296       TestRSquared = testRSquaredCalculators.ErrorState == OnlineCalculatorError.None ? testRSquaredCalculators.Value : 0.0;
    297       TrainingNormalizedMeanSquaredError = trainingNmseCalculators.ErrorState == OnlineCalculatorError.None ? trainingNmseCalculators.Value : double.PositiveInfinity;
    298       TestNormalizedMeanSquaredError = testNmseCalculators.ErrorState == OnlineCalculatorError.None ? testNmseCalculators.Value : double.PositiveInfinity;
    299 
    300       TrainingDirectionalSymmetry = trainingDsCalculators.ErrorState == OnlineCalculatorError.None ? trainingDsCalculators.Value : 0.0;
    301       TestDirectionalSymmetry = testDsCalculators.ErrorState == OnlineCalculatorError.None ? testDsCalculators.Value : 0.0;
    302       TrainingWeightedDirectionalSymmetry = trainingWdsCalculators.ErrorState == OnlineCalculatorError.None ? trainingWdsCalculators.Value : double.PositiveInfinity;
    303       TestWeightedDirectionalSymmetry = testWdsCalculators.ErrorState == OnlineCalculatorError.None ? testWdsCalculators.Value : double.PositiveInfinity;
    304       TrainingTheilsUStatisticLast = trainingTheilsULastCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsULastCalculators.Value : double.PositiveInfinity;
    305       TestTheilsUStatisticLast = testTheilsULastCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsULastCalculators.Value : double.PositiveInfinity;
    306       TrainingTheilsUStatisticMean = trainingTheilsUMeanCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsUMeanCalculators.Value : double.PositiveInfinity;
    307       TestTheilsUStatisticMean = testTheilsUMeanCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsUMeanCalculators.Value : double.PositiveInfinity;
    308       TrainingTheilsUStatisticMovingAverage = trainingTheilsUMovingAverageCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsUMovingAverageCalculators.Value : double.PositiveInfinity;
    309       TestTheilsUStatisticMovingAverage = testTheilsUMovingAverageCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsUMovingAverageCalculators.Value : double.PositiveInfinity;
     194      OnlineCalculatorError errorState;
     195      //mean model
     196      double trainingMean = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average();
     197      var meanModel = new TimeSeriesPrognosisConstantModel(trainingMean);
     198
     199      //AR1 model
     200      double alpha, beta;
     201      IEnumerable<double> trainingStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes.Select(r => r - 1).Where(r => r > 0)).ToList();
     202      OnlineLinearScalingParameterCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes.Where(x => x > 0)), trainingStartValues, out alpha, out beta, out errorState);
     203      var AR1model = new TimeSeriesPrognosisAutoRegressiveModel(alpha, beta, ProblemData.TargetVariable);
     204
     205      //MA model
     206      int movingAverageWindowSize = 10 + horizon;
     207      var MovingAverageModel = new TimeSeriesPrognosisMovingAverageModel(movingAverageWindowSize, ProblemData.TargetVariable);
     208
     209      #region Calculate training quality measures
     210      var trainingHorizions = ProblemData.TrainingIndizes.Select(r => Math.Min(horizon, ProblemData.TrainingPartition.End - r)).ToList();
     211      IEnumerable<IEnumerable<double>> trainingTargetValues = ProblemData.TrainingIndizes.Zip(trainingHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList();
     212      IEnumerable<IEnumerable<double>> trainingEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndizes, trainingHorizions).ToList();
     213
     214      TrainingMeanSquaredError = OnlineMeanSquaredErrorCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState);
     215      TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? TrainingMeanSquaredError : double.PositiveInfinity;
     216      TrainingMeanAbsoluteError = OnlineMeanAbsoluteErrorCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState);
     217      TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? TrainingMeanAbsoluteError : double.PositiveInfinity;
     218      TrainingRelativeError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState);
     219      TrainingRelativeError = errorState == OnlineCalculatorError.None ? TrainingRelativeError : double.PositiveInfinity;
     220      TrainingRSquared = OnlinePearsonsRSquaredCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState);
     221      TrainingRSquared = errorState == OnlineCalculatorError.None ? TrainingRSquared : 0.0;
     222      TrainingNormalizedMeanSquaredError = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState);
     223      TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? TrainingNormalizedMeanSquaredError : double.PositiveInfinity;
     224
     225      IEnumerable<IEnumerable<double>> trainingMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndizes, trainingHorizions);
     226      IEnumerable<IEnumerable<double>> trainingAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndizes, trainingHorizions);
     227      IEnumerable<IEnumerable<double>> trainingMovingAverageModelPredictions = MovingAverageModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndizes, trainingHorizions);
     228
     229      TrainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingEstimatedValues, out errorState);
     230      TrainingDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TrainingDirectionalSymmetry : 0.0;
     231      TrainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingEstimatedValues, out errorState);
     232      TrainingWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TrainingWeightedDirectionalSymmetry : 0.0;
     233      TrainingTheilsUStatisticLast = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingAR1ModelPredictions, trainingEstimatedValues, out errorState);
     234      TrainingTheilsUStatisticLast = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticLast : double.PositiveInfinity; ;
     235      TrainingTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingMeanModelPredictions, trainingEstimatedValues, out errorState);
     236      TrainingTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticMean : double.PositiveInfinity; ;
     237      TrainingTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingMovingAverageModelPredictions, trainingEstimatedValues, out errorState);
     238      TrainingTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticMovingAverage : double.PositiveInfinity; ; ;
     239      #endregion
     240
     241      #region  Calculate test quality measures
     242      var testHorizions = ProblemData.TestIndizes.Select(r => Math.Min(horizon, ProblemData.TestPartition.End - r)).ToList();
     243      IEnumerable<IEnumerable<double>> testTargetValues = ProblemData.TestIndizes.Zip(testHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList();
     244      IEnumerable<IEnumerable<double>> testEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndizes, testHorizions).ToList();
     245
     246      TestMeanSquaredError = OnlineMeanSquaredErrorCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState);
     247      TestMeanSquaredError = errorState == OnlineCalculatorError.None ? TestMeanSquaredError : double.PositiveInfinity;
     248      TestMeanAbsoluteError = OnlineMeanAbsoluteErrorCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState);
     249      TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? TestMeanAbsoluteError : double.PositiveInfinity;
     250      TestRelativeError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState);
     251      TestRelativeError = errorState == OnlineCalculatorError.None ? TestRelativeError : double.PositiveInfinity;
     252      TestRSquared = OnlinePearsonsRSquaredCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState);
     253      TestRSquared = errorState == OnlineCalculatorError.None ? TestRSquared : 0.0;
     254      TestNormalizedMeanSquaredError = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState);
     255      TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? TestNormalizedMeanSquaredError : double.PositiveInfinity;
     256
     257      IEnumerable<double> testStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndizes.Select(r => r - 1).Where(r => r > 0)).ToList();
     258      IEnumerable<IEnumerable<double>> testMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndizes, testHorizions);
     259      IEnumerable<IEnumerable<double>> testAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndizes, testHorizions);
     260      IEnumerable<IEnumerable<double>> testMovingAverageModelPredictions = MovingAverageModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndizes, testHorizions);
     261
     262      TestDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(testStartValues, testTargetValues, testEstimatedValues, out errorState);
     263      TestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TestDirectionalSymmetry : 0.0;
     264      TestWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(testStartValues, testTargetValues, testEstimatedValues, out errorState);
     265      TestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TestWeightedDirectionalSymmetry : 0.0;
     266      TestTheilsUStatisticLast = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testAR1ModelPredictions, testEstimatedValues, out errorState);
     267      TestTheilsUStatisticLast = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticLast : double.PositiveInfinity; ;
     268      TestTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testMeanModelPredictions, testEstimatedValues, out errorState);
     269      TestTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticMean : double.PositiveInfinity; ;
     270      TestTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testMovingAverageModelPredictions, testEstimatedValues, out errorState);
     271      TestTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticMovingAverage : double.PositiveInfinity; ; ;
     272      #endregion     
    310273    }
    311274  }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisModel.cs

    r7989 r8010  
    2323namespace HeuristicLab.Problems.DataAnalysis {
    2424  public interface ITimeSeriesPrognosisModel : IDataAnalysisModel {
    25     IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, int horizon);
     25    IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons);
    2626    ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData);
    2727  }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisSolution.cs

    r7989 r8010  
    2727    new ITimeSeriesPrognosisProblemData ProblemData { get; set; }
    2828
    29     IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, int horizon);
     29    IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizon);
    3030
    3131    double TrainingMeanSquaredError { get; }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs

    r7160 r8010  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Common;
    2625
    2726namespace HeuristicLab.Problems.DataAnalysis {
     
    9796    #endregion
    9897
    99     public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) {
     98    public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> referenceContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) {
    10099      IEnumerator<double> startValueEnumerator = startValues.GetEnumerator();
    101100      IEnumerator<IEnumerable<double>> actualContinuationsEnumerator = actualContinuations.GetEnumerator();
     101      IEnumerator<IEnumerable<double>> referenceContinuationsEnumerator = referenceContinuations.GetEnumerator();
    102102      IEnumerator<IEnumerable<double>> predictedContinuationsEnumerator = predictedContinuations.GetEnumerator();
     103
    103104      OnlineTheilsUStatisticCalculator calculator = new OnlineTheilsUStatisticCalculator();
    104105
    105106      // always move forward all enumerators (do not use short-circuit evaluation!)
    106       while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) {
    107         calculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current);
     107      while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & referenceContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) {
     108        calculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, referenceContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current);
    108109        if (calculator.ErrorState != OnlineCalculatorError.None) break;
    109110      }
     
    111112      // check if all enumerators are at the end to make sure both enumerations have the same length
    112113      if (calculator.ErrorState == OnlineCalculatorError.None &&
    113           (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) {
    114         throw new ArgumentException("Number of elements in startValues, actualContinuations and estimatedValues predictedContinuations doesn't match.");
     114          (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || referenceContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) {
     115        throw new ArgumentException("Number of elements in startValues, actualContinuations, referenceContinuation and estimatedValues predictedContinuations doesn't match.");
    115116      } else {
    116117        errorState = calculator.ErrorState;
  • branches/HeuristicLab.TimeSeries/HeuristicLab.TimeSeries-3.3.sln

    r7890 r8010  
    77    ConfigMerger.exe = ConfigMerger.exe
    88    ..\documentation\License\gpl-3.0.txt = ..\documentation\License\gpl-3.0.txt
     9    HeuristicLab.TimeSeries-3.32.vsmdi = HeuristicLab.TimeSeries-3.32.vsmdi
    910    LocalTestRun.testrunconfig = LocalTestRun.testrunconfig
    1011    MergeConfigs.cmd = MergeConfigs.cmd
     
    3233EndProject
    3334Global
     35  GlobalSection(TestCaseManagementSettings) = postSolution
     36    CategoryFile = HeuristicLab.TimeSeries-3.32.vsmdi
     37  EndGlobalSection
    3438  GlobalSection(SolutionConfigurationPlatforms) = preSolution
    3539    Debug|Any CPU = Debug|Any CPU
Note: See TracChangeset for help on using the changeset viewer.