Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/04/15 13:08:49 (10 years ago)
Author:
gkronber
Message:

Merged revision(s) 12333-12365 from trunk/sources:
#2373: Corrected typo in RandomBinaryVectorCreator by implementing an after-deserialization-hook.

........
#2359: Refactored pruning operators and analyzers.

........
#2359: Removed commented code from pruning analyzer.

........
#2378: Vertex.cs: Fixed bug in Label setter.
........
#2359: The changes in r12358 look fine to me. Added total number of pruned nodes in the analyzer's data table. Removed unused parameter names in the SymbolicDataAnalysisSingleObjectivePruningAnalyzer.
........
#2345: Fixed x-axis maximum in error characteristics curve.

........

Location:
branches/GBT
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/GBT

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

  • branches/GBT/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs

    r12012 r12378  
    4545    private const string TotalNumberOfPrunedSubtreesParameterName = "Number of pruned subtrees";
    4646    private const string TotalNumberOfPrunedTreesParameterName = "Number of pruned trees";
     47    private const string TotalNumberOfPrunedNodesParameterName = "Number of pruned nodes";
    4748    private const string RandomParameterName = "Random";
    48     private const string PruneOnlyZeroImpactNodesParameterName = "PruneOnlyZeroImpactNodes";
    49     private const string NodeImpactThresholdParameterName = "ImpactThreshold";
    50     private const string PruningOperatorParameterName = "PruningOperator";
    5149    private const string ResultsParameterName = "Results";
    5250    private const string PopulationSizeParameterName = "PopulationSize";
     
    5452
    5553    #region private members
     54    private DataReducer prunedNodesReducer;
    5655    private DataReducer prunedSubtreesReducer;
    5756    private DataReducer prunedTreesReducer;
     
    6160
    6261    #region parameter properties
    63     public IValueParameter<SymbolicDataAnalysisExpressionPruningOperator> PruningOperatorParameter {
    64       get { return (IValueParameter<SymbolicDataAnalysisExpressionPruningOperator>)Parameters[PruningOperatorParameterName]; }
    65     }
    66     public IFixedValueParameter<BoolValue> PruneOnlyZeroImpactNodesParameter {
    67       get { return (IFixedValueParameter<BoolValue>)Parameters[PruneOnlyZeroImpactNodesParameterName]; }
    68     }
    69     public IFixedValueParameter<DoubleValue> NodeImpactThresholdParameter {
    70       get { return (IFixedValueParameter<DoubleValue>)Parameters[NodeImpactThresholdParameterName]; }
    71     }
    7262    public ILookupParameter<IRandom> RandomParameter {
    7363      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
     
    9181
    9282    #region properties
    93     protected SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get { return PruningOperatorParameter.Value; } }
     83    protected abstract SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get; }
    9484    protected int UpdateInterval { get { return UpdateIntervalParameter.Value.Value; } }
    9585
     
    112102      get { return PruningProbabilityParameter.Value.Value; }
    113103      set { PruningProbabilityParameter.Value.Value = value; }
    114     }
    115 
    116     protected bool PruneOnlyZeroImpactNodes {
    117       get { return PruneOnlyZeroImpactNodesParameter.Value.Value; }
    118       set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; }
    119     }
    120     protected double NodeImpactThreshold {
    121       get { return NodeImpactThresholdParameter.Value.Value; }
    122       set { NodeImpactThresholdParameter.Value.Value = value; }
    123104    }
    124105    #endregion
     
    140121    protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(SymbolicDataAnalysisSingleObjectivePruningAnalyzer original, Cloner cloner)
    141122      : base(original, cloner) {
     123      if (original.prunedNodesReducer != null)
     124        this.prunedNodesReducer = (DataReducer)original.prunedNodesReducer.Clone();
    142125      if (original.prunedSubtreesReducer != null)
    143126        this.prunedSubtreesReducer = (DataReducer)original.prunedSubtreesReducer.Clone();
     
    197180      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random number generator."));
    198181      Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data."));
    199       Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, "The impact threshold  below which an individual should be pruned.", new DoubleValue(0.0)));
    200       Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, "Switch to determine of only zero impact individuals should be pruned.", new BoolValue(false)));
    201182      Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals."));
    202183      #endregion
     
    250231      UpdateCounter = 0;
    251232
    252       if (prunedSubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); }
     233      if (prunedNodesReducer == null || prunedSubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); }
    253234
    254235      var prune = CreatePruningOperation();
     236      var reducePrunedNodes = ExecutionContext.CreateChildOperation(prunedNodesReducer);
    255237      var reducePrunedSubtrees = ExecutionContext.CreateChildOperation(prunedSubtreesReducer);
    256238      var reducePrunedTrees = ExecutionContext.CreateChildOperation(prunedTreesReducer);
     
    258240      var collectResults = ExecutionContext.CreateChildOperation(resultsCollector);
    259241
    260       return new OperationCollection { prune, reducePrunedSubtrees, reducePrunedTrees, collectValues, collectResults, base.Apply() };
     242      return new OperationCollection { prune, reducePrunedNodes, reducePrunedSubtrees, reducePrunedTrees, collectValues, collectResults, base.Apply() };
    261243    }
    262244
    263245    private void InitializeOperators() {
     246      prunedNodesReducer = new DataReducer();
     247      prunedNodesReducer.ParameterToReduce.ActualName = PruningOperator.PrunedNodesParameter.ActualName;
     248      prunedNodesReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); // sum all the pruned subtrees parameter values
     249      prunedNodesReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); // asign the sum to the target parameter
     250      prunedNodesReducer.TargetParameter.ActualName = TotalNumberOfPrunedNodesParameterName;
     251
    264252      prunedSubtreesReducer = new DataReducer();
    265253      prunedSubtreesReducer.ParameterToReduce.ActualName = PruningOperator.PrunedSubtreesParameter.ActualName;
     
    275263
    276264      valuesCollector = new DataTableValuesCollector();
     265      valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedNodesParameterName));
    277266      valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedSubtreesParameterName));
    278267      valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedTreesParameterName));
  • branches/GBT/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs

    r12189 r12378  
    3434  [StorableClass]
    3535  [Item("SymbolicExpressionTreePruningOperator", "An operator that replaces introns with constant values in a symbolic expression tree.")]
    36   public abstract class SymbolicDataAnalysisExpressionPruningOperator : SingleSuccessorOperator {
     36  public abstract class SymbolicDataAnalysisExpressionPruningOperator : SingleSuccessorOperator, ISymbolicExpressionTreeOperator {
    3737    #region parameter names
    3838    private const string ProblemDataParameterName = "ProblemData";
     
    4141    private const string PrunedSubtreesParameterName = "PrunedSubtrees";
    4242    private const string PrunedTreesParameterName = "PrunedTrees";
     43    private const string PrunedNodesParameterName = "PrunedNodes";
    4344    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
    4445    private const string NodeImpactThresholdParameterName = "ImpactThreshold";
     
    7273      get { return (ILookupParameter<IntValue>)Parameters[PrunedTreesParameterName]; }
    7374    }
     75    public ILookupParameter<IntValue> PrunedNodesParameter {
     76      get { return (ILookupParameter<IntValue>)Parameters[PrunedNodesParameterName]; }
     77    }
    7478    public IFixedValueParameter<DoubleValue> NodeImpactThresholdParameter {
    7579      get { return (IFixedValueParameter<DoubleValue>)Parameters[NodeImpactThresholdParameterName]; }
     
    8791
    8892    #region properties
    89     protected IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } }
    90     protected ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator { get { return ImpactValuesCalculatorParameter.Value; } }
    91     protected IntRange FitnessCalculationPartition { get { return FitnessCalculationPartitionParameter.ActualValue; } }
    92     protected bool PruneOnlyZeroImpactNodes {
     93    public ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator {
     94      get { return ImpactValuesCalculatorParameter.Value; }
     95      set { ImpactValuesCalculatorParameter.Value = value; }
     96    }
     97    public bool PruneOnlyZeroImpactNodes {
    9398      get { return PruneOnlyZeroImpactNodesParameter.Value.Value; }
    9499      set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; }
    95100    }
    96     protected double NodeImpactThreshold {
     101    public double NodeImpactThreshold {
    97102      get { return NodeImpactThresholdParameter.Value.Value; }
    98103      set { NodeImpactThresholdParameter.Value.Value = value; }
    99104    }
    100     protected ISymbolicExpressionTree SymbolicExpressionTree { get { return SymbolicExpressionTreeParameter.ActualValue; } }
    101     protected DoubleValue Quality { get { return QualityParameter.ActualValue; } }
    102     protected DoubleLimit EstimationLimits { get { return EstimationLimitsParameter.ActualValue; } }
    103     protected ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get { return InterpreterParameter.ActualValue; } }
    104105    #endregion
    105106
     
    114115      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisModel>(SymbolicDataAnalysisModelParameterName));
    115116      Parameters.Add(new LookupParameter<IntRange>(FitnessCalculationPartitionParameterName));
     117      Parameters.Add(new LookupParameter<IntValue>(PrunedNodesParameterName, "A counter of how many nodes were pruned."));
    116118      Parameters.Add(new LookupParameter<IntValue>(PrunedSubtreesParameterName, "A counter of how many subtrees were replaced."));
    117119      Parameters.Add(new LookupParameter<IntValue>(PrunedTreesParameterName, "A counter of how many trees were pruned."));
     
    131133
    132134    public override IOperation Apply() {
    133       var model = CreateModel(SymbolicExpressionTree, Interpreter, ProblemData, EstimationLimits);
    134       var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
    135       var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
     135      var tree = SymbolicExpressionTreeParameter.ActualValue;
     136      var problemData = ProblemDataParameter.ActualValue;
     137      var fitnessCalculationPartition = FitnessCalculationPartitionParameter.ActualValue;
     138      var estimationLimits = EstimationLimitsParameter.ActualValue;
     139      var interpreter = InterpreterParameter.ActualValue;
     140
     141      var model = CreateModel(tree, interpreter, problemData, estimationLimits);
     142      var nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
     143      var rows = Enumerable.Range(fitnessCalculationPartition.Start, fitnessCalculationPartition.Size);
    136144      var prunedSubtrees = 0;
    137145      var prunedTrees = 0;
     146      var prunedNodes = 0;
    138147
    139148      double quality = Evaluate(model);
     
    144153
    145154        double impactValue, replacementValue;
    146         ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality);
     155        ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality);
    147156
    148         if (PruneOnlyZeroImpactNodes) {
    149           if (!impactValue.IsAlmost(0.0)) continue;
    150         } else if (NodeImpactThreshold < impactValue) {
    151           continue;
    152         }
     157        if (PruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue;
     158        if (!PruneOnlyZeroImpactNodes && impactValue > NodeImpactThreshold) continue;
    153159
    154160        var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();
    155161        constantNode.Value = replacementValue;
    156162
     163        var length = node.GetLength();
    157164        ReplaceWithConstant(node, constantNode);
    158         i += node.GetLength() - 1; // skip subtrees under the node that was folded
     165        i += length - 1; // skip subtrees under the node that was folded
    159166
    160167        quality -= impactValue;
    161 
    162168        prunedSubtrees++;
     169        prunedNodes += length;
    163170      }
    164171
     
    166173      PrunedSubtreesParameter.ActualValue = new IntValue(prunedSubtrees);
    167174      PrunedTreesParameter.ActualValue = new IntValue(prunedTrees);
     175      PrunedNodesParameter.ActualValue = new IntValue(prunedNodes);
     176      QualityParameter.ActualValue.Value = quality;
    168177
    169178      return base.Apply();
    170     }
    171 
    172     public ISymbolicExpressionTree Prune(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {
    173       var model = CreateModel((ISymbolicExpressionTree)tree.Clone(), Interpreter, ProblemData, EstimationLimits);
    174       var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
    175       var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
    176 
    177       double quality = Evaluate(model);
    178 
    179       for (int i = 0; i < nodes.Count; ++i) {
    180         var node = nodes[i];
    181         if (node is ConstantTreeNode) continue;
    182 
    183         double impactValue, replacementValue;
    184         ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality);
    185 
    186         if (PruneOnlyZeroImpactNodes) {
    187           if (!impactValue.IsAlmost(0.0)) continue;
    188         } else if (NodeImpactThreshold < impactValue) {
    189           continue;
    190         }
    191 
    192         var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();
    193         constantNode.Value = replacementValue;
    194 
    195         ReplaceWithConstant(node, constantNode);
    196         i += node.GetLength() - 1; // skip subtrees under the node that was folded
    197 
    198         quality -= impactValue;
    199       }
    200       return model.SymbolicExpressionTree;
    201179    }
    202180
Note: See TracChangeset for help on using the changeset viewer.