Changeset 17750 for branches/3076_IA_evaluators_analyzers
- Timestamp:
- 09/18/20 11:24:48 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintEvaluator.cs
r17744 r17750 119 119 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 120 120 121 if (applyLinearScaling) {122 //Check for interval arithmetic grammar123 //remove scaling nodes for linear scaling evaluation124 var rootNode = new ProgramRootSymbol().CreateTreeNode();125 var startNode = new StartSymbol().CreateTreeNode();126 SymbolicExpressionTree newTree = null;127 foreach (var node in solution.IterateNodesPrefix())128 if (node.Symbol.Name == "Scaling") {129 for (var i = 0; i < node.SubtreeCount; ++i) startNode.AddSubtree(node.GetSubtree(i));130 rootNode.AddSubtree(startNode);131 newTree = new SymbolicExpressionTree(rootNode);132 break;133 }134 135 //calculate alpha and beta for scaling136 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);137 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);138 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta,139 out var errorState);140 //Set alpha and beta to the scaling nodes from ia grammar141 foreach (var node in solution.IterateNodesPrefix())142 if (node.Symbol.Name == "Offset") {143 node.RemoveSubtree(1);144 var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha};145 node.AddSubtree(alphaNode);146 } else if (node.Symbol.Name == "Scaling") {147 node.RemoveSubtree(1);148 var betaNode = new ConstantTreeNode(new Constant()) {Value = beta};149 node.AddSubtree(betaNode);150 }151 }152 153 121 if (UseConstantOptimization) { 154 122 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, 155 123 false, ConstantOptimizationIterations, true, 156 124 estimationLimits.Lower, estimationLimits.Upper); 157 } 158 159 var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, UseSoftConstraints, 125 } else { 126 if (applyLinearScaling) { 127 //Check for interval arithmetic grammar 128 //remove scaling nodes for linear scaling evaluation 129 var rootNode = new ProgramRootSymbol().CreateTreeNode(); 130 var startNode = new StartSymbol().CreateTreeNode(); 131 SymbolicExpressionTree newTree = null; 132 foreach (var node in solution.IterateNodesPrefix()) 133 if (node.Symbol.Name == "Scaling") { 134 for (var i = 0; i < node.SubtreeCount; ++i) startNode.AddSubtree(node.GetSubtree(i)); 135 rootNode.AddSubtree(startNode); 136 newTree = new SymbolicExpressionTree(rootNode); 137 break; 138 } 139 140 //calculate alpha and beta for scaling 141 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 142 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 143 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, 144 out var errorState); 145 //Set alpha and beta to the scaling nodes from ia grammar 146 foreach (var node in solution.IterateNodesPrefix()) 147 if (node.Symbol.Name == "Offset") { 148 node.RemoveSubtree(1); 149 var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha}; 150 node.AddSubtree(alphaNode); 151 } else if (node.Symbol.Name == "Scaling") { 152 node.RemoveSubtree(1); 153 var betaNode = new ConstantTreeNode(new Constant()) {Value = beta}; 154 node.AddSubtree(betaNode); 155 } 156 } 157 } 158 159 var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, 160 UseSoftConstraints, 160 161 PenaltyMultiplier); 161 162 QualityParameter.ActualValue = new DoubleValue(quality); … … 171 172 double penaltyMultiplier) { 172 173 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 173 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);174 var constraints = problemData.IntervalConstraints.EnabledConstraints;175 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();176 174 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 175 var constraints = problemData.IntervalConstraints.EnabledConstraints; 176 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 177 177 178 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 178 179 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, 179 180 out var errorState); 180 181 181 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, out var error)) { 182 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, 183 out var error)) { 182 184 if (useSoftConstraints) { 183 185 if (double.IsNaN(error) || double.IsInfinity(error)) { … … 186 188 nmse += penaltyMultiplier * error; 187 189 } 188 190 189 191 nmse = Math.Min(1.0, nmse); 190 192 } else { … … 205 207 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 206 208 EstimationLimitsParameter.ExecutionContext = context; 207 ApplyLinearScalingParameter.ExecutionContext = context;209 ApplyLinearScalingParameter.ExecutionContext = context; 208 210 209 211 var nmse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree,
Note: See TracChangeset
for help on using the changeset viewer.