Changeset 14232 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
- Timestamp:
- 08/03/16 18:54:14 (8 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r14185 r14232 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 36 37 [StorableConstructor] 37 38 protected SymbolicDataAnalysisSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 38 public abstract double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows);39 public abstract double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN);40 39 public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN); 41 40 42 protected static double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,41 protected IEnumerable<double> CalculateReplacementValues(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 43 42 IDataset dataset, IEnumerable<int> rows) { 44 43 //optimization: constant nodes return always the same value 45 44 ConstantTreeNode constantNode = node as ConstantTreeNode; 46 if (constantNode != null) return constantNode.Value; 45 FactorVariableTreeNode factorNode = node as FactorVariableTreeNode; 46 if (constantNode != null) { 47 yield return constantNode.Value; 48 } else if (factorNode != null) { 49 // valid replacements are either all off or all on 50 yield return 0; 51 yield return 1; 52 } else { 53 var rootSymbol = new ProgramRootSymbol().CreateTreeNode(); 54 var startSymbol = new StartSymbol().CreateTreeNode(); 55 rootSymbol.AddSubtree(startSymbol); 56 startSymbol.AddSubtree((ISymbolicExpressionTreeNode)node.Clone()); 47 57 48 var rootSymbol = new ProgramRootSymbol().CreateTreeNode(); 49 var startSymbol = new StartSymbol().CreateTreeNode(); 50 rootSymbol.AddSubtree(startSymbol); 51 startSymbol.AddSubtree((ISymbolicExpressionTreeNode)node.Clone()); 52 53 var tempTree = new SymbolicExpressionTree(rootSymbol); 54 // clone ADFs of source tree 55 for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) { 56 tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone()); 58 var tempTree = new SymbolicExpressionTree(rootSymbol); 59 // clone ADFs of source tree 60 for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) { 61 tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone()); 62 } 63 yield return interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Median(); 64 yield return interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Average(); // TODO perf 57 65 } 58 return interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Median();59 66 } 60 67 }
Note: See TracChangeset
for help on using the changeset viewer.