- Timestamp:
- 12/02/21 17:23:10 (3 years ago)
- Location:
- branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionSingleObjectiveEvaluator.cs
r18095 r18103 28 28 public interface ISymbolicRegressionSingleObjectiveEvaluator : ISymbolicRegressionEvaluator, ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData> { 29 29 double Evaluate( 30 I RegressionProblemData problemData,31 I SymbolicExpressionTree tree,32 I SymbolicDataAnalysisExpressionTreeInterpreter interpreter,33 I Enumerable<int> rows = null,30 ISymbolicExpressionTree tree, 31 IRegressionProblemData problemData, 32 IEnumerable<int> rows, 33 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 34 34 bool applyLinearScaling = true, 35 35 double lowerEstimationLimit = double.MinValue, -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredAverageSimilarityEvaluator.cs
r17180 r18103 70 70 public override IOperation InstrumentedApply() { 71 71 IEnumerable<int> rows = GenerateRowsToEvaluate(); 72 var solution= SymbolicExpressionTreeParameter.ActualValue;72 var tree = SymbolicExpressionTreeParameter.ActualValue; 73 73 var problemData = ProblemDataParameter.ActualValue; 74 74 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; … … 77 77 78 78 if (UseConstantOptimization) { 79 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper);79 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper); 80 80 } 81 81 82 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling); 82 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 83 tree, problemData, rows, interpreter, applyLinearScaling, 84 estimationLimits.Lower, estimationLimits.Upper); 83 85 84 86 if (DecimalPlaces >= 0) … … 107 109 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 108 110 109 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling); 111 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 112 tree, problemData, rows, 113 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 114 applyLinearScaling, 115 estimationLimits.Lower, estimationLimits.Upper); 110 116 111 117 lock (locker) { -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNestedTreeSizeEvaluator.cs
r17180 r18103 63 63 } 64 64 65 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 66 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 65 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 66 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 67 tree, problemData, rows, 68 interpreter, applyLinearScaling, 69 lowerEstimationLimit, upperEstimationLimit); 67 70 if (decimalPlaces >= 0) 68 71 r2 = Math.Round(r2, decimalPlaces); 69 return new double[2] { r2, solution.IterateNodesPostfix().Sum(n => n.GetLength()) }; // sum of the length of the whole sub-tree for each node72 return new double[2] { r2, tree.IterateNodesPostfix().Sum(n => n.GetLength()) }; // sum of the length of the whole sub-tree for each node 70 73 } 71 74 -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNumberOfVariablesEvaluator.cs
r17180 r18103 62 62 } 63 63 64 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 65 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 64 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 65 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 66 tree, problemData, rows, interpreter, applyLinearScaling, 67 lowerEstimationLimit, upperEstimationLimit); 66 68 if (decimalPlaces >= 0) 67 69 r2 = Math.Round(r2, decimalPlaces); 68 return new double[2] { r2, solution.IterateNodesPostfix().OfType<IVariableTreeNode>().Count() }; // count the number of variables70 return new double[2] { r2, tree.IterateNodesPostfix().OfType<IVariableTreeNode>().Count() }; // count the number of variables 69 71 } 70 72 -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredTreeComplexityEvaluator.cs
r17180 r18103 61 61 } 62 62 63 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 64 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 63 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 64 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 65 tree, problemData, rows, 66 interpreter, applyLinearScaling, 67 lowerEstimationLimit, upperEstimationLimit); 65 68 if (decimalPlaces >= 0) 66 69 r2 = Math.Round(r2, decimalPlaces); 67 return new double[2] { r2, SymbolicDataAnalysisModelComplexityCalculator.CalculateComplexity( solution) };70 return new double[2] { r2, SymbolicDataAnalysisModelComplexityCalculator.CalculateComplexity(tree) }; 68 71 } 69 72 -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r17180 r18103 47 47 public override IOperation InstrumentedApply() { 48 48 IEnumerable<int> rows = GenerateRowsToEvaluate(); 49 var solution= SymbolicExpressionTreeParameter.ActualValue;49 var tree = SymbolicExpressionTreeParameter.ActualValue; 50 50 var problemData = ProblemDataParameter.ActualValue; 51 51 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; … … 54 54 55 55 if (UseConstantOptimization) { 56 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper);56 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper); 57 57 } 58 58 59 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 59 double[] qualities = Calculate( 60 tree, ProblemDataParameter.ActualValue, 61 rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 62 ApplyLinearScalingParameter.ActualValue.Value, 63 EstimationLimitsParameter.ActualValue.Lower, 64 EstimationLimitsParameter.ActualValue.Upper, 65 DecimalPlaces); 60 66 QualitiesParameter.ActualValue = new DoubleArray(qualities); 61 67 return base.InstrumentedApply(); 62 68 } 63 69 64 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 65 var mse = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, 66 upperEstimationLimit, problemData, rows, applyLinearScaling); 70 public static double[] Calculate( 71 ISymbolicExpressionTree tree, 72 IRegressionProblemData problemData, 73 IEnumerable<int> rows, 74 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 75 bool applyLinearScaling, 76 double lowerEstimationLimit, double upperEstimationLimit, 77 int decimalPlaces) { 78 var mse = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate( 79 tree, problemData, rows, 80 interpreter, applyLinearScaling, 81 lowerEstimationLimit, 82 upperEstimationLimit); 67 83 68 84 if (decimalPlaces >= 0) 69 85 mse = Math.Round(mse, decimalPlaces); 70 86 71 return new double[2] { mse, solution.Length };87 return new double[2] { mse, tree.Length }; 72 88 } 73 89 … … 77 93 ApplyLinearScalingParameter.ExecutionContext = context; 78 94 79 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 95 double[] quality = Calculate( 96 tree, problemData, rows, 97 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 98 ApplyLinearScalingParameter.ActualValue.Value, 99 EstimationLimitsParameter.ActualValue.Lower, 100 EstimationLimitsParameter.ActualValue.Upper, DecimalPlaces); 80 101 81 102 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r17180 r18103 61 61 } 62 62 63 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 64 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 63 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 64 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 65 tree, problemData, rows, interpreter, applyLinearScaling, 66 lowerEstimationLimit, upperEstimationLimit); 65 67 if (decimalPlaces >= 0) 66 68 r2 = Math.Round(r2, decimalPlaces); 67 return new double[2] { r2, solution.Length };69 return new double[2] { r2, tree.Length }; 68 70 } 69 71 -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSESingleObjectiveConstraintsEvaluator.cs
r18095 r18103 125 125 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 126 126 127 if (OptimizeParameters) { 128 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, rows, 129 false, ConstantOptimizationIterations, true, 130 estimationLimits.Lower, estimationLimits.Upper); 131 } else { 132 if (applyLinearScaling) { 133 var rootNode = new ProgramRootSymbol().CreateTreeNode(); 134 var startNode = new StartSymbol().CreateTreeNode(); 135 var offset = tree.Root.GetSubtree(0) //Start 136 .GetSubtree(0); //Offset 137 var scaling = offset.GetSubtree(0); 138 139 //Check if tree contains offset and scaling nodes 140 if (!(offset.Symbol is Addition) || !(scaling.Symbol is Multiplication)) 141 throw new ArgumentException($"{ItemName} can only be used with LinearScalingGrammar."); 142 143 var t = (ISymbolicExpressionTreeNode)scaling.GetSubtree(0).Clone(); 144 rootNode.AddSubtree(startNode); 145 startNode.AddSubtree(t); 146 var newTree = new SymbolicExpressionTree(rootNode); 147 148 //calculate alpha and beta for scaling 149 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 150 151 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 152 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, 153 out var errorState); 154 155 if (errorState == OnlineCalculatorError.None) { 156 //Set alpha and beta to the scaling nodes from ia grammar 157 var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode; 158 offsetParameter.Value = alpha; 159 var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode; 160 scalingParameter.Value = beta; 161 } 162 } // else: alpha and beta are evolved 127 var quality = Evaluate(tree, problemData, rows, interpreter, applyLinearScaling, estimationLimits.Lower, estimationLimits.Upper); 128 QualityParameter.ActualValue = new DoubleValue(quality); 129 130 return base.InstrumentedApply(); 131 } 132 133 private static void CalcLinearScalingTerms( 134 ISymbolicExpressionTree tree, 135 IRegressionProblemData problemData, 136 IEnumerable<int> rows, 137 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter) { 138 var rootNode = new ProgramRootSymbol().CreateTreeNode(); 139 var startNode = new StartSymbol().CreateTreeNode(); 140 var offset = tree.Root.GetSubtree(0) //Start 141 .GetSubtree(0); //Offset 142 var scaling = offset.GetSubtree(0); 143 144 //Check if tree contains offset and scaling nodes 145 if (!(offset.Symbol is Addition) || !(scaling.Symbol is Multiplication)) 146 throw new ArgumentException($"Shape Constraints Evaluation can only be used with LinearScalingGrammar."); 147 148 var t = (ISymbolicExpressionTreeNode)scaling.GetSubtree(0).Clone(); 149 rootNode.AddSubtree(startNode); 150 startNode.AddSubtree(t); 151 var newTree = new SymbolicExpressionTree(rootNode); 152 153 //calculate alpha and beta for scaling 154 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 155 156 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 157 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, 158 out var errorState); 159 if (errorState == OnlineCalculatorError.None) { 160 //Set alpha and beta to the scaling nodes from ia grammar 161 var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode; 162 offsetParameter.Value = alpha; 163 var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode; 164 scalingParameter.Value = beta; 163 165 } 164 165 var quality = Calculate(interpreter, tree, estimationLimits.Lower, estimationLimits.Upper, problemData, rows,166 BoundsEstimator, UseSoftConstraints, PenalityFactor);167 QualityParameter.ActualValue = new DoubleValue(quality);168 169 return base.InstrumentedApply();170 166 } 171 167 172 168 public static double Calculate( 169 ISymbolicExpressionTree tree, 170 IRegressionProblemData problemData, IEnumerable<int> rows, 173 171 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 174 ISymbolicExpressionTree tree,175 172 double lowerEstimationLimit, double upperEstimationLimit, 176 IRegressionProblemData problemData, IEnumerable<int> rows,177 173 IBoundsEstimator estimator, 178 174 bool useSoftConstraints = false, double penaltyFactor = 1.0) { 179 175 176 var constraints = Enumerable.Empty<ShapeConstraint>(); 177 if (problemData is ShapeConstrainedRegressionProblemData scProbData) 178 constraints = scProbData.ShapeConstraints.EnabledConstraints; 179 180 180 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 181 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 181 182 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 182 var constraints = Enumerable.Empty<ShapeConstraint>(); 183 if (problemData is ShapeConstrainedRegressionProblemData scProbData) { 184 constraints = scProbData.ShapeConstraints.EnabledConstraints; 185 } 183 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState); 184 if (errorState != OnlineCalculatorError.None) 185 return 1.0; 186 187 if (!constraints.Any()) 188 return nmse; 189 186 190 var intervalCollection = problemData.VariableRanges; 187 188 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 189 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, 190 out var errorState); 191 192 if (errorState != OnlineCalculatorError.None) { 191 var constraintViolations = IntervalUtil.GetConstraintViolations(constraints, estimator, intervalCollection, tree); 192 193 // infinite/NaN constraints 194 if (constraintViolations.Any(x => double.IsNaN(x) || double.IsInfinity(x))) 193 195 return 1.0; 196 197 // hard constraints 198 if (!useSoftConstraints) { 199 if (constraintViolations.Any(x => x > 0.0)) 200 return 1.0; 201 return nmse; 194 202 } 195 203 196 var constraintViolations = IntervalUtil.GetConstraintViolations(constraints, estimator, intervalCollection, tree); 197 198 if (constraintViolations.Any(x => double.IsNaN(x) || double.IsInfinity(x))) { 199 return 1.0; 200 } 201 202 if (useSoftConstraints) { 203 if (penaltyFactor < 0.0) 204 throw new ArgumentException("The parameter has to be >= 0.0.", nameof(penaltyFactor)); 205 206 var weightedViolationsAvg = constraints 207 .Zip(constraintViolations, (c, v) => c.Weight * v) 208 .Average(); 209 210 return Math.Min(nmse, 1.0) + penaltyFactor * weightedViolationsAvg; 211 } else if (constraintViolations.Any(x => x > 0.0)) { 212 return 1.0; 213 } 214 215 return nmse; 204 // soft constraints 205 if (penaltyFactor < 0.0) 206 throw new ArgumentException("The parameter has to be >= 0.0.", nameof(penaltyFactor)); 207 208 var weightedViolationsAvg = constraints 209 .Zip(constraintViolations, (c, v) => c.Weight * v) 210 .Average(); 211 212 return Math.Min(nmse, 1.0) + penaltyFactor * weightedViolationsAvg; 216 213 } 217 214 … … 223 220 ApplyLinearScalingParameter.ExecutionContext = context; 224 221 225 var nmse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, 226 EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 227 problemData, rows, BoundsEstimator, UseSoftConstraints, PenalityFactor); 222 var nmse = Calculate( 223 tree, problemData, rows, 224 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 225 EstimationLimitsParameter.ActualValue.Lower, 226 EstimationLimitsParameter.ActualValue.Upper, 227 BoundsEstimator, 228 UseSoftConstraints, 229 PenalityFactor); 228 230 229 231 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 234 236 } 235 237 236 public override double Evaluate(IRegressionProblemData problemData, 237 ISymbolicExpressionTree solution, 238 public override double Evaluate( 239 ISymbolicExpressionTree tree, 240 IRegressionProblemData problemData, 241 IEnumerable<int> rows, 238 242 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 239 IEnumerable<int> rows = null,240 243 bool applyLinearScaling = true, 241 244 double lowerEstimationLimit = double.MinValue, 242 245 double upperEstimationLimit = double.MaxValue) { 243 246 244 if (OptimizeParameters) {247 if (OptimizeParameters) 245 248 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants( 246 interpreter, 247 solution, 248 problemData, 249 rows, 250 false, 249 interpreter, tree, 250 problemData, rows, 251 applyLinearScaling: false, // OptimizeConstants deletes the scaling terms -> wrong estimations 251 252 ConstantOptimizationIterations, 252 true,253 updateVariableWeights: true, 253 254 lowerEstimationLimit, 254 255 upperEstimationLimit); 255 } else { 256 if (applyLinearScaling) { 257 var rootNode = new ProgramRootSymbol().CreateTreeNode(); 258 var startNode = new StartSymbol().CreateTreeNode(); 259 var offset = solution.Root.GetSubtree(0) //Start 260 .GetSubtree(0); //Offset 261 var scaling = offset.GetSubtree(0); 262 263 //Check if tree contains offset and scaling nodes 264 if (!(offset.Symbol is Addition) || !(scaling.Symbol is Multiplication)) 265 throw new ArgumentException($"{ItemName} can only be used with LinearScalingGrammar."); 266 267 var t = (ISymbolicExpressionTreeNode)scaling.GetSubtree(0).Clone(); 268 rootNode.AddSubtree(startNode); 269 startNode.AddSubtree(t); 270 var newTree = new SymbolicExpressionTree(rootNode); 271 272 //calculate alpha and beta for scaling 273 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 274 275 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 276 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, 277 out var errorState); 278 279 if (errorState == OnlineCalculatorError.None) { 280 //Set alpha and beta to the scaling nodes from ia grammar 281 var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode; 282 offsetParameter.Value = alpha; 283 var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode; 284 scalingParameter.Value = beta; 285 } 286 } // else: alpha and beta are evolved 287 } 256 257 if (applyLinearScaling) // extra scaling terms, which are included in tree 258 CalcLinearScalingTerms(tree, problemData, rows, interpreter); 259 288 260 return Calculate( 289 interpreter,290 solution,261 tree, problemData, 262 rows, interpreter, 291 263 lowerEstimationLimit, 292 264 upperEstimationLimit, 293 problemData,294 rows ?? problemData.TrainingIndices,295 265 BoundsEstimator, 296 266 UseSoftConstraints, -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r18099 r18103 149 149 private static readonly object locker = new object(); 150 150 public override IOperation InstrumentedApply() { 151 var solution= SymbolicExpressionTreeParameter.ActualValue;151 var tree = SymbolicExpressionTreeParameter.ActualValue; 152 152 double quality; 153 153 if (RandomParameter.ActualValue.NextDouble() < ConstantOptimizationProbability.Value) { 154 154 IEnumerable<int> constantOptimizationRows = GenerateRowsToEvaluate(ConstantOptimizationRowsPercentage.Value); 155 155 var counter = new EvaluationsCounter(); 156 quality = OptimizeConstants(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, ProblemDataParameter.ActualValue,156 quality = OptimizeConstants(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, ProblemDataParameter.ActualValue, 157 157 constantOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, ConstantOptimizationIterations.Value, updateVariableWeights: UpdateVariableWeights, lowerEstimationLimit: EstimationLimitsParameter.ActualValue.Lower, upperEstimationLimit: EstimationLimitsParameter.ActualValue.Upper, updateConstantsInTree: UpdateConstantsInTree, counter: counter); 158 158 159 159 if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) { 160 160 var evaluationRows = GenerateRowsToEvaluate(); 161 quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value); 161 quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 162 tree, ProblemDataParameter.ActualValue, 163 evaluationRows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 164 ApplyLinearScalingParameter.ActualValue.Value, 165 EstimationLimitsParameter.ActualValue.Lower, 166 EstimationLimitsParameter.ActualValue.Upper); 162 167 } 163 168 … … 171 176 } else { 172 177 var evaluationRows = GenerateRowsToEvaluate(); 173 quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value); 178 quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 179 tree, ProblemDataParameter.ActualValue, 180 evaluationRows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 181 ApplyLinearScalingParameter.ActualValue.Value, 182 EstimationLimitsParameter.ActualValue.Lower, 183 EstimationLimitsParameter.ActualValue.Upper); 174 184 } 175 185 QualityParameter.ActualValue = new DoubleValue(quality); … … 178 188 } 179 189 180 public override double Evaluate(IRegressionProblemData problemData, 181 ISymbolicExpressionTree solution, 190 public override double Evaluate( 191 ISymbolicExpressionTree tree, 192 IRegressionProblemData problemData, 193 IEnumerable<int> rows, 182 194 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 183 IEnumerable<int> rows = null,184 195 bool applyLinearScaling = true, 185 196 double lowerEstimationLimit = double.MinValue, 186 197 double upperEstimationLimit = double.MaxValue) { 187 198 188 189 var random = RandomParameter?.Value ?? new MersenneTwister((uint)DateTime.Now.Millisecond); 190 double quality; 199 var random = RandomParameter.ActualValue; 200 double quality = double.NaN; 191 201 192 202 var propability = random.NextDouble(); 193 203 if (propability < ConstantOptimizationProbability.Value) { 194 var counter = new EvaluationsCounter();204 IEnumerable<int> constantOptimizationRows = GenerateRowsToEvaluate(ConstantOptimizationRowsPercentage.Value); 195 205 quality = OptimizeConstants( 196 interpreter, 197 solution, 198 problemData, 199 rows ?? problemData.TrainingIndices, 200 applyLinearScaling, 201 ConstantOptimizationIterations.Value, 202 updateVariableWeights: UpdateVariableWeights, 203 lowerEstimationLimit: lowerEstimationLimit, 204 upperEstimationLimit: upperEstimationLimit, 205 updateConstantsInTree: UpdateConstantsInTree, 206 counter: counter); 207 208 if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) { //TODO: remove this? 209 var evaluationRows = GenerateRowsToEvaluate(); 210 quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 211 interpreter, 212 solution, 213 lowerEstimationLimit, 214 upperEstimationLimit, 215 problemData, 216 evaluationRows, 217 applyLinearScaling); 218 } 219 220 } else { 221 var evaluationRows = GenerateRowsToEvaluate(); 206 interpreter, tree, 207 problemData, constantOptimizationRows, 208 applyLinearScaling, 209 ConstantOptimizationIterations.Value, 210 updateVariableWeights: UpdateVariableWeights, 211 lowerEstimationLimit: lowerEstimationLimit, 212 upperEstimationLimit: upperEstimationLimit, 213 updateConstantsInTree: UpdateConstantsInTree); 214 } 215 if (double.IsNaN(quality) || ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) { 222 216 quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 223 interpreter, 224 solution, 217 tree, problemData, 218 rows, interpreter, 219 applyLinearScaling, 225 220 lowerEstimationLimit, 226 upperEstimationLimit, 227 problemData, 228 evaluationRows, 229 applyLinearScaling); 221 upperEstimationLimit); 230 222 } 231 223 return quality; … … 242 234 // because Evaluate() is used to get the quality of evolved models on 243 235 // different partitions of the dataset (e.g., best validation model) 244 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 236 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 237 tree, problemData, rows, 238 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 239 ApplyLinearScalingParameter.ActualValue.Value, 240 EstimationLimitsParameter.ActualValue.Lower, 241 EstimationLimitsParameter.ActualValue.Upper); 245 242 246 243 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 290 287 } 291 288 292 double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 289 double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 290 tree, problemData, rows, 291 interpreter, applyLinearScaling, 292 lowerEstimationLimit, 293 upperEstimationLimit); 293 294 294 295 if (counter == null) counter = new EvaluationsCounter(); … … 348 349 } else UpdateConstants(tree, c, updateVariableWeights); 349 350 } 350 var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 351 var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 352 tree, problemData, rows, 353 interpreter, applyLinearScaling, 354 lowerEstimationLimit, upperEstimationLimit); 351 355 352 356 if (!updateConstantsInTree) UpdateConstants(tree, initialConstants, updateVariableWeights); -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionLogResidualEvaluator.cs
r18095 r18103 54 54 55 55 public override IOperation InstrumentedApply() { 56 var solution= SymbolicExpressionTreeParameter.ActualValue;56 var tree = SymbolicExpressionTreeParameter.ActualValue; 57 57 IEnumerable<int> rows = GenerateRowsToEvaluate(); 58 58 59 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows); 59 double quality = Calculate( 60 tree, ProblemDataParameter.ActualValue, 61 rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 62 EstimationLimitsParameter.ActualValue.Lower, 63 EstimationLimitsParameter.ActualValue.Upper); 60 64 QualityParameter.ActualValue = new DoubleValue(quality); 61 65 … … 63 67 } 64 68 65 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows) { 66 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 69 public static double Calculate( 70 ISymbolicExpressionTree tree, 71 IRegressionProblemData problemData, 72 IEnumerable<int> rows, 73 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 74 double lowerEstimationLimit, 75 double upperEstimationLimit) { 76 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 67 77 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 68 78 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); … … 83 93 EstimationLimitsParameter.ExecutionContext = context; 84 94 85 double mlr = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows); 95 double mlr = Calculate( 96 tree, problemData, rows, 97 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 98 EstimationLimitsParameter.ActualValue.Lower, 99 EstimationLimitsParameter.ActualValue.Upper); 86 100 87 101 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 91 105 } 92 106 93 public override double Evaluate(IRegressionProblemData problemData, 94 ISymbolicExpressionTree solution, 107 public override double Evaluate( 108 ISymbolicExpressionTree tree, 109 IRegressionProblemData problemData, 110 IEnumerable<int> rows, 95 111 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 96 IEnumerable<int> rows = null,97 112 bool applyLinearScaling = true, 98 113 double lowerEstimationLimit = double.MinValue, 99 114 double upperEstimationLimit = double.MaxValue) { 100 return Calculate( interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices);115 return Calculate(tree, problemData, rows, interpreter, lowerEstimationLimit, upperEstimationLimit); 101 116 } 102 117 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionMeanRelativeErrorEvaluator.cs
r18095 r18103 47 47 48 48 public override IOperation InstrumentedApply() { 49 var solution= SymbolicExpressionTreeParameter.ActualValue;49 var tree = SymbolicExpressionTreeParameter.ActualValue; 50 50 IEnumerable<int> rows = GenerateRowsToEvaluate(); 51 51 52 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows); 52 double quality = Calculate( 53 tree, ProblemDataParameter.ActualValue, rows, 54 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 55 EstimationLimitsParameter.ActualValue.Lower, 56 EstimationLimitsParameter.ActualValue.Upper); 53 57 QualityParameter.ActualValue = new DoubleValue(quality); 54 58 … … 56 60 } 57 61 58 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows) { 59 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 62 public static double Calculate( 63 ISymbolicExpressionTree tree, 64 IRegressionProblemData problemData, 65 IEnumerable<int> rows, 66 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 67 double lowerEstimationLimit, double upperEstimationLimit) { 68 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 60 69 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 61 70 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); … … 76 85 EstimationLimitsParameter.ExecutionContext = context; 77 86 78 double mre = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows); 87 double mre = Calculate( 88 tree, problemData, rows, 89 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 90 EstimationLimitsParameter.ActualValue.Lower, 91 EstimationLimitsParameter.ActualValue.Upper); 79 92 80 93 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 84 97 } 85 98 86 public override double Evaluate(IRegressionProblemData problemData, 87 ISymbolicExpressionTree solution, 99 public override double Evaluate( 100 ISymbolicExpressionTree tree, 101 IRegressionProblemData problemData, 102 IEnumerable<int> rows, 88 103 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 89 IEnumerable<int> rows = null,90 104 bool applyLinearScaling = true, 91 105 double lowerEstimationLimit = double.MinValue, 92 106 double upperEstimationLimit = double.MaxValue) { 93 return Calculate( interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices);107 return Calculate(tree, problemData, rows, interpreter, lowerEstimationLimit, upperEstimationLimit); 94 108 } 95 109 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs
r18095 r18103 33 33 protected SymbolicRegressionSingleObjectiveEvaluator(): base() {} 34 34 public abstract double Evaluate( 35 ISymbolicExpressionTree tree, 35 36 IRegressionProblemData problemData, 36 I SymbolicExpressionTree tree,37 IEnumerable<int> rows, 37 38 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 38 IEnumerable<int> rows = null,39 39 bool applyLinearScaling = true, 40 40 double lowerEstimationLimit = double.MinValue, -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs
r18095 r18103 43 43 44 44 public override IOperation InstrumentedApply() { 45 var solution= SymbolicExpressionTreeParameter.ActualValue;45 var tree = SymbolicExpressionTreeParameter.ActualValue; 46 46 IEnumerable<int> rows = GenerateRowsToEvaluate(); 47 47 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 48 double quality = Calculate( 49 tree, ProblemDataParameter.ActualValue, 50 rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 51 ApplyLinearScalingParameter.ActualValue.Value, 52 EstimationLimitsParameter.ActualValue.Lower, 53 EstimationLimitsParameter.ActualValue.Upper); 49 54 QualityParameter.ActualValue = new DoubleValue(quality); 50 55 … … 52 57 } 53 58 54 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 59 public static double Calculate( 60 ISymbolicExpressionTree tree, 61 IRegressionProblemData problemData, 62 IEnumerable<int> rows, 63 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 64 bool applyLinearScaling, 65 double lowerEstimationLimit, 66 double upperEstimationLimit) { 67 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 56 68 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 57 69 OnlineCalculatorError errorState; … … 76 88 ApplyLinearScalingParameter.ExecutionContext = context; 77 89 78 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 90 double mse = Calculate( 91 tree, problemData, rows, 92 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 93 ApplyLinearScalingParameter.ActualValue.Value, 94 EstimationLimitsParameter.ActualValue.Lower, 95 EstimationLimitsParameter.ActualValue.Upper); 79 96 80 97 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 85 102 } 86 103 87 public override double Evaluate(IRegressionProblemData problemData, 88 ISymbolicExpressionTree solution, 104 public override double Evaluate( 105 ISymbolicExpressionTree tree, 106 IRegressionProblemData problemData, 107 IEnumerable<int> rows, 89 108 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 90 IEnumerable<int> rows = null,91 109 bool applyLinearScaling = true, 92 110 double lowerEstimationLimit = double.MinValue, 93 111 double upperEstimationLimit = double.MaxValue) { 94 return Calculate( interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices, applyLinearScaling);112 return Calculate(tree, problemData, rows, interpreter, applyLinearScaling, lowerEstimationLimit, upperEstimationLimit); 95 113 } 96 114 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs
r18095 r18103 43 43 44 44 public override IOperation InstrumentedApply() { 45 var solution= SymbolicExpressionTreeParameter.ActualValue;45 var tree = SymbolicExpressionTreeParameter.ActualValue; 46 46 IEnumerable<int> rows = GenerateRowsToEvaluate(); 47 47 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 48 double quality = Calculate(tree, 49 ProblemDataParameter.ActualValue, rows, 50 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 51 ApplyLinearScalingParameter.ActualValue.Value, 52 EstimationLimitsParameter.ActualValue.Lower, 53 EstimationLimitsParameter.ActualValue.Upper); 49 54 QualityParameter.ActualValue = new DoubleValue(quality); 50 55 … … 52 57 } 53 58 54 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 59 public static double Calculate( 60 ISymbolicExpressionTree tree, 61 IRegressionProblemData problemData, 62 IEnumerable<int> rows, 63 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 64 bool applyLinearScaling, 65 double lowerEstimationLimit, 66 double upperEstimationLimit) { 67 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 56 68 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 57 69 OnlineCalculatorError errorState; … … 76 88 ApplyLinearScalingParameter.ExecutionContext = context; 77 89 78 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 90 double mse = Calculate( 91 tree, problemData, rows, 92 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 93 ApplyLinearScalingParameter.ActualValue.Value, 94 EstimationLimitsParameter.ActualValue.Lower, 95 EstimationLimitsParameter.ActualValue.Upper); 79 96 80 97 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 85 102 } 86 103 87 public override double Evaluate(IRegressionProblemData problemData, 88 ISymbolicExpressionTree solution, 104 public override double Evaluate( 105 ISymbolicExpressionTree tree, 106 IRegressionProblemData problemData, 107 IEnumerable<int> rows, 89 108 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 90 IEnumerable<int> rows = null,91 109 bool applyLinearScaling = true, 92 110 double lowerEstimationLimit = double.MinValue, 93 111 double upperEstimationLimit = double.MaxValue) { 94 return Calculate( interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices, applyLinearScaling);112 return Calculate(tree, problemData, rows, interpreter, applyLinearScaling, lowerEstimationLimit, upperEstimationLimit); 95 113 } 96 114 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r18095 r18103 43 43 44 44 public override IOperation InstrumentedApply() { 45 var solution= SymbolicExpressionTreeParameter.ActualValue;45 var tree = SymbolicExpressionTreeParameter.ActualValue; 46 46 IEnumerable<int> rows = GenerateRowsToEvaluate(); 47 47 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 48 double quality = Calculate( 49 tree, ProblemDataParameter.ActualValue, 50 rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 51 ApplyLinearScalingParameter.ActualValue.Value, 52 EstimationLimitsParameter.ActualValue.Lower, 53 EstimationLimitsParameter.ActualValue.Upper); 49 54 QualityParameter.ActualValue = new DoubleValue(quality); 50 55 … … 52 57 } 53 58 54 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 59 public static double Calculate( 60 ISymbolicExpressionTree tree, 61 IRegressionProblemData problemData, 62 IEnumerable<int> rows, 63 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 64 bool applyLinearScaling, 65 double lowerEstimationLimit, double upperEstimationLimit) { 66 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 56 67 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 57 68 OnlineCalculatorError errorState; … … 76 87 ApplyLinearScalingParameter.ExecutionContext = context; 77 88 78 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 89 double mse = Calculate( 90 tree, problemData, rows, 91 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 92 ApplyLinearScalingParameter.ActualValue.Value, 93 EstimationLimitsParameter.ActualValue.Lower, 94 EstimationLimitsParameter.ActualValue.Upper); 79 95 80 96 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 85 101 } 86 102 87 public override double Evaluate(IRegressionProblemData problemData, 88 ISymbolicExpressionTree solution, 103 public override double Evaluate( 104 ISymbolicExpressionTree tree, 105 IRegressionProblemData problemData, 106 IEnumerable<int> rows, 89 107 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 90 IEnumerable<int> rows = null,91 108 bool applyLinearScaling = true, 92 109 double lowerEstimationLimit = double.MinValue, 93 110 double upperEstimationLimit = double.MaxValue) { 94 return Calculate( interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices, applyLinearScaling);111 return Calculate(tree, problemData, rows, interpreter, applyLinearScaling, lowerEstimationLimit, upperEstimationLimit); 95 112 } 96 113 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r18095 r18103 48 48 IEnumerable<int> rows = GenerateRowsToEvaluate(); 49 49 50 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 double quality = Calculate( 51 solution, ProblemDataParameter.ActualValue, 52 rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 53 ApplyLinearScalingParameter.ActualValue.Value, 54 EstimationLimitsParameter.ActualValue.Lower, 55 EstimationLimitsParameter.ActualValue.Upper); 51 56 QualityParameter.ActualValue = new DoubleValue(quality); 52 57 … … 54 59 } 55 60 56 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 57 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 61 //TODO: refactor like evaluate method 62 public static double Calculate( 63 ISymbolicExpressionTree tree, 64 IRegressionProblemData problemData, 65 IEnumerable<int> rows, 66 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 67 bool applyLinearScaling, 68 double lowerEstimationLimit, 69 double upperEstimationLimit) { 70 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 58 71 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 59 72 OnlineCalculatorError errorState; … … 78 91 ApplyLinearScalingParameter.ExecutionContext = context; 79 92 80 double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 93 double r2 = Calculate( 94 tree, problemData, rows, 95 SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 96 ApplyLinearScalingParameter.ActualValue.Value, 97 EstimationLimitsParameter.ActualValue.Lower, 98 EstimationLimitsParameter.ActualValue.Upper); 81 99 82 100 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 87 105 } 88 106 89 public override double Evaluate(IRegressionProblemData problemData, 90 ISymbolicExpressionTree solution, 107 public override double Evaluate( 108 ISymbolicExpressionTree tree, 109 IRegressionProblemData problemData, 110 IEnumerable<int> rows, 91 111 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 92 IEnumerable<int> rows = null,93 112 bool applyLinearScaling = true, 94 113 double lowerEstimationLimit = double.MinValue, 95 114 double upperEstimationLimit = double.MaxValue) { 96 return Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices, applyLinearScaling); 115 return Calculate( 116 tree, problemData, rows, 117 interpreter, applyLinearScaling, 118 lowerEstimationLimit, upperEstimationLimit); 97 119 } 98 120 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs
r18101 r18103 194 194 individual[SymbolicExpressionTreeName] = tree; 195 195 196 if(TreeEvaluatorParameter.Value is SymbolicRegressionConstantOptimizationEvaluator) 197 TreeEvaluatorParameter.Value.RandomParameter.Value = random; 198 196 199 return TreeEvaluatorParameter.Value.Evaluate( 197 ProblemData,198 tree,200 tree, ProblemData, 201 ProblemData.TrainingIndices, 199 202 Interpreter, 200 ProblemData.TrainingIndices,201 203 StructureTemplate.ApplyLinearScaling, 202 204 EstimationLimits.Lower,
Note: See TracChangeset
for help on using the changeset viewer.