Ignore:
Timestamp:
07/01/14 10:53:46 (5 years ago)
Author:
mkommend
Message:

#2206: Updated data preprocessing branch with trunk changes.

Location:
branches/DataPreprocessing
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing

  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs

    r10538 r11064  
    8585    }
    8686    #endregion
     87
    8788    #region properties
    8889    protected IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } }
    8990    protected ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator { get { return ImpactValuesCalculatorParameter.Value; } }
    9091    protected IntRange FitnessCalculationPartition { get { return FitnessCalculationPartitionParameter.ActualValue; } }
    91     protected BoolValue PruneOnlyZeroImpactNodes { get { return PruneOnlyZeroImpactNodesParameter.Value; } }
    92     protected DoubleValue NodeImpactThreshold { get { return NodeImpactThresholdParameter.Value; } }
     92    protected bool PruneOnlyZeroImpactNodes {
     93      get { return PruneOnlyZeroImpactNodesParameter.Value.Value; }
     94      set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; }
     95    }
     96    protected double NodeImpactThreshold {
     97      get { return NodeImpactThresholdParameter.Value.Value; }
     98      set { NodeImpactThresholdParameter.Value.Value = value; }
     99    }
    93100    protected ISymbolicExpressionTree SymbolicExpressionTree { get { return SymbolicExpressionTreeParameter.ActualValue; } }
    94101    protected DoubleValue Quality { get { return QualityParameter.ActualValue; } }
     
    117124      #endregion
    118125    }
     126
     127    protected abstract ISymbolicDataAnalysisModel CreateModel();
     128
     129    protected abstract double Evaluate(IDataAnalysisModel model);
     130
    119131    public override IOperation Apply() {
    120132      var model = CreateModel();
    121133      var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
    122       var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size).ToList();
    123 
     134      var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
    124135      var prunedSubtrees = 0;
    125136      var prunedTrees = 0;
     
    134145        ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality);
    135146
    136         if (PruneOnlyZeroImpactNodes.Value && (!impactValue.IsAlmost(0.0))) continue;
    137         else if (NodeImpactThreshold.Value < impactValue) continue;
     147        if (PruneOnlyZeroImpactNodes) {
     148          if (!impactValue.IsAlmost(0.0)) continue;
     149        } else if (NodeImpactThreshold < impactValue) {
     150          continue;
     151        }
    138152
    139         var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue };
     153        var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();
     154        constantNode.Value = replacementValue;
     155
    140156        ReplaceWithConstant(node, constantNode);
    141157        i += node.GetLength() - 1; // skip subtrees under the node that was folded
     
    152168      return base.Apply();
    153169    }
     170
    154171    private static void ReplaceWithConstant(ISymbolicExpressionTreeNode original, ISymbolicExpressionTreeNode replacement) {
    155172      var parent = original.Parent;
     
    158175      parent.InsertSubtree(i, replacement);
    159176    }
    160     protected abstract ISymbolicDataAnalysisModel CreateModel();
    161     protected abstract double Evaluate(IDataAnalysisModel model);
    162177  }
    163178}
Note: See TracChangeset for help on using the changeset viewer.