Changeset 12247 for branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 03/24/15 11:17:08 (10 years ago)
- Location:
- branches/HeuristicLab.DatasetRefactor/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DatasetRefactor/sources
- Property svn:mergeinfo changed
-
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Symbolic
-
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs
r12031 r12247 109 109 : base(original, cloner) { } 110 110 111 protected SymbolicDataAnalysisExpressionPruningOperator( ) {111 protected SymbolicDataAnalysisExpressionPruningOperator(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactValuesCalculator) { 112 112 #region add parameters 113 113 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName)); … … 122 122 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName)); 123 123 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName)); 124 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, impactValuesCalculator)); 124 125 #endregion 125 126 } 126 127 127 protected abstract ISymbolicDataAnalysisModel CreateModel( );128 protected abstract ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits); 128 129 129 130 protected abstract double Evaluate(IDataAnalysisModel model); 130 131 131 132 public override IOperation Apply() { 132 var model = CreateModel( );133 var model = CreateModel(SymbolicExpressionTree, Interpreter, ProblemData, EstimationLimits); 133 134 var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); 134 135 var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size); … … 169 170 } 170 171 171 private static void ReplaceWithConstant(ISymbolicExpressionTreeNode original, ISymbolicExpressionTreeNode replacement) { 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; 201 } 202 203 protected static void ReplaceWithConstant(ISymbolicExpressionTreeNode original, ISymbolicExpressionTreeNode replacement) { 172 204 var parent = original.Parent; 173 205 var i = parent.IndexOfSubtree(original); -
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r12031 r12247 299 299 // simplify expressions x0..xn 300 300 // make multiplication (x0 * 1/(x1 * x1 * .. * xn)) 301 var simplifiedTrees = original.Subtrees.Select( x => GetSimplifiedTree(x));301 var simplifiedTrees = original.Subtrees.Select(GetSimplifiedTree).ToArray(); 302 302 return 303 MakeProduct(simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate( (a, b) => MakeProduct(a, b))));303 MakeProduct(simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate(MakeProduct))); 304 304 } 305 305 } … … 310 310 } else { 311 311 return original.Subtrees 312 .Select( x => GetSimplifiedTree(x))313 .Aggregate( (a, b) => MakeProduct(a, b));312 .Select(GetSimplifiedTree).ToArray() 313 .Aggregate(MakeProduct); 314 314 } 315 315 } … … 321 321 // simplify expressions x0..xn 322 322 // make addition (x0,-x1..-xn) 323 var simplifiedTrees = original.Subtrees.Select( x => GetSimplifiedTree(x));323 var simplifiedTrees = original.Subtrees.Select(GetSimplifiedTree).ToArray(); 324 324 return simplifiedTrees.Take(1) 325 .Concat(simplifiedTrees.Skip(1).Select( x => Negate(x)))326 .Aggregate( (a, b) => MakeSum(a, b));325 .Concat(simplifiedTrees.Skip(1).Select(Negate)) 326 .Aggregate(MakeSum); 327 327 } 328 328 } … … 335 335 // make addition (x0..xn) 336 336 return original.Subtrees 337 .Select( x => GetSimplifiedTree(x))338 .Aggregate( (a, b) => MakeSum(a, b));337 .Select(GetSimplifiedTree).ToArray() 338 .Aggregate(MakeSum); 339 339 } 340 340 }
Note: See TracChangeset
for help on using the changeset viewer.