Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/05/11 20:17:59 (12 years ago)
Author:
gkronber
Message:

#1081 worked on multi-variate time series prognosis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r6808 r7129  
    5050
    5151    protected override void UpdateModel(ISymbolicExpressionTree tree) {
    52       var model = new SymbolicTimeSeriesPrognosisModel(tree, Content.Model.Interpreter);
     52      var model = new SymbolicTimeSeriesPrognosisModel(tree, Content.Model.Interpreter, Content.ProblemData.TargetVariables.ToArray());
    5353      SymbolicTimeSeriesPrognosisModel.Scale(model, Content.ProblemData);
    5454      Content.Model = model;
     
    6767      var dataset = Content.ProblemData.Dataset;
    6868      var rows = Content.ProblemData.TrainingIndizes;
    69       string targetVariable = Content.ProblemData.TargetVariable;
    70       Dictionary<ISymbolicExpressionTreeNode, double> impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    71       List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();
    72       var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows)
     69      Dictionary<ISymbolicExpressionTreeNode, double> impactValues =
     70        new Dictionary<ISymbolicExpressionTreeNode, double>();
     71      var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1)
    7372        .ToArray();
    74       var targetValues = dataset.GetDoubleValues(targetVariable, rows);
    75       OnlineCalculatorError errorState;
    76       double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput, out errorState);
    77       if (errorState != OnlineCalculatorError.None) originalR2 = 0.0;
     73      int i = 0;
     74      foreach (var targetVariable in Content.ProblemData.TargetVariables) {
     75        List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(i).IterateNodesPostfix().ToList();
     76        var targetValues = dataset.GetDoubleValues(targetVariable, rows);
     77        OnlineCalculatorError errorState;
     78        double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput.Select(v => v.ElementAt(i).First()), out errorState);
     79        if (errorState != OnlineCalculatorError.None) originalR2 = 0.0;
    7880
    79       foreach (ISymbolicExpressionTreeNode node in nodes) {
    80         var parent = node.Parent;
    81         constantNode.Value = CalculateReplacementValue(node, tree);
    82         ISymbolicExpressionTreeNode replacementNode = constantNode;
    83         SwitchNode(parent, node, replacementNode);
    84         var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);
    85         double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput, out errorState);
    86         if (errorState != OnlineCalculatorError.None) newR2 = 0.0;
     81        foreach (ISymbolicExpressionTreeNode node in nodes) {
     82          var parent = node.Parent;
     83          constantNode.Value = CalculateReplacementValue(node, tree);
     84          ISymbolicExpressionTreeNode replacementNode = constantNode;
     85          SwitchNode(parent, node, replacementNode);
     86          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);
     88          if (errorState != OnlineCalculatorError.None) newR2 = 0.0;
    8789
    88         // impact = 0 if no change
    89         // impact < 0 if new solution is better
    90         // impact > 0 if new solution is worse
    91         impactValues[node] = originalR2 - newR2;
    92         SwitchNode(parent, replacementNode, node);
     90          // impact = 0 if no change
     91          // impact < 0 if new solution is better
     92          // impact > 0 if new solution is worse
     93          impactValues[node] = originalR2 - newR2;
     94          SwitchNode(parent, replacementNode, node);
     95        }
     96        i++;
    9397      }
    9498      return impactValues;
     
    107111      var interpreter = Content.Model.Interpreter;
    108112      var rows = Content.ProblemData.TrainingIndizes;
    109       return interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, rows).Median();
     113      var allPrognosedValues = interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1);
     114     
     115      return allPrognosedValues.Select(x=>x.First().First()).Median();
    110116    }
    111117
Note: See TracChangeset for help on using the changeset viewer.