Ignore:
Timestamp:
12/09/10 10:45:36 (10 years ago)
Author:
mkommend
Message:

Corrected persistence of VariableCondition and conditional evaluator (ticket #1256).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionConditionalPearsonsRSquaredEvaluator.cs

    r5074 r5076  
    2323using System;
    2424using System.Collections.Generic;
    25 using System.Linq;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    3231using HeuristicLab.Problems.DataAnalysis.Evaluators;
    3332using HeuristicLab.Problems.DataAnalysis.Symbolic;
    34 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
    3533
    3634namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Evaluators {
     
    7371      OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator();
    7472
    75       int minLag = 0;
    76       var laggedTreeNodes = solution.IterateNodesPrefix().OfType<LaggedVariableTreeNode>();
    77       if (laggedTreeNodes.Any())
    78         minLag = laggedTreeNodes.Min(laggedTreeNode => laggedTreeNode.Symbol.MinLag);
     73      int minLag = GetMinimumLagFromTree(solution.Root);
    7974
    8075      while (originalEnumerator.MoveNext() && estimatedEnumerator.MoveNext() && rowsEnumerator.MoveNext()) {
     
    8883        }
    8984
    90         if (evaluate)
    91           if (dataset[conditionVariable, row].IsAlmost(0.0) && dataset[conditionVariable, row - 1].IsAlmost(0.0)) {
    92             if (double.IsNaN(estimated))
    93               estimated = upperEstimationLimit;
    94             else
    95               estimated = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, estimated));
    96             r2Evaluator.Add(original, estimated);
    97           }
     85        if (evaluate) {
     86          if (double.IsNaN(estimated))
     87            estimated = upperEstimationLimit;
     88          else
     89            estimated = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, estimated));
     90          r2Evaluator.Add(original, estimated);
     91        }
    9892      }
    9993
    10094      if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext() || rowsEnumerator.MoveNext()) {
    10195        throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match.");
    102       } else {
    103         return r2Evaluator.RSquared;
     96      } else return r2Evaluator.RSquared;
     97    }
     98
     99    protected static int GetMinimumLagFromTree(SymbolicExpressionTreeNode node) {
     100      if (node == null) return 0;
     101      int lag = 0;
     102
     103      var laggedTreeNode = node as ILaggedTreeNode;
     104      if (laggedTreeNode != null) lag += laggedTreeNode.Lag;
     105
     106      int subtreeLag = 0;
     107      foreach (var subtree in node.SubTrees) {
     108        subtreeLag = Math.Min(subtreeLag, GetMinimumLagFromTree(subtree));
    104109      }
     110      return lag + subtreeLag;
    105111    }
    106112
Note: See TracChangeset for help on using the changeset viewer.