Changeset 16140 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
- Timestamp:
- 09/14/18 11:36:59 (6 years ago)
- Location:
- branches/2817-BinPackingSpeedup
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r14826 r16140 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 32 32 public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator : Item, ISymbolicDataAnalysisSolutionImpactValuesCalculator { 33 33 protected SymbolicDataAnalysisSolutionImpactValuesCalculator() { } 34 35 34 protected SymbolicDataAnalysisSolutionImpactValuesCalculator(SymbolicDataAnalysisSolutionImpactValuesCalculator original, Cloner cloner) 36 35 : base(original, cloner) { } 37 36 [StorableConstructor] 38 37 protected SymbolicDataAnalysisSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 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); 38 39 public virtual void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, 40 out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, 41 double qualityForImpactsCalculation = double.NaN) { 42 if (double.IsNaN(qualityForImpactsCalculation)) 43 qualityForImpactsCalculation = CalculateQualityForImpacts(model, problemData, rows); 44 45 var cloner = new Cloner(); 46 var tempModel = cloner.Clone(model); 47 var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node); 48 49 var tempModelParentNode = tempModelNode.Parent; 50 int i = tempModelParentNode.IndexOfSubtree(tempModelNode); 51 52 double bestReplacementValue = 0.0; 53 double bestImpactValue = double.PositiveInfinity; 54 newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize 55 // try the potentially reasonable replacement values and use the best one 56 foreach (var repValue in CalculateReplacementValues(node, model.SymbolicExpressionTree, model.Interpreter, problemData.Dataset, problemData.TrainingIndices)) { 57 tempModelParentNode.RemoveSubtree(i); 58 59 var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue }; 60 tempModelParentNode.InsertSubtree(i, constantNode); 61 62 newQualityForImpactsCalculation = CalculateQualityForImpacts(tempModel, problemData, rows); 63 64 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation; 65 if (impactValue < bestImpactValue) { 66 bestImpactValue = impactValue; 67 bestReplacementValue = repValue; 68 } 69 } 70 71 replacementValue = bestReplacementValue; 72 impactValue = bestImpactValue; 73 } 74 75 protected abstract double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows); 40 76 41 77 protected IEnumerable<double> CalculateReplacementValues(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
Note: See TracChangeset
for help on using the changeset viewer.