Changeset 12358
- Timestamp:
- 04/29/15 11:56:50 (9 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningAnalyzer.cs
r12189 r12358 29 29 [StorableClass] 30 30 public sealed class SymbolicClassificationPruningAnalyzer : SymbolicDataAnalysisSingleObjectivePruningAnalyzer { 31 private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";32 31 private const string PruningOperatorParameterName = "PruningOperator"; 33 p rivate SymbolicClassificationPruningAnalyzer(SymbolicClassificationPruningAnalyzer original, Cloner cloner)34 : base(original, cloner) {32 public IValueParameter<SymbolicClassificationPruningOperator> PruningOperatorParameter { 33 get { return (IValueParameter<SymbolicClassificationPruningOperator>)Parameters[PruningOperatorParameterName]; } 35 34 } 36 public override IDeepCloneable Clone(Cloner cloner) { 37 return new SymbolicClassificationPruningAnalyzer(this, cloner); 35 36 protected override SymbolicDataAnalysisExpressionPruningOperator PruningOperator { 37 get { return PruningOperatorParameter.Value; } 38 38 } 39 40 private SymbolicClassificationPruningAnalyzer(SymbolicClassificationPruningAnalyzer original, Cloner cloner) : base(original, cloner) { } 41 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicClassificationPruningAnalyzer(this, cloner); } 39 42 40 43 [StorableConstructor] … … 42 45 43 46 public SymbolicClassificationPruningAnalyzer() { 44 Parameters.Add(new ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, "The impact values calculator", new SymbolicClassificationSolutionImpactValuesCalculator()));45 47 Parameters.Add(new ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator()))); 46 48 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs
r12189 r12358 42 42 #endregion 43 43 44 protected SymbolicClassificationPruningOperator(SymbolicClassificationPruningOperator original, Cloner cloner) 45 : base(original, cloner) { 46 } 47 48 public override IDeepCloneable Clone(Cloner cloner) { 49 return new SymbolicClassificationPruningOperator(this, cloner); 50 } 44 protected SymbolicClassificationPruningOperator(SymbolicClassificationPruningOperator original, Cloner cloner) : base(original, cloner) { } 45 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicClassificationPruningOperator(this, cloner); } 51 46 52 47 [StorableConstructor] … … 68 63 protected override double Evaluate(IDataAnalysisModel model) { 69 64 var classificationModel = (IClassificationModel)model; 70 var classificationProblemData = (IClassificationProblemData)ProblemData ;71 var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);65 var classificationProblemData = (IClassificationProblemData)ProblemDataParameter.ActualValue; 66 var rows = Enumerable.Range(FitnessCalculationPartitionParameter.ActualValue.Start, FitnessCalculationPartitionParameter.ActualValue.Size); 72 67 73 return Evaluate(classificationModel, classificationProblemData, trainingIndices);68 return Evaluate(classificationModel, classificationProblemData, rows); 74 69 } 75 70 … … 100 95 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality); 101 96 102 if (pruneOnlyZeroImpactNodes) { 103 if (!impactValue.IsAlmost(0.0)) continue; 104 } else if (nodeImpactThreshold < impactValue) { 105 continue; 106 } 97 if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue; 98 if (!pruneOnlyZeroImpactNodes && impactValue > nodeImpactThreshold) continue; 107 99 108 100 var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningAnalyzer.cs
r12189 r12358 31 31 [StorableClass] 32 32 public sealed class SymbolicRegressionPruningAnalyzer : SymbolicDataAnalysisSingleObjectivePruningAnalyzer { 33 private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";34 33 private const string PruningOperatorParameterName = "PruningOperator"; 35 p rivate SymbolicRegressionPruningAnalyzer(SymbolicRegressionPruningAnalyzer original, Cloner cloner)36 : base(original, cloner) {34 public IValueParameter<SymbolicRegressionPruningOperator> PruningOperatorParameter { 35 get { return (IValueParameter<SymbolicRegressionPruningOperator>)Parameters[PruningOperatorParameterName]; } 37 36 } 38 public override IDeepCloneable Clone(Cloner cloner) { 39 return new SymbolicRegressionPruningAnalyzer(this, cloner); 37 38 protected override SymbolicDataAnalysisExpressionPruningOperator PruningOperator { 39 get { return PruningOperatorParameter.Value; } 40 40 } 41 42 private SymbolicRegressionPruningAnalyzer(SymbolicRegressionPruningAnalyzer original, Cloner cloner) : base(original, cloner) { } 43 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionPruningAnalyzer(this, cloner); } 41 44 42 45 [StorableConstructor] … … 44 47 45 48 public SymbolicRegressionPruningAnalyzer() { 46 Parameters.Add(new ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, "The impact values calculator", new SymbolicRegressionSolutionImpactValuesCalculator())); 47 Parameters.Add(new ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator()))); 49 Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator()))); 48 50 } 49 51 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs
r12189 r12358 53 53 protected override double Evaluate(IDataAnalysisModel model) { 54 54 var regressionModel = (IRegressionModel)model; 55 var regressionProblemData = (IRegressionProblemData)ProblemData ;56 var rows = Enumerable.Range(FitnessCalculationPartition .Start, FitnessCalculationPartition.Size);55 var regressionProblemData = (IRegressionProblemData)ProblemDataParameter.ActualValue; 56 var rows = Enumerable.Range(FitnessCalculationPartitionParameter.ActualValue.Start, FitnessCalculationPartitionParameter.ActualValue.Size); 57 57 return Evaluate(regressionModel, regressionProblemData, rows); 58 58 } … … 81 81 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality); 82 82 83 if (pruneOnlyZeroImpactNodes) { 84 if (!impactValue.IsAlmost(0.0)) continue; 85 } else if (nodeImpactThreshold < impactValue) { 86 continue; 87 } 83 if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue; 84 if (!pruneOnlyZeroImpactNodes && impactValue > nodeImpactThreshold) continue; 88 85 89 86 var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode(); -
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.