Changeset 7154


Ignore:
Timestamp:
12/07/11 22:47:12 (9 years ago)
Author:
gkronber
Message:

#1081: worked on multi-variate time series prognosis

Location:
branches/HeuristicLab.TimeSeries
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views-3.4.csproj

    r7129 r7154  
    110110  </ItemGroup>
    111111  <ItemGroup>
    112     <Compile Include="InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs">
    113       <SubType>UserControl</SubType>
    114     </Compile>
    115     <Compile Include="InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.Designer.cs">
    116       <DependentUpon>InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs</DependentUpon>
    117     </Compile>
    118112    <Compile Include="Plugin.cs" />
    119113    <Compile Include="SymbolicTimeSeriesPrognosisSolutionView.cs">
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r7129 r7154  
    6969      Dictionary<ISymbolicExpressionTreeNode, double> impactValues =
    7070        new Dictionary<ISymbolicExpressionTreeNode, double>();
    71       var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1)
     71      var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows)
    7272        .ToArray();
    7373      int i = 0;
     
    7676        var targetValues = dataset.GetDoubleValues(targetVariable, rows);
    7777        OnlineCalculatorError errorState;
    78         double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput.Select(v => v.ElementAt(i).First()), out errorState);
     78        double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput.Select(v => v.ElementAt(i)), out errorState);
    7979        if (errorState != OnlineCalculatorError.None) originalR2 = 0.0;
    8080
     
    8585          SwitchNode(parent, node, replacementNode);
    8686          var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1);
    87           double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput.Select(v => v.ElementAt(i).First()), out errorState);
     87          double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput.Select(v => v.First().ElementAt(i)), out errorState);
    8888          if (errorState != OnlineCalculatorError.None) newR2 = 0.0;
    8989
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/SymbolicTimeSeriesPrognosisSolutionView.cs

    r6807 r7154  
    3939
    4040    private void btn_SimplifyModel_Click(object sender, EventArgs e) {
    41       InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView view = new InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView();
    42       view.Content = (SymbolicTimeSeriesPrognosisSolution)this.Content.Clone();
    43       view.Show();
     41      //InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView view = new InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView();
     42      //view.Content = (SymbolicTimeSeriesPrognosisSolution)this.Content.Clone();
     43      //view.Show();
    4444    }
    4545  }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs

    r7129 r7154  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing.Printing;
    2425using System.Linq;
    2526using HeuristicLab.Common;
     
    6566      DetermineScalingFactors(solution, problemData, interpreter, rows, out alpha, out beta);
    6667      var scaledSolution = Scale(solution, alpha, beta);
    67 
     68      string[] targetVariables = problemData.TargetVariables.ToArray();
    6869      var meanSquaredErrorCalculators = Enumerable.Range(0, problemData.TargetVariables.Count())
    6970        .Select(i => new OnlineMeanSquaredErrorCalculator()).ToArray();
    7071
    71       var allPredictedContinuations = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset,
    72                                                                                   problemData.TargetVariables.ToArray(),
    73                                                                                   rows, horizon);
    74       var allContinuationsEnumerator = allPredictedContinuations.GetEnumerator();
    75       var rowsEnumerator = rows.GetEnumerator();
    76       while (allContinuationsEnumerator.MoveNext() & rowsEnumerator.MoveNext()) {
    77         var componentEnumerator = allContinuationsEnumerator.Current.GetEnumerator();
    78         var mseCalculatorsEnumerator = meanSquaredErrorCalculators.AsEnumerable().GetEnumerator();
    79         var targetVarEnumerator = problemData.TargetVariables.GetEnumerator();
    80         while (componentEnumerator.MoveNext() & mseCalculatorsEnumerator.MoveNext() & targetVarEnumerator.MoveNext()) {
    81           var stepEnumerator = componentEnumerator.Current.GetEnumerator();
    82           var actualContinuationEnumerator = problemData.Dataset.GetDoubleValues(targetVarEnumerator.Current,
    83                                                                        Enumerable.Range(rowsEnumerator.Current, horizon)).GetEnumerator();
    84           while (stepEnumerator.MoveNext() & actualContinuationEnumerator.MoveNext()) {
    85             double e = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, stepEnumerator.Current));
    86             mseCalculatorsEnumerator.Current.Add(actualContinuationEnumerator.Current, e);
    87             if (mseCalculatorsEnumerator.Current.ErrorState == OnlineCalculatorError.InvalidValueAdded)
    88               return double.NaN;
     72      var allContinuationsEnumerator = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset,
     73                                                                                  targetVariables,
     74                                                                                  rows, horizon).GetEnumerator();
     75      allContinuationsEnumerator.MoveNext();
     76      // foreach row
     77      foreach (var row in rows) {
     78        // foreach horizon
     79        for (int h = 0; h < horizon; h++) {
     80          // foreach component
     81          for (int i = 0; i < meanSquaredErrorCalculators.Length; i++) {
     82            double e = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, allContinuationsEnumerator.Current));
     83            meanSquaredErrorCalculators[i].Add(problemData.Dataset.GetDoubleValue(targetVariables[i], row + h), e);
     84            if (meanSquaredErrorCalculators[i].ErrorState == OnlineCalculatorError.InvalidValueAdded)
     85              return double.MaxValue;
     86            allContinuationsEnumerator.MoveNext();
    8987          }
    9088        }
     
    9290      var meanCalculator = new OnlineMeanAndVarianceCalculator();
    9391      foreach (var calc in meanSquaredErrorCalculators) {
    94         if (calc.ErrorState != OnlineCalculatorError.None) return double.NaN;
     92        if (calc.ErrorState != OnlineCalculatorError.None) return double.MaxValue;
    9593        meanCalculator.Add(calc.MeanSquaredError);
    9694      }
     
    109107      //  }
    110108      //}
    111       return meanCalculator.MeanErrorState == OnlineCalculatorError.None ? meanCalculator.Mean : double.NaN;
     109      return meanCalculator.MeanErrorState == OnlineCalculatorError.None ? meanCalculator.Mean : double.MaxValue;
    112110    }
    113111
     
    153151      alpha = new double[nComponents];
    154152      beta = new double[nComponents];
    155       var oneStepPredictions = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset,
    156                                                                      targetVariables, rows,
    157                                                                      1);
     153      var oneStepPredictionsEnumerator = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, targetVariables, rows).GetEnumerator();
     154      var scalingParameterCalculators =
     155        Enumerable.Repeat(0, nComponents).Select(x => new OnlineLinearScalingParameterCalculator()).ToArray();
     156      var targetValues = problemData.Dataset.GetVectorEnumerable(targetVariables, rows);
     157      var targetValueEnumerator = targetValues.GetEnumerator();
     158
     159      var more = oneStepPredictionsEnumerator.MoveNext() & targetValueEnumerator.MoveNext();
     160      while (more) {
     161        for (int i = 0; i < nComponents; i++) {
     162          scalingParameterCalculators[i].Add(oneStepPredictionsEnumerator.Current, targetValueEnumerator.Current);
     163          more = oneStepPredictionsEnumerator.MoveNext() & targetValueEnumerator.MoveNext();
     164        }
     165      }
     166
    158167      for (int i = 0; i < nComponents; i++) {
    159         var target = problemData.Dataset.GetDoubleValues(targetVariables[i], rows);
    160         var prediction = oneStepPredictions.Select(v => v.ElementAt(i).First());
    161         OnlineCalculatorError errorState;
    162         OnlineLinearScalingParameterCalculator.Calculate(prediction, target, out alpha[i], out beta[i], out errorState);
    163         if (errorState != OnlineCalculatorError.None) {
    164           alpha[i] = 0;
    165           beta[i] = 1;
     168        if (scalingParameterCalculators[i].ErrorState == OnlineCalculatorError.None) {
     169          alpha[i] = scalingParameterCalculators[i].Alpha;
     170          beta[i] = scalingParameterCalculators[i].Beta;
     171        } else {
     172          alpha[i] = 0.0;
     173          beta[i] = 1.0;
    166174        }
    167175      }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveProblem.cs

    r7129 r7154  
    5757      EstimationLimitsParameter.Hidden = true;
    5858
    59       Maximization.Value = true;
     59      Maximization.Value = false;
    6060      MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
    6161      MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
     
    106106          op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name;
    107107        }
     108        foreach (var op in operators.OfType<SymbolicTimeSeriesPrognosisSingleObjectiveTrainingBestSolutionAnalyzer>())
     109        {
     110          op.MaximizationParameter.ActualName = MaximizationParameter.Name;
     111          op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
     112          op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     113          op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
     114          op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     115        }
    108116      }
    109117    }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs

    r7129 r7154  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Drawing;
     
    6970      this.symbolicExpressionTree = cloner.Clone(original.symbolicExpressionTree);
    7071      this.interpreter = cloner.Clone(original.interpreter);
     72      this.targetVariables = new string[original.targetVariables.Length];
     73      Array.Copy(original.targetVariables, this.targetVariables, this.targetVariables.Length);
    7174    }
    7275    public SymbolicTimeSeriesPrognosisModel(ISymbolicExpressionTree tree, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, IEnumerable<string> targetVariables)
     
    8386
    8487    public IEnumerable<IEnumerable<IEnumerable<double>>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, int horizon) {
    85       return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, targetVariables, rows, horizon);
     88      var enumerator =
     89        Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, targetVariables, rows, horizon).
     90          GetEnumerator();
     91      foreach (var r in rows) {
     92        var l = new List<double[]>();
     93        for (int h = 0; h < horizon; h++) {
     94          double[] components = new double[targetVariables.Length];
     95          for (int c = 0; c < components.Length; c++) {
     96            enumerator.MoveNext();
     97            components[c] = enumerator.Current;
     98          }
     99          l.Add(components);
     100        }
     101        yield return l;
     102      }
    86103    }
    87104
     
    95112    public static void Scale(SymbolicTimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) {
    96113      var dataset = problemData.Dataset;
    97       var targetVariables = problemData.TargetVariables;
     114      var targetVariables = problemData.TargetVariables.ToArray();
    98115      var rows = problemData.TrainingIndizes;
    99       int i = 0;
    100       int horizon = 1;
    101       var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, problemData.TargetVariables.ToArray(), rows, horizon)
    102         .ToArray();
    103       foreach (var targetVariable in targetVariables) {
    104         var targetValues = dataset.GetDoubleValues(targetVariable, rows);
    105         double alpha;
    106         double beta;
    107         OnlineCalculatorError errorState;
    108         OnlineLinearScalingParameterCalculator.Calculate(estimatedValues.Select(x => x.ElementAt(i).First()), targetValues,
    109           out alpha, out beta, out errorState);
    110         if (errorState != OnlineCalculatorError.None) continue;
     116      var estimatedValuesEnumerator = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset,
     117                                                                              targetVariables,
     118                                                                              rows).GetEnumerator();
     119      var scalingParameterCalculators =
     120        problemData.TargetVariables.Select(v => new OnlineLinearScalingParameterCalculator()).ToArray();
     121      var targetValuesEnumerator = problemData.Dataset.GetVectorEnumerable(targetVariables, rows).GetEnumerator();
    111122
     123      var more = targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext();
     124      // foreach row
     125      while (more) {
     126        // foreach component
     127        for (int i = 0; i < targetVariables.Length; i++) {
     128          scalingParameterCalculators[i].Add(estimatedValuesEnumerator.Current, targetValuesEnumerator.Current);
     129          more = estimatedValuesEnumerator.MoveNext() & targetValuesEnumerator.MoveNext();
     130        }
     131      }
     132
     133      for (int i = 0; i < targetVariables.Count(); i++) {
     134        if (scalingParameterCalculators[i].ErrorState != OnlineCalculatorError.None) continue;
     135        double alpha = scalingParameterCalculators[i].Alpha;
     136        double beta = scalingParameterCalculators[i].Beta;
    112137        ConstantTreeNode alphaTreeNode = null;
    113138        ConstantTreeNode betaTreeNode = null;
     
    136161          startNode.InsertSubtree(i, scaledMainBranch);
    137162        }
    138         i++;
    139163      } // foreach
    140164    }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r5882 r7154  
    8585
    8686      var results = ResultCollection;
    87       if (TrainingBestSolutionQuality == null ||
    88         IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value)) {
     87      if (bestTree != null && (TrainingBestSolutionQuality == null ||
     88        IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value))) {
    8989        TrainingBestSolution = CreateSolution(bestTree, bestQuality);
    9090        TrainingBestSolutionQuality = new DoubleValue(bestQuality);
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicTimeSeriesPrognogisExpressionTreeInterpreter.cs

    r7120 r7154  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    27   public interface ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter : INamedItem  {
    28     IEnumerable<IEnumerable<IEnumerable<double>>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon);
     27  public interface ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter : INamedItem {
     28    IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset,
     29                                                        string[] targetVariables, IEnumerable<int> rows);
     30    IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon);
    2931  }
    3032}
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r7129 r7154  
    4646    private static MethodInfo round = typeof(Math).GetMethod("Round", new Type[] { typeof(double) });
    4747
    48     internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns);
     48    internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns, IList<double>[] cachedValues, int cacheStartIndex);
    4949    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
    5050    #region private classes
     
    179179
    180180    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    181       return from prog in GetSymbolicExpressionTreeValues(tree, dataset, new string[] { "#NOTHING#" }, rows, 1)
    182              select prog.First().First();
    183     }
    184 
    185     // for each row for each target variable one prognosis (=enumerable of future values)
    186     public IEnumerable<IEnumerable<IEnumerable<double>>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) {
     181      return GetSymbolicExpressionTreeValues(tree, dataset, new string[] { "#NOTHING#" }, rows);
     182    }
     183    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows) {
     184      return GetSymbolicExpressionTreeValues(tree, dataset, targetVariables, rows, 1);
     185    }
     186    // for each row for each horizon for each target variable one value
     187    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) {
    187188      if (CheckExpressionsWithIntervalArithmetic.Value)
    188189        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     
    211212      }
    212213      var state = new InterpreterState(code);
    213       Type[] methodArgs = { typeof(int), typeof(IList<double>[]) };
     214      Type[] methodArgs = { typeof(int), typeof(IList<double>[]), typeof(IList<double>[]), typeof(int) };
    214215
    215216      CompiledFunction[] function = new CompiledFunction[targetVariables.Length];
     
    222223        function[i] = (CompiledFunction)testFun.CreateDelegate(typeof(CompiledFunction));
    223224      }
    224       int nComponents = tree.Root.GetSubtree(0).SubtreeCount;
    225       // produce a n-step forecast for each target variable for all rows
    226225      var values = doubleVariableNames.Keys
    227         .Select(v => targetVariables.Contains(v) ?
    228           (IList<double>)dataset.GetDoubleValues(v).ToList() :
    229           dataset.GetReadOnlyDoubleValues(v))
    230         .Concat(new List<double>[] { Enumerable.Repeat(0.0, dataset.Rows).ToList() }) // append list for calculated target variable
     226        .Select(v => dataset.GetReadOnlyDoubleValues(v))
    231227        .ToArray();
    232       doubleVariableNames.Add("#NOTHING#", values.Count() - 1);
    233       foreach (var rowEnum in rows) {
    234         int row = rowEnum;
    235         foreach (var horizonRow in Enumerable.Range(row, horizon)) {
    236           for (int i = 0; i < nComponents; i++) {
    237             var componentProg = function[i](horizonRow, values);
     228      var cachedValues = (from var in doubleVariableNames.Keys
     229                          select new double[horizon]).ToArray();
     230      foreach (var row in rows) {
     231        // init first line of cache
     232        int c = 0;
     233        foreach (var var in doubleVariableNames.Keys)
     234          cachedValues[c++][0] = dataset.GetDoubleValue(var, row);
     235        for (int horizonRow = row; horizonRow < row + horizon; horizonRow++) {
     236          for (int i = 0; i < function.Length; i++) {
     237            var componentProg = function[i](horizonRow, values, cachedValues, row);
    238238            // set cachedValues for prognosis of future values
    239             values[doubleVariableNames[targetVariables[i]]][horizonRow] = componentProg;
    240           }
    241         }
    242 
    243         yield return from component in Enumerable.Range(0, nComponents)
    244                      select from horizonRow in Enumerable.Range(row, horizon)
    245                             select values[doubleVariableNames[targetVariables[component]]][horizonRow];
    246         // reset start value
    247         foreach (var v in targetVariables) {
    248           if (v != "#NOTHING#")
    249             values[doubleVariableNames[v]][row] = dataset.GetDoubleValue(v, row);
     239            if (horizon > 1)
     240              cachedValues[doubleVariableNames[targetVariables[i]]][horizonRow - row] = componentProg;
     241            yield return componentProg;
     242          }
    250243        }
    251244      }
     
    547540        case OpCodes.Variable: {
    548541            VariableTreeNode varNode = (VariableTreeNode)currentInstr.dynamicNode;
    549             il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
    550             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0);
    551             // load correct column of the current variable
    552             il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
    553             il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
    554542            if (!state.InLaggedContext) {
     543              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
     544              il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0);
     545              // load correct column of the current variable
     546              il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
     547              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
    555548              il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue);
    556549              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight
     
    559552              var nanResult = il.DefineLabel();
    560553              var normalResult = il.DefineLabel();
     554              var cachedValue = il.DefineLabel();
     555              var multiplyValue = il.DefineLabel();
     556              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
    561557              il.Emit(System.Reflection.Emit.OpCodes.Dup);
    562558              il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
     
    565561              il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, ds.Rows);
    566562              il.Emit(System.Reflection.Emit.OpCodes.Bge, nanResult);
     563              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3);
     564              il.Emit(System.Reflection.Emit.OpCodes.Bge, cachedValue);
     565              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
     566              il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0);
     567              il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
     568              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
    567569              il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue);
     570              il.Emit(System.Reflection.Emit.OpCodes.Br, multiplyValue);
     571              il.MarkLabel(cachedValue);
     572              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_2); // load cached values array
     573              il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0);
     574              il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
     575              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
     576              il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3); // startRow
     577              il.Emit(System.Reflection.Emit.OpCodes.Sub); // startRow
     578              il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue);
     579              il.MarkLabel(multiplyValue);
    568580              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight
    569581              il.Emit(System.Reflection.Emit.OpCodes.Mul);
     
    571583              il.MarkLabel(nanResult);
    572584              il.Emit(System.Reflection.Emit.OpCodes.Pop); // rowIndex
    573               il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference
    574585              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN);
    575586              il.MarkLabel(normalResult);
     
    580591            var nanResult = il.DefineLabel();
    581592            var normalResult = il.DefineLabel();
     593            var cachedValue = il.DefineLabel();
     594            var multiplyValue = il.DefineLabel();
    582595            LaggedVariableTreeNode varNode = (LaggedVariableTreeNode)currentInstr.dynamicNode;
    583             il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
    584             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); // load correct column of the current variable
    585             il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
    586596            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, varNode.Lag); // lag
    587597            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
     
    593603            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, ds.Rows);
    594604            il.Emit(System.Reflection.Emit.OpCodes.Bge, nanResult);
     605            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3); // startindex
     606            il.Emit(System.Reflection.Emit.OpCodes.Bge, cachedValue);
     607            // normal value
     608            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
     609            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); // load correct column of the current variable
     610            il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
     611            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, varNode.Lag); // lag
     612            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
     613            il.Emit(System.Reflection.Emit.OpCodes.Add); // actualRowIndex = rowIndex + sampleOffset
    595614            il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue);
     615            il.Emit(System.Reflection.Emit.OpCodes.Br, multiplyValue);
     616            il.MarkLabel(cachedValue);
     617            // cached value
     618            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_2); // load cached values
     619            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); // load correct column of the current variable
     620            il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
     621            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, varNode.Lag); // lag
     622            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
     623            il.Emit(System.Reflection.Emit.OpCodes.Add); // actualRowIndex = rowIndex + sampleOffset
     624            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3); // startRow
     625            il.Emit(System.Reflection.Emit.OpCodes.Sub); // startRow           
     626            il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue);
     627
     628            il.MarkLabel(multiplyValue);
    596629            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight
    597630            il.Emit(System.Reflection.Emit.OpCodes.Mul);
    598631            il.Emit(System.Reflection.Emit.OpCodes.Br, normalResult);
    599632            il.MarkLabel(nanResult);
    600             il.Emit(System.Reflection.Emit.OpCodes.Pop); // sample index
    601             il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference
     633            il.Emit(System.Reflection.Emit.OpCodes.Pop); // pop the row index
    602634            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN);
    603635            il.MarkLabel(normalResult);
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r7120 r7154  
    201201
    202202    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    203       return from prog in GetSymbolicExpressionTreeValues(tree, dataset, new string[] { "#NOTHING#" }, rows, 1)
    204              select prog.First().First();
    205     }
    206 
    207     // for each row for each target variable one prognosis (=enumerable of future values)
    208     public IEnumerable<IEnumerable<IEnumerable<double>>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) {
     203      return GetSymbolicExpressionTreeValues(tree, dataset, new string[] { "#NOTHING#" }, rows);
     204    }
     205
     206    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows) {
     207      return GetSymbolicExpressionTreeValues(tree, dataset, targetVariables, rows, 1);
     208    }
     209
     210
     211    // for each row for each horizon for each target variable one value
     212    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) {
    209213      if (CheckExpressionsWithIntervalArithmetic.Value)
    210214        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     
    238242      foreach (var rowEnum in rows) {
    239243        int row = rowEnum;
    240         List<double[]> vProgs = new List<double[]>();
    241244        foreach (var horizonRow in Enumerable.Range(row, horizon)) {
    242245          int localRow = horizonRow; // create a local variable for the ref parameter
    243           var vPrognosis = from i in Enumerable.Range(0, nComponents)
    244                            select Evaluate(dataset, ref localRow, row - 1, state, cachedPrognosedValues);
    245 
    246           var vPrognosisArr = vPrognosis.ToArray();
    247           vProgs.Add(vPrognosisArr);
    248           // set cachedValues for prognosis of future values
    249           for (int i = 0; i < vPrognosisArr.Length; i++)
    250             cachedPrognosedValues[targetVariables[i]][horizonRow - row] = vPrognosisArr[i];
     246          for (int c = 0; c < nComponents; c++) {
     247            var prog = Evaluate(dataset, ref localRow, row - 1, state, cachedPrognosedValues);
     248            yield return prog;
     249            cachedPrognosedValues[targetVariables[c]][horizonRow - row] = prog;
     250          }
    251251
    252252          state.Reset();
    253253        }
    254 
    255         yield return from component in Enumerable.Range(0, nComponents)
    256                      select from prognosisStep in Enumerable.Range(0, vProgs.Count)
    257                             select vProgs[prognosisStep][component];
    258254      }
    259255    }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionLineChartView.cs

    r7129 r7154  
    9191          this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Points
    9292            .DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(),
    93                         Content.PrognosedTrainingValues.ElementAt(varIndex).ToArray());
     93                        Content.PrognosedTrainingValues.SelectMany(x => x).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray());
    9494        } else {
    9595          this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Points
    9696            .DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(),
    97                         Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes, 1).Select(v => v.ElementAt(varIndex).First()).ToArray());
     97                        Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes, 1).SelectMany(x => x.Single()).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray());
    9898        }
    9999        this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
     
    109109          this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points
    110110            .DataBindXY(Content.ProblemData.TestIndizes.ToArray(),
    111                         Content.PrognosedTestValues.ElementAt(varIndex).ToArray());
     111                        Content.PrognosedTestValues.SelectMany(x => x).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray());
    112112        } else {
    113113          this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points
    114114            .DataBindXY(Content.ProblemData.TestIndizes.ToArray(),
    115                         Content.GetPrognosedValues(Content.ProblemData.TestIndizes, 1).Select(
    116                           v => v.ElementAt(varIndex).First()).ToArray());
     115                        Content.GetPrognosedValues(Content.ProblemData.TestIndizes, 1).SelectMany(x => x.Single()).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray());
    117116        }
    118117        this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Tag = Content;
     
    242241          case PROGNOSEDVALUES_TRAINING_SERIES_NAME:
    243242            indizes = Content.ProblemData.TrainingIndizes.ToArray();
    244             predictedValues = Content.PrognosedTrainingValues.ElementAt(varIndex).ToArray();
     243            predictedValues =
     244              Content.PrognosedTrainingValues.SelectMany(x => x).Skip(varIndex).TakeEvery(
     245                Content.ProblemData.TargetVariables.Count()).ToArray();
    245246            break;
    246247          case PROGNOSEDVALUES_TEST_SERIES_NAME:
    247248            indizes = Content.ProblemData.TestIndizes.ToArray();
    248             predictedValues = Content.PrognosedTestValues.ElementAt(varIndex).ToArray();
     249            Content.PrognosedTestValues.SelectMany(x => x).Skip(varIndex).TakeEvery(
     250              Content.ProblemData.TargetVariables.Count()).ToArray();
    249251            break;
    250252        }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionPrognosedValuesView.cs

    r7100 r7154  
    9393            values[row, 0] = row.ToString();
    9494
    95           var prognosedTraining = Content.PrognosedTrainingValues.ToArray();
    96           var prognosedTest = Content.PrognosedTestValues.ToArray();
     95          var allPrognosedTraining = Content.PrognosedTrainingValues.SelectMany(x=>x).ToArray();
     96          var allPrognosedTest = Content.PrognosedTestValues.SelectMany(x => x).ToArray();
    9797
    9898          int i = 0;
    9999          int targetVariableIndex = 0;
    100100          foreach (var targetVariable in Content.ProblemData.TargetVariables) {
     101            var prognosedTraining =
     102              allPrognosedTraining.Skip(targetVariableIndex).TakeEvery(Content.ProblemData.TargetVariables.Count());
     103            var prognosedTest =
     104              allPrognosedTest.Skip(targetVariableIndex).TakeEvery(Content.ProblemData.TargetVariables.Count());
     105
    101106            double[] target = Content.ProblemData.Dataset.GetDoubleValues(targetVariable).ToArray();
    102107
    103             var prognosedTrainingEnumerator = prognosedTraining[targetVariableIndex].GetEnumerator();
     108            var prognosedTrainingEnumerator = prognosedTraining.GetEnumerator();
    104109            foreach (var row in Content.ProblemData.TrainingIndizes) {
    105110              prognosedTrainingEnumerator.MoveNext();
     
    107112            }
    108113
    109             var prognosedTestEnumerator = prognosedTest[targetVariableIndex].GetEnumerator();
     114            var prognosedTestEnumerator = prognosedTest.GetEnumerator();
    110115            foreach (var row in Content.ProblemData.TestIndizes) {
    111116              prognosedTestEnumerator.MoveNext();
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r7099 r7154  
    108108  </ItemGroup>
    109109  <ItemGroup>
     110    <Compile Include="DatasetExtensions.cs" />
    110111    <Compile Include="DoubleLimit.cs" />
    111112    <Compile Include="Implementation\Classification\ClassificationEnsembleModel.cs">
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs

    r7100 r7154  
    161161    protected void CalculateResults() {
    162162      OnlineCalculatorError errorState;
     163      string[] targetVariables = ProblemData.TargetVariables.ToArray();
    163164      /*
    164165      double[] estimatedTrainingValues = PrognosedTrainingValues.ToArray(); // cache values
     
    193194              */
    194195
    195       double[] trainingDs = new double[ProblemData.TargetVariables.Count()];
    196       double[] testDs = new double[ProblemData.TargetVariables.Count()];
    197 
    198       double[] trainingWds = new double[ProblemData.TargetVariables.Count()];
    199       double[] testWds = new double[ProblemData.TargetVariables.Count()];
    200 
    201       double[] trainingTheilsU = new double[ProblemData.TargetVariables.Count()];
    202       double[] testTheilsU = new double[ProblemData.TargetVariables.Count()];
    203       int i = 0;
    204       var predictedContinuationTraining = PrognosedTrainingValues.ToArray();
    205       var predictedContinuationTest = PrognosedTestValues.ToArray();
    206 
    207       foreach (var targetVariable in ProblemData.TargetVariables) {
    208         var actualTrainingValues = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TrainingIndizes).ToArray();
    209         var startTrainingValues = actualTrainingValues.Take(1);
    210         // only one continuation (but the full training set)
    211         var actualContinuationTraining = actualTrainingValues.Skip(1);
    212 
    213         var actualTestValues = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TestIndizes).ToArray();
    214         var startTestValues = actualTestValues.Take(1);
    215         // only one continuation (but the full training set)
    216         var actualContinuationTest = actualTestValues.Skip(1);
    217 
    218 
    219         trainingDs[i] = OnlineDirectionalSymmetryCalculator.Calculate(startTrainingValues,
    220           Enumerable.Repeat(actualContinuationTraining, 1),
    221           Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState);
    222         if (errorState != OnlineCalculatorError.None) trainingDs[i] = double.NaN;
    223 
    224         testDs[i] = OnlineDirectionalSymmetryCalculator.Calculate(startTestValues,
    225           Enumerable.Repeat(actualContinuationTest, 1),
    226           Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState);
    227         if (errorState != OnlineCalculatorError.None) testDs[i] = double.NaN;
    228 
    229         trainingWds[i] =
    230           OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTrainingValues,
    231           Enumerable.Repeat(actualContinuationTraining, 1),
    232           Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState);
    233         if (errorState != OnlineCalculatorError.None) trainingWds[i] = double.NaN;
    234 
    235         testWds[i] = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTestValues,
    236           Enumerable.Repeat(actualContinuationTest, 1),
    237           Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState);
    238         if (errorState != OnlineCalculatorError.None) testWds[i] = double.NaN;
    239 
    240         trainingTheilsU[i] = OnlineTheilsUStatisticCalculator.Calculate(startTrainingValues,
    241           Enumerable.Repeat(actualContinuationTraining, 1),
    242           Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState);
    243         if (errorState != OnlineCalculatorError.None) trainingTheilsU[i] = double.NaN;
    244 
    245         testTheilsU[i] = OnlineTheilsUStatisticCalculator.Calculate(startTestValues,
    246           Enumerable.Repeat(actualContinuationTest, 1),
    247           Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState);
    248         if (errorState != OnlineCalculatorError.None) testTheilsU[i] = double.NaN;
    249         i++;
     196      //double[] trainingDs = new double[targetVariables.Length];
     197      //double[] testDs = new double[targetVariables.Length];
     198
     199      //double[] trainingWds = new double[targetVariables.Length];
     200      //double[] testWds = new double[targetVariables.Length];
     201
     202      //double[] trainingTheilsU = new double[targetVariables.Length];
     203      //double[] testTheilsU = new double[targetVariables.Length];
     204
     205      var trainingDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length];
     206      var testDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length];
     207      var trainingWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator[targetVariables.Length];
     208      var testWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator[targetVariables.Length];
     209      var trainingTheilsUCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
     210      var testTheilsUCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
     211      for (int i = 0; i < targetVariables.Length; i++) {
     212        trainingDsCalculators[i] = new OnlineDirectionalSymmetryCalculator();
     213        testDsCalculators[i] = new OnlineDirectionalSymmetryCalculator();
     214        trainingWdsCalculators[i] = new OnlineWeightedDirectionalSymmetryCalculator();
     215        testWdsCalculators[i] = new OnlineWeightedDirectionalSymmetryCalculator();
     216        trainingTheilsUCalculators[i] = new OnlineTheilsUStatisticCalculator();
     217        testTheilsUCalculators[i] = new OnlineTheilsUStatisticCalculator();
    250218      }
    251219
    252       TrainingDirectionalSymmetry = trainingDs;
    253       TestDirectionalSymmetry = testDs;
    254       TrainingWeightedDirectionalSymmetry = trainingWds;
    255       TestWeightedDirectionalSymmetry = testWds;
    256       TrainingTheilsUStatistic = trainingTheilsU;
    257       TestTheilsUStatistic = testTheilsU;
     220      var allPrognosedTrainingValues = PrognosedTrainingValues.SelectMany(x => x).ToArray();
     221      var allPrognosedTestValues = PrognosedTestValues.SelectMany(x => x).ToArray();
     222      for (int t = 0; t < targetVariables.Length; t++) {
     223        var actualTrainingValues = ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TrainingIndizes);
     224        double startTrainingValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], ProblemData.TrainingIndizes.First() - 1);
     225        var prognosedTrainingValues = allPrognosedTrainingValues.Skip(t).TakeEvery(targetVariables.Length);
     226        trainingDsCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues);
     227        trainingWdsCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues);
     228        trainingTheilsUCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues);
     229
     230        var actualTestValues = ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TestIndizes);
     231        double startTestValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], ProblemData.TestIndizes.First() - 1);
     232        var prognosedTestValues = allPrognosedTestValues.Skip(t).TakeEvery(targetVariables.Length);
     233        testDsCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues);
     234        testWdsCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues);
     235        testTheilsUCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues);
     236      }
     237
     238      TrainingDirectionalSymmetry = trainingDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
     239        .ToArray();
     240      TestDirectionalSymmetry = testDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
     241        .ToArray();
     242      TrainingWeightedDirectionalSymmetry = trainingWdsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     243        .ToArray();
     244      TestWeightedDirectionalSymmetry = testWdsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     245        .ToArray();
     246      TrainingTheilsUStatistic = trainingDsCalculators
     247        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     248        .ToArray();
     249      TestTheilsUStatistic = testTheilsUCalculators
     250        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     251        .ToArray();
    258252    }
    259253  }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Tests/HeuristicLab-3.3/SamplesTest.cs

    r7082 r7154  
    4444using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification;
    4545using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
     46using HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis;
    4647using HeuristicLab.Problems.Knapsack;
    4748using HeuristicLab.Problems.TestFunctions;
     
    434435    }
    435436    #endregion
     437    #region Symbolic Time-Series Prognosis
     438    [TestMethod]
     439    public void CreateGpSymbolicTimeSeriesPrognosisSampleTest() {
     440      var ga = CreateGpSymbolicTimeSeriesPrognosisSample();
     441      XmlGenerator.Serialize(ga, "../../SGP_SymbTimeSeries.hl");
     442    }
     443
     444    [TestMethod]
     445    public void RunGpSymbolicTimeSeriesPrognosisSample() {
     446      var ga = CreateGpSymbolicTimeSeriesPrognosisSample();
     447      ga.SetSeedRandomly.Value = false;
     448      RunAlgorithm(ga);
     449      Assert.Inconclusive("Asserts not implemented!");
     450    }
     451
     452    private GeneticAlgorithm CreateGpSymbolicTimeSeriesPrognosisSample() {
     453      GeneticAlgorithm ga = new GeneticAlgorithm();
     454      #region Problem Configuration
     455      SymbolicTimeSeriesPrognosisSingleObjectiveProblem symbTimeProblem = new SymbolicTimeSeriesPrognosisSingleObjectiveProblem();
     456      symbTimeProblem.ProblemData.TrainingPartition.Start = 20;
     457
     458
     459      // configure remaining problem parameters
     460      symbTimeProblem.RelativeNumberOfEvaluatedSamples.Value = 1;
     461      symbTimeProblem.MaximumSymbolicExpressionTreeLength.Value = 100;
     462      symbTimeProblem.MaximumSymbolicExpressionTreeDepth.Value = 10;
     463      symbTimeProblem.MaximumFunctionDefinitions.Value = 0;
     464      symbTimeProblem.MaximumFunctionArguments.Value = 0;
     465      symbTimeProblem.SymbolicExpressionTreeInterpreter = new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter();
     466     
     467      #endregion
     468      #region Algorithm Configuration
     469      ga.Problem = symbTimeProblem;
     470      ga.Name = "Genetic Programming - Symbolic Time-Series Prognosis";
     471      ga.Description = "A standard genetic programming algorithm to solve a time-series prognosis problem (Mackey-Glass 17)";
     472      ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(
     473        ga, 1000, 1, 100, 0.15, 5
     474        );
     475
     476      var mutator = (MultiSymbolicExpressionTreeManipulator)ga.Mutator;
     477      mutator.Operators.OfType<FullTreeShaker>().Single().ShakingFactor = 0.1;
     478      mutator.Operators.OfType<OnePointShaker>().Single().ShakingFactor = 1.0;
     479
     480      ga.Analyzer.Operators.SetItemCheckedState(
     481        ga.Analyzer.Operators
     482        .OfType<SymbolicDataAnalysisAlleleFrequencyAnalyzer>()
     483        .First(), false);
     484      #endregion
     485      return ga;
     486    }
     487    #endregion
    436488    #endregion
    437489
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs

    r7129 r7154  
    315315      Evaluate(interpreter, ds, "(lagVariable 1.0 a -1) ", 2, ds.GetDoubleValue("A", 1));
    316316      Evaluate(interpreter, ds, "(lagVariable 1.0 a 0) ", 2, ds.GetDoubleValue("A", 2));
    317       Evaluate(interpreter, ds, "(lagVariable 1.0 a 1) ", 0, ds.GetDoubleValue("A", 1));
     317      //Evaluate(interpreter, ds, "(lagVariable 1.0 a 1) ", 0, ds.GetDoubleValue("A", 1));
    318318
    319319      // integral
    320320      Evaluate(interpreter, ds, "(integral -1.0 (variable 1.0 a)) ", 1, ds.GetDoubleValue("A", 0) + ds.GetDoubleValue("A", 1));
    321       Evaluate(interpreter, ds, "(integral -1.0 (lagVariable 1.0 a 1)) ", 1, ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2));
     321      Evaluate(interpreter, ds, "(integral -1.0 (lagVariable 1.0 a -1)) ", 3, ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2));
    322322      Evaluate(interpreter, ds, "(integral -2.0 (variable 1.0 a)) ", 2, ds.GetDoubleValue("A", 0) + ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2));
    323323      Evaluate(interpreter, ds, "(integral -1.0 (* (variable 1.0 a) (variable 1.0 b)))", 1, ds.GetDoubleValue("A", 0) * ds.GetDoubleValue("B", 0) + ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 1));
     
    336336
    337337      // timelag
    338       Evaluate(interpreter, ds, "(lag -1.0 (lagVariable 1.0 a 2)) ", 1, ds.GetDoubleValue("A", 2));
    339       Evaluate(interpreter, ds, "(lag -2.0 (lagVariable 1.0 a 2)) ", 2, ds.GetDoubleValue("A", 2));
    340       Evaluate(interpreter, ds, "(lag -1.0 (* (lagVariable 1.0 a 1) (lagVariable 1.0 b 2)))", 1, ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 2));
     338      Evaluate(interpreter, ds, "(lag -1.0 (lagVariable 1.0 a -2)) ", 5, ds.GetDoubleValue("A", 2));
     339      Evaluate(interpreter, ds, "(lag -2.0 (lagVariable 1.0 a -2)) ", 5, ds.GetDoubleValue("A", 1));
     340      Evaluate(interpreter, ds, "(lag -1.0 (* (lagVariable 1.0 a -1) (lagVariable 1.0 b -2)))", 3, ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 0));
    341341      Evaluate(interpreter, ds, "(lag -2.0 3.0)", 1, 3.0);
    342342
     
    349349      Evaluate(interpreter, ds, @"(PROG
    350350                                    (MAIN (lagVariable 1.0 a -1) (lagVariable 1.0 b -1)))", new string[] { "A", "B" }, Enumerable.Range(1, 2), 3,
    351       new[] { new[] { 1.0, 1.0, 1.0 }, new[] { 1.0, 1.0, 1.0 } },
    352       new[] { new[] { 2.0, 2.0, 2.0 }, new[] { 2.0, 2.0, 2.0 } }
     351      new[] { new[] { 1.0, 1.0},
     352              new[] { 1.0, 1.0},
     353              new[] { 1.0, 1.0}},
     354      new[] { new[] { 2.0, 2.0},
     355              new[] { 2.0, 2.0},
     356              new[] { 2.0, 2.0} }
    353357        );
    354358
     
    364368      Evaluate(interpreter, ds, @"(PROG
    365369                                     (MAIN (lagVariable 2.0 a -2) (lagVariable 1.0 a -1)))", new string[] { "A", "B" }, Enumerable.Range(2, 3), 4,
    366       new[] { new[] { 2.0, 4.0, 4.0, 8.0 }, new[] { 2.0, 2.0, 4.0, 4.0 } },
    367       new[] { new[] { 4.0, 2.0, 8.0, 4.0 }, new[] { 1.0, 4.0, 2.0, 8.0 } },
    368       new[] { new[] { 2.0, 2.0, 4.0, 4.0 }, new[] { 1.0, 2.0, 2.0, 4.0 } }
     370      new[] { new[] { 2.0, 2.0},
     371              new[] { 4.0, 2.0},
     372              new[] { 4.0, 4.0},
     373              new[] { 8.0, 4.0}},
     374      new[] { new[] { 4.0, 1.0},
     375              new[] { 2.0, 4.0},
     376              new[] { 8.0, 2.0},
     377              new[] { 4.0, 8.0}},
     378      new[] { new[] { 2.0, 1.0},
     379              new[] { 2.0, 2.0},
     380              new[] { 4.0, 2.0},
     381              new[] { 4.0, 4.0}}
    369382        );
    370383    }
     
    384397      ISymbolicExpressionTree tree = importer.Import(expr);
    385398
    386       var allPrognosis = interpreter.GetSymbolicExpressionTreeValues(tree, ds, targetVariables, rows, horizon);
     399      var allPrognosis = interpreter.GetSymbolicExpressionTreeValues(tree, ds, targetVariables, rows, horizon).GetEnumerator();
    387400      int i = 0;
    388       foreach (var actual in allPrognosis) {
    389         var actualEnumerator = actual.GetEnumerator();
    390         var expectedEnumerator = expected[i].GetEnumerator();
    391         while (actualEnumerator.MoveNext() & expectedEnumerator.MoveNext()) {
    392           var aEnumerator = actualEnumerator.Current.GetEnumerator();
     401      var expectedEnumerator = expected[i].GetEnumerator();
     402      while (allPrognosis.MoveNext()) {
     403        while (expectedEnumerator.MoveNext()) {
    393404          var eEnumerator = expectedEnumerator.Current.GetEnumerator();
    394           while (aEnumerator.MoveNext() & eEnumerator.MoveNext()) {
    395             Assert.IsFalse(double.IsNaN(aEnumerator.Current) && !double.IsNaN(eEnumerator.Current));
    396             Assert.IsFalse(!double.IsNaN(aEnumerator.Current) && double.IsNaN(eEnumerator.Current));
    397             Assert.AreEqual(eEnumerator.Current, aEnumerator.Current, 1.0E-12, expr);
     405          while (eEnumerator.MoveNext()) {
     406            Assert.IsFalse(double.IsNaN(allPrognosis.Current) && !double.IsNaN(eEnumerator.Current));
     407            Assert.IsFalse(!double.IsNaN(allPrognosis.Current) && double.IsNaN(eEnumerator.Current));
     408            Assert.AreEqual(eEnumerator.Current, allPrognosis.Current, 1.0E-12, expr);
     409            allPrognosis.MoveNext();
    398410          }
    399411        }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r7097 r7154  
    830830      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</Name>
    831831    </ProjectReference>
     832    <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj">
     833      <Project>{07486E68-1517-4B9D-A58D-A38E99AE71AB}</Project>
     834      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4</Name>
     835    </ProjectReference>
    832836    <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis.Symbolic.Views\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj">
    833837      <Project>{7A2531CE-3F7C-4F13-BCCA-ED6DC27A7086}</Project>
Note: See TracChangeset for help on using the changeset viewer.