Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/08/12 16:11:03 (12 years ago)
Author:
mkommend
Message:

#1081: Fixed serialization and corrected AR(n) modeling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs

    r8468 r8762  
    7777    /// <param name="timeOffset">The parameter p of the AR(p) specifying the maximum time offset [1,infinity] </param>
    7878    /// <returns>The times series autoregressive solution </returns>
    79     public ITimeSeriesPrognosisSolution CreateAutoRegressiveSolution(ITimeSeriesPrognosisProblemData problemData, int timeOffset) {
     79    public static ITimeSeriesPrognosisSolution CreateAutoRegressiveSolution(ITimeSeriesPrognosisProblemData problemData, int timeOffset) {
    8080      double rmsError, cvRmsError;
    8181      return CreateAutoRegressiveSolution(problemData, timeOffset, out rmsError, out cvRmsError);
    8282    }
    8383
    84     internal ITimeSeriesPrognosisSolution CreateAutoRegressiveSolution(ITimeSeriesPrognosisProblemData problemData, int timeOffset, out double rmsError, out double cvRmsError) {
     84    private static ITimeSeriesPrognosisSolution CreateAutoRegressiveSolution(ITimeSeriesPrognosisProblemData problemData, int timeOffset, out double rmsError, out double cvRmsError) {
    8585      string targetVariable = problemData.TargetVariable;
    8686
    8787      double[,] inputMatrix = new double[problemData.TrainingPartition.Size, timeOffset + 1];
    88       var targetValues = problemData.Dataset.GetReadOnlyDoubleValues(targetVariable);
     88      var targetValues = problemData.Dataset.GetDoubleValues(targetVariable).ToList();
    8989      for (int i = 0, row = problemData.TrainingPartition.Start; i < problemData.TrainingPartition.Size; i++, row++) {
    90         for (int col = 0; col < timeOffset + 1; col++) {
    91           inputMatrix[i, col] = targetValues[row - col];
     90        for (int col = 0; col < timeOffset; col++) {
     91          inputMatrix[i, col] = targetValues[row - col - 1];
    9292        }
    9393      }
     94      // set target values in last column
     95      for (int i = 0; i < inputMatrix.GetLength(0); i++)
     96        inputMatrix[i, timeOffset] = targetValues[i + problemData.TrainingPartition.Start];
    9497
    9598      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     
    119122
    120123      for (int i = 0; i < timeOffset; i++) {
    121         LaggedVariableTreeNode node = (LaggedVariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.LaggedVariable().CreateTreeNode();
     124        LaggedVariableTreeNode node = (LaggedVariableTreeNode)new LaggedVariable().CreateTreeNode();
    122125        node.VariableName = targetVariable;
    123126        node.Weight = coefficients[i];
Note: See TracChangeset for help on using the changeset viewer.