Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/23/10 13:49:30 (14 years ago)
Author:
gkronber
Message:

Fixed bugs in time series prognosis classes #1142.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Views/3.3/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r4464 r4475  
    9595        int samplesEnd = Content.ProblemData.TrainingSamplesEnd.Value;
    9696
    97         double[] alpha, beta;
    9897        double quality;
    9998        conditionVariableName = Content.ConditionalEvaluationVariable;
    10099        targetVariables = Content.ProblemData.TargetVariables.CheckedItems.Select(x => x.Value.Value);
    101100        int nTargetVariables = Content.ProblemData.TargetVariables.CheckedItems.Count();
    102         lowerEstimationLimit = new DoubleArray(Enumerable.Repeat(double.NegativeInfinity, nTargetVariables).ToArray());
    103         upperEstimationLimit = new DoubleArray(Enumerable.Repeat(double.PositiveInfinity, nTargetVariables).ToArray());
    104101        interpreter = Content.Model.Interpreter;
    105102        horizon = Content.Horizon;
    106103        IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);
    107         SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.CalculateScalingParameters(simplifiedExpressionTree,
    108           Content.ProblemData, interpreter,
    109           conditionVariableName, rows,
    110           out beta, out alpha);
    111 
    112         quality = SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.Evaluate(simplifiedExpressionTree, Content.ProblemData, interpreter,
    113           conditionVariableName, rows, horizon,
    114           lowerEstimationLimit, upperEstimationLimit,
    115           beta, alpha);
     104        if (!string.IsNullOrEmpty(conditionVariableName)) {
     105          rows = (from row in rows
     106                  where !Content.ProblemData.Dataset[conditionVariableName, row].IsAlmost(0.0)
     107                  select row).ToList();
     108        }
     109        lowerEstimationLimit = new DoubleArray(nTargetVariables);
     110        upperEstimationLimit = new DoubleArray(nTargetVariables);
     111        for (int i = 0; i < nTargetVariables; i++) {
     112          lowerEstimationLimit[i] = Content.GetLowerEstimationLimit(i);
     113          upperEstimationLimit[i] = Content.GetUpperEstimationLimit(i);
     114        }
     115        quality = SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.Calculate(simplifiedExpressionTree, Content.ProblemData, interpreter,
     116          rows, horizon,
     117          lowerEstimationLimit, upperEstimationLimit);
    116118
    117119        this.CalculateReplacementNodes();
    118120
    119         this.CalculateNodeImpacts(simplifiedExpressionTree, simplifiedExpressionTree.Root, quality);
     121        this.CalculateNodeImpacts(simplifiedExpressionTree, simplifiedExpressionTree.Root, quality, rows);
    120122        // show only interesing part
    121123        this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0]);
     
    134136          while (start.SubTrees.Count > 0) start.RemoveSubTree(0);
    135137          start.AddSubTree(node);
    136           double constantTreeNodeValue = interpreter.GetSymbolicExpressionTreeValues(tree, Content.ProblemData.Dataset, targetVariables, trainingSamples, 1).Select(x => x[0]).Median();
     138          // we only want a scalar replacement value for the single branch that should be evaluated
     139          // so assume we only create an estimation for the first target variable
     140          double constantTreeNodeValue = interpreter.GetSymbolicExpressionTreeValues(tree, Content.ProblemData.Dataset, targetVariables.Take(1) , trainingSamples, 1).Select(x => x[0]).Median();
    137141          ConstantTreeNode constantTreeNode = MakeConstantTreeNode(constantTreeNodeValue);
    138142          replacementNodes[node] = constantTreeNode;
     
    141145    }
    142146
    143     private void CalculateNodeImpacts(SymbolicExpressionTree tree, SymbolicExpressionTreeNode currentTreeNode, double originalQuality) {
     147    private void CalculateNodeImpacts(SymbolicExpressionTree tree, SymbolicExpressionTreeNode currentTreeNode, double originalQuality, IEnumerable<int> rows) {
    144148      foreach (SymbolicExpressionTreeNode childNode in currentTreeNode.SubTrees.ToList()) {
    145149        if (!(childNode.Symbol is StartSymbol || childNode.Symbol is ProgramRootSymbol)) {
    146150          SwitchNode(currentTreeNode, childNode, replacementNodes[childNode]);
    147           int samplesStart = Content.ProblemData.TrainingSamplesStart.Value;
    148           int samplesEnd = Content.ProblemData.TrainingSamplesEnd.Value;
    149           double[] alpha;
    150           double[] beta;
    151151          int horizon = Content.Horizon;
    152           IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);         
    153           SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.CalculateScalingParameters(tree,
    154             Content.ProblemData, interpreter,
    155             conditionVariableName, rows,
    156             out beta, out alpha);
    157 
    158           double newQuality = SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.Evaluate(tree, Content.ProblemData, interpreter,
    159             conditionVariableName, rows, horizon,
    160             lowerEstimationLimit, upperEstimationLimit,
    161             beta, alpha);
     152
     153          double newQuality = SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.Calculate(tree, Content.ProblemData, interpreter,
     154            rows, horizon,
     155            lowerEstimationLimit, upperEstimationLimit);
    162156
    163157          nodeImpacts[childNode] = newQuality / originalQuality;
    164158          SwitchNode(currentTreeNode, replacementNodes[childNode], childNode);
    165159        }
    166         CalculateNodeImpacts(tree, childNode, originalQuality);
     160        CalculateNodeImpacts(tree, childNode, originalQuality, rows);
    167161      }
    168162    }
Note: See TracChangeset for help on using the changeset viewer.