Changeset 11883 for branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective
- Timestamp:
- 02/04/15 11:16:41 (10 years ago)
- Location:
- branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective
- Files:
-
- 2 edited
- 1 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNestedTreeSizeEvaluator.cs
r11882 r11883 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 … … 31 32 [Item("Pearson R² & Nested Tree size Evaluator", "Calculates the Pearson R² and the nested tree size of a symbolic regression solution.")] 32 33 [StorableClass] 33 public class SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 34 public class PearsonRSquaredNestedTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 35 private const string useConstantOptimizationParameterName = "Use constant optimization"; 36 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter { 37 get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; } 38 } 39 public bool UseConstantOptimization { 40 get { return UseConstantOptimizationParameter.Value.Value; } 41 set { UseConstantOptimizationParameter.Value.Value = value; } 42 } 43 34 44 [StorableConstructor] 35 protected SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(bool deserializing) : base(deserializing) { }36 protected SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator original, Cloner cloner)45 protected PearsonRSquaredNestedTreeSizeEvaluator(bool deserializing) : base(deserializing) { } 46 protected PearsonRSquaredNestedTreeSizeEvaluator(PearsonRSquaredNestedTreeSizeEvaluator original, Cloner cloner) 37 47 : base(original, cloner) { 38 48 } 39 49 public override IDeepCloneable Clone(Cloner cloner) { 40 return new SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(this, cloner);50 return new PearsonRSquaredNestedTreeSizeEvaluator(this, cloner); 41 51 } 42 52 43 public SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator() : base() { } 53 public PearsonRSquaredNestedTreeSizeEvaluator() 54 : base() { 55 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 56 } 44 57 45 58 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } … … 48 61 IEnumerable<int> rows = GenerateRowsToEvaluate(); 49 62 var solution = SymbolicExpressionTreeParameter.ActualValue; 63 var problemData = ProblemDataParameter.ActualValue; 64 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 65 var estimationLimits = EstimationLimitsParameter.ActualValue; 66 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 67 68 if (UseConstantOptimization) { 69 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower); 70 } 71 50 72 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 51 73 QualitiesParameter.ActualValue = new DoubleArray(qualities); -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNumberofVariablesEvaluator.cs
r11861 r11883 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 30 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 31 [Item("Pearson R² & N ested Tree size Evaluator", "Calculates the Pearson R² and the nested tree sizeof a symbolic regression solution.")]32 [Item("Pearson R² & Number of Variables Evaluator", "Calculates the Pearson R² and the number of used variables of a symbolic regression solution.")] 32 33 [StorableClass] 33 public class SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 34 public class PearsonRSquaredNumberOfVariablesEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 35 private const string useConstantOptimizationParameterName = "Use constant optimization"; 36 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter { 37 get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; } 38 } 39 public bool UseConstantOptimization { 40 get { return UseConstantOptimizationParameter.Value.Value; } 41 set { UseConstantOptimizationParameter.Value.Value = value; } 42 } 43 34 44 [StorableConstructor] 35 protected SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(bool deserializing) : base(deserializing) { }36 protected SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator original, Cloner cloner)45 protected PearsonRSquaredNumberOfVariablesEvaluator(bool deserializing) : base(deserializing) { } 46 protected PearsonRSquaredNumberOfVariablesEvaluator(PearsonRSquaredNumberOfVariablesEvaluator original, Cloner cloner) 37 47 : base(original, cloner) { 38 48 } 39 49 public override IDeepCloneable Clone(Cloner cloner) { 40 return new SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(this, cloner);50 return new PearsonRSquaredNumberOfVariablesEvaluator(this, cloner); 41 51 } 42 52 43 public SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator() : base() { } 53 public PearsonRSquaredNumberOfVariablesEvaluator() 54 : base() { 55 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 56 } 44 57 45 58 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } … … 48 61 IEnumerable<int> rows = GenerateRowsToEvaluate(); 49 62 var solution = SymbolicExpressionTreeParameter.ActualValue; 63 var problemData = ProblemDataParameter.ActualValue; 64 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 65 var estimationLimits = EstimationLimitsParameter.ActualValue; 66 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 67 68 if (UseConstantOptimization) { 69 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower); 70 } 50 71 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 51 72 QualitiesParameter.ActualValue = new DoubleArray(qualities); … … 55 76 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 56 77 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 57 return new double[2] { r2, solution.IterateNodesPostfix(). Sum(n => n.GetLength()) };78 return new double[2] { r2, solution.IterateNodesPostfix().OfType<VariableTreeNode>().Count() }; 58 79 } 59 80 -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredTreeComplexityEvaluator.cs
r11861 r11883 31 31 [Item("Pearson R² & Tree Complexity Evaluator", "Calculates the Pearson R² and the tree complexity of a symbolic regression solution.")] 32 32 [StorableClass] 33 public class SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 34 private string useConstantOptimizationParameterName = "Use constant optimization"; 35 33 public class PearsonRSquaredTreeComplexityEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 34 private const string useConstantOptimizationParameterName = "Use constant optimization"; 36 35 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter { 37 36 get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; } 38 37 } 39 40 38 public bool UseConstantOptimization { 41 39 get { return UseConstantOptimizationParameter.Value.Value; } … … 44 42 45 43 [StorableConstructor] 46 protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator(bool deserializing) : base(deserializing) { }47 protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator(SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator original, Cloner cloner)44 protected PearsonRSquaredTreeComplexityEvaluator(bool deserializing) : base(deserializing) { } 45 protected PearsonRSquaredTreeComplexityEvaluator(PearsonRSquaredTreeComplexityEvaluator original, Cloner cloner) 48 46 : base(original, cloner) { 49 47 } 50 48 public override IDeepCloneable Clone(Cloner cloner) { 51 return new SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator(this, cloner);49 return new PearsonRSquaredTreeComplexityEvaluator(this, cloner); 52 50 } 53 51 54 public SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator()52 public PearsonRSquaredTreeComplexityEvaluator() 55 53 : base() { 56 54 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 57 58 55 } 59 56 -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r11310 r11883 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 … … 31 32 [StorableClass] 32 33 public class SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 34 private const string useConstantOptimizationParameterName = "Use constant optimization"; 35 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter { 36 get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; } 37 } 38 public bool UseConstantOptimization { 39 get { return UseConstantOptimizationParameter.Value.Value; } 40 set { UseConstantOptimizationParameter.Value.Value = value; } 41 } 42 33 43 [StorableConstructor] 34 44 protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(bool deserializing) : base(deserializing) { } … … 40 50 } 41 51 42 public SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base() { } 52 public SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base() 53 { 54 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 55 } 56 57 [StorableHook(HookType.AfterDeserialization)] 58 private void AfterDeserialization() { 59 if (!Parameters.ContainsKey(useConstantOptimizationParameterName)) { 60 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 61 } 62 } 43 63 44 64 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } … … 47 67 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 68 var solution = SymbolicExpressionTreeParameter.ActualValue; 69 var problemData = ProblemDataParameter.ActualValue; 70 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 71 var estimationLimits = EstimationLimitsParameter.ActualValue; 72 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 73 74 if (UseConstantOptimization) { 75 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower); 76 } 49 77 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 78 QualitiesParameter.ActualValue = new DoubleArray(qualities); -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs
r11310 r11883 109 109 } 110 110 111 var problemData = ProblemDataParameter.ActualValue;112 var constantValue = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).Average();113 var constantSolution = CreateConstantSymbolicRegressionSolution(constantValue);114 111 115 int previousTreeLength = constantSolution.Model.SymbolicExpressionTree.Length;112 int previousTreeLength = -1; 116 113 var sizeParetoFront = new LinkedList<ISymbolicRegressionSolution>(); 117 sizeParetoFront.AddLast(constantSolution);118 119 114 foreach (var solution in paretoFront.OrderBy(s => s.Model.SymbolicExpressionTree.Length)) { 120 115 int treeLength = solution.Model.SymbolicExpressionTree.Length; … … 136 131 qualityToTreeSize.Rows.Add(testRow); 137 132 138 double training HyperVolume, testHyperVolume;139 CalculateNormalizedHyperVolume(sizeParetoFront, out trainingHyperVolume, out testHyperVolume);133 double trainingArea = sizeParetoFront.Select(s => s.Model.SymbolicExpressionTree.Length * s.TrainingNormalizedMeanSquaredError).Average(); 134 double testArea = sizeParetoFront.Select(s => s.Model.SymbolicExpressionTree.Length * s.TestNormalizedMeanSquaredError).Average(); 140 135 141 DoubleValue trainingHyperVolumeResult, testHyperVolumeResult;142 if (!ResultCollection.TryGetValue(" HyperVolume training", out result)) {143 trainingHyperVolumeResult = new DoubleValue();144 ResultCollection.Add(new Result(" HyperVolume training", trainingHyperVolumeResult));145 } else trainingHyperVolumeResult = (DoubleValue)result.Value;136 ResultCollection paretoFrontResults; 137 if (!ResultCollection.TryGetValue("Pareto Front Results", out result)) { 138 paretoFrontResults = new ResultCollection(); 139 ResultCollection.Add(new Result("Pareto Front Results", paretoFrontResults)); 140 } else paretoFrontResults = (ResultCollection)result.Value; 146 141 147 if (!ResultCollection.TryGetValue("HyperVolume test", out result)) { 148 testHyperVolumeResult = new DoubleValue(); 149 ResultCollection.Add(new Result("HyperVolume test", testHyperVolumeResult)); 150 } else testHyperVolumeResult = (DoubleValue)result.Value; 142 DoubleValue trainingAreaResult, testAreaResult, areaDifferenceResult, avgTrainingNMSE, avgTestNMSE; 143 if (!paretoFrontResults.TryGetValue("Non Dominated Area (training)", out result)) { 144 trainingAreaResult = new DoubleValue(); 145 paretoFrontResults.Add(new Result("Non Dominated Area (training)", trainingAreaResult)); 146 } else trainingAreaResult = (DoubleValue)result.Value; 147 if (!paretoFrontResults.TryGetValue("Non Dominated Area (test)", out result)) { 148 testAreaResult = new DoubleValue(); 149 paretoFrontResults.Add(new Result("Non Dominated Area (test)", testAreaResult)); 150 } else testAreaResult = (DoubleValue)result.Value; 151 if (!paretoFrontResults.TryGetValue("Non Dominated Area Difference", out result)) { 152 areaDifferenceResult = new DoubleValue(); 153 paretoFrontResults.Add(new Result("Non Dominated Area Difference", areaDifferenceResult)); 154 } else areaDifferenceResult = (DoubleValue)result.Value; 155 if (!paretoFrontResults.TryGetValue("Average Training NMSE", out result)) { 156 avgTrainingNMSE = new DoubleValue(); 157 paretoFrontResults.Add(new Result("Average Training NMSE", avgTrainingNMSE)); 158 } else avgTrainingNMSE = (DoubleValue)result.Value; 159 if (!paretoFrontResults.TryGetValue("Average Test NMSE", out result)) { 160 avgTestNMSE = new DoubleValue(); 161 paretoFrontResults.Add(new Result("Average Test NMSE", avgTestNMSE)); 162 } else avgTestNMSE = (DoubleValue)result.Value; 151 163 152 trainingHyperVolumeResult.Value = trainingHyperVolume; 153 testHyperVolumeResult.Value = testHyperVolume; 164 trainingAreaResult.Value = trainingArea; 165 testAreaResult.Value = testArea; 166 areaDifferenceResult.Value = trainingArea - testArea; 167 avgTrainingNMSE.Value = sizeParetoFront.Select(s => s.TrainingNormalizedMeanSquaredError).Average(); 168 avgTestNMSE.Value = sizeParetoFront.Select(s => s.TestNormalizedMeanSquaredError).Average(); 154 169 155 170 return operation; 156 171 } 157 172 158 private void CalculateNormalizedHyperVolume(IEnumerable<ISymbolicRegressionSolution> solutions, out double trainingHyperVolume, out double testHyperVolume) {159 trainingHyperVolume = 0.0;160 testHyperVolume = 0.0;161 162 var prevX = 0;163 var prevYTraining = 1.0;164 var prevYTest = 1.0;165 var treeSize = 0;166 167 foreach (var solution in solutions) {168 treeSize = solution.Model.SymbolicExpressionTree.Length;169 trainingHyperVolume += (prevYTraining + solution.TrainingNormalizedMeanSquaredError) * (treeSize - prevX) / 2;170 testHyperVolume += (prevYTest + solution.TestNormalizedMeanSquaredError) * (treeSize - prevX) / 2;171 prevX = treeSize;172 prevYTraining = solution.TrainingNormalizedMeanSquaredError;173 prevYTest = solution.TestNormalizedMeanSquaredError;174 }175 176 trainingHyperVolume = trainingHyperVolume / treeSize;177 testHyperVolume = testHyperVolume / treeSize;178 }179 180 private ISymbolicRegressionSolution CreateConstantSymbolicRegressionSolution(double constantValue) {181 var grammar = new ArithmeticExpressionGrammar();182 var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();183 var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode();184 var constantTreeNode = new ConstantTreeNode(new Constant()) { Value = constantValue };185 rootNode.AddSubtree(startNode);186 startNode.AddSubtree(constantTreeNode);187 var tree = new SymbolicExpressionTree();188 tree.Root = rootNode;189 190 var model = new SymbolicRegressionModel(tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue);191 var solution = new SymbolicRegressionSolution(model, ProblemDataParameter.ActualValue);192 return solution;193 }194 173 } 195 174 }
Note: See TracChangeset
for help on using the changeset viewer.