- Timestamp:
- 04/29/15 11:56:50 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs
r12012 r12358 61 61 62 62 #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 }72 63 public ILookupParameter<IRandom> RandomParameter { 73 64 get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; } … … 91 82 92 83 #region properties 93 protected SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get { return PruningOperatorParameter.Value; }}84 protected abstract SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get; } 94 85 protected int UpdateInterval { get { return UpdateIntervalParameter.Value.Value; } } 95 86 … … 112 103 get { return PruningProbabilityParameter.Value.Value; } 113 104 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; }123 105 } 124 106 #endregion … … 197 179 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random number generator.")); 198 180 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)));201 181 Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals.")); 202 182 #endregion -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs
r12189 r12358 34 34 [StorableClass] 35 35 [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 { 37 37 #region parameter names 38 38 private const string ProblemDataParameterName = "ProblemData"; … … 87 87 88 88 #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 { 89 public ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator { 90 get { return ImpactValuesCalculatorParameter.Value; } 91 set { ImpactValuesCalculatorParameter.Value = value; } 92 } 93 public bool PruneOnlyZeroImpactNodes { 93 94 get { return PruneOnlyZeroImpactNodesParameter.Value.Value; } 94 95 set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; } 95 96 } 96 p rotecteddouble NodeImpactThreshold {97 public double NodeImpactThreshold { 97 98 get { return NodeImpactThresholdParameter.Value.Value; } 98 99 set { NodeImpactThresholdParameter.Value.Value = value; } 99 100 } 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; } }104 101 #endregion 105 102 … … 131 128 132 129 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); 130 var tree = SymbolicExpressionTreeParameter.ActualValue; 131 var problemData = ProblemDataParameter.ActualValue; 132 var fitnessCalculationPartition = FitnessCalculationPartitionParameter.ActualValue; 133 var estimationLimits = EstimationLimitsParameter.ActualValue; 134 var interpreter = InterpreterParameter.ActualValue; 135 136 var model = CreateModel(tree, interpreter, problemData, estimationLimits); 137 var nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); 138 var rows = Enumerable.Range(fitnessCalculationPartition.Start, fitnessCalculationPartition.Size); 136 139 var prunedSubtrees = 0; 137 140 var prunedTrees = 0; … … 144 147 145 148 double impactValue, replacementValue; 146 ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality); 147 148 if (PruneOnlyZeroImpactNodes) { 149 if (!impactValue.IsAlmost(0.0)) continue; 150 } else if (NodeImpactThreshold < impactValue) { 151 continue; 152 } 149 ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality); 150 151 if (PruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue; 152 if (!PruneOnlyZeroImpactNodes && impactValue > NodeImpactThreshold) continue; 153 153 154 154 var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode(); … … 159 159 160 160 quality -= impactValue; 161 162 161 prunedSubtrees++; 163 162 } … … 166 165 PrunedSubtreesParameter.ActualValue = new IntValue(prunedSubtrees); 167 166 PrunedTreesParameter.ActualValue = new IntValue(prunedTrees); 167 QualityParameter.ActualValue.Value = quality; 168 168 169 169 return base.Apply(); 170 170 } 171 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 folded197 198 quality -= impactValue;199 }200 return model.SymbolicExpressionTree;201 }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 = tree.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; 201 //} 202 202 203 203 protected static void ReplaceWithConstant(ISymbolicExpressionTreeNode original, ISymbolicExpressionTreeNode replacement) {
Note: See TracChangeset
for help on using the changeset viewer.