Changeset 17705
- Timestamp:
- 07/29/20 15:12:55 (4 years ago)
- Location:
- branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator.cs
r17636 r17705 62 62 var minIntervalWidth = MinSplittingWidth; 63 63 var maxIntervalSplitDepth = MaxSplittingDepth; 64 //var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 65 var applyLinearScaling = false; 64 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 65 66 if (applyLinearScaling) { 67 //Check for interval arithmetic grammar 68 //remove scaling nodes for linear scaling evaluation 69 var rootNode = new ProgramRootSymbol().CreateTreeNode(); 70 var startNode = new StartSymbol().CreateTreeNode(); 71 SymbolicExpressionTree newTree = null; 72 foreach (var node in solution.IterateNodesPrefix()) 73 if (node.Symbol.Name == "Scaling") { 74 for (var i = 0; i < node.SubtreeCount; ++i) startNode.AddSubtree(node.GetSubtree(i)); 75 rootNode.AddSubtree(startNode); 76 newTree = new SymbolicExpressionTree(rootNode); 77 break; 78 } 79 80 //calculate alpha and beta for scaling 81 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 82 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 83 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, 84 out var errorState); 85 //Set alpha and beta to the scaling nodes from ia grammar 86 foreach (var node in solution.IterateNodesPrefix()) 87 if (node.Symbol.Name == "Offset") { 88 node.RemoveSubtree(1); 89 var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha}; 90 node.AddSubtree(alphaNode); 91 } else if (node.Symbol.Name == "Scaling") { 92 node.RemoveSubtree(1); 93 var betaNode = new ConstantTreeNode(new Constant()) {Value = beta}; 94 node.AddSubtree(betaNode); 95 } 96 } 66 97 67 98 if (UseConstantOptimization) 68 99 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, 69 applyLinearScaling,100 false, 70 101 ConstantOptimizationIterations, 71 102 ConstantOptimizationUpdateVariableWeights, … … 74 105 75 106 var qualities = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, 76 rows, applyLinearScaling,DecimalPlaces, minIntervalWidth, maxIntervalSplitDepth);107 rows, DecimalPlaces, minIntervalWidth, maxIntervalSplitDepth); 77 108 QualitiesParameter.ActualValue = new DoubleArray(qualities); 78 109 return base.InstrumentedApply(); … … 88 119 var quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, 89 120 EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 90 problemData, rows, 91 ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces, MinSplittingWidth, 121 problemData, rows, DecimalPlaces, MinSplittingWidth, 92 122 MaxSplittingDepth); 93 123 … … 103 133 ISymbolicExpressionTree solution, double lowerEstimationLimit, 104 134 double upperEstimationLimit, 105 IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling,135 IRegressionProblemData problemData, IEnumerable<int> rows, 106 136 int decimalPlaces, double minIntervalSplitWidth, int maxIntervalSplitDepth) { 107 137 OnlineCalculatorError errorState; … … 114 144 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 115 145 nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 116 if (errorState != OnlineCalculatorError.None) nmse = double.NaN;146 if (errorState != OnlineCalculatorError.None) nmse = 1.0; 117 147 118 148 if (nmse > 1) 119 nmse = 1 ;149 nmse = 1.0; 120 150 121 151 var constraints = problemData.IntervalConstraints.Constraints.Where(c => c.Enabled); … … 190 220 var objectives = new List<bool> {false}; //First NMSE ==> min 191 221 objectives.AddRange(Enumerable.Repeat(false, 2)); //Constraints ==> min 192 222 193 223 return objectives; 194 224 } -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs
r17660 r17705 1 using System; 2 using System.Collections.Generic; 1 using System.Collections.Generic; 3 2 using HEAL.Attic; 4 3 using HeuristicLab.Common; … … 6 5 using HeuristicLab.Data; 7 6 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 8 using HeuristicLab.Parameters;9 7 10 8 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.SingleObjective.Evaluators { … … 13 11 public class SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator 14 12 : SymbolicRegressionSingleObjectiveEvaluator { 15 16 13 [StorableConstructor] 17 protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(StorableConstructorFlag _) : base(_) { }14 protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(StorableConstructorFlag _) : base(_) { } 18 15 19 16 protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator( … … 31 28 32 29 public override IOperation InstrumentedApply() { 33 var rows = GenerateRowsToEvaluate(); 34 var solution = SymbolicExpressionTreeParameter.ActualValue; 35 var problemData = ProblemDataParameter.ActualValue; 36 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 37 var estimationLimits = EstimationLimitsParameter.ActualValue; 38 var applyLinearScaling = false; 39 40 //Check for interval arithmetic grammar 41 //remove scaling nodes for linear scaling evaluation 42 var rootNode = new ProgramRootSymbol().CreateTreeNode(); 43 var startNode = new StartSymbol().CreateTreeNode(); 44 SymbolicExpressionTree newTree = null; 45 foreach (var node in solution.IterateNodesPrefix()) { 46 if (node.Symbol.Name == "Scaling") { 47 for (var i = 0; i < node.SubtreeCount; ++i) { 48 startNode.AddSubtree(node.GetSubtree(i)); 49 } 50 rootNode.AddSubtree(startNode); 51 newTree = new SymbolicExpressionTree(rootNode); 52 break; 53 } 54 } 55 //calculate alpha and beta for scaling 56 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 57 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, out var errorState); 59 var a = alpha; 60 var b = beta; 61 //Set alpha and beta to the scaling nodes from ia grammar 62 foreach (var node in solution.IterateNodesPrefix()) { 63 if (node.Symbol.Name == "Offset") { 64 node.RemoveSubtree(1); 65 var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha}; 66 node.AddSubtree(alphaNode); 67 } else if (node.Symbol.Name == "Scaling") { 68 node.RemoveSubtree(1); 69 var betaNode = new ConstantTreeNode(new Constant()) {Value = beta}; 70 node.AddSubtree(betaNode); 71 } 72 } 30 var rows = GenerateRowsToEvaluate(); 31 var solution = SymbolicExpressionTreeParameter.ActualValue; 32 var problemData = ProblemDataParameter.ActualValue; 33 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 34 var estimationLimits = EstimationLimitsParameter.ActualValue; 35 var applyLinearScaling = true; 36 37 if (applyLinearScaling) { 38 //Check for interval arithmetic grammar 39 //remove scaling nodes for linear scaling evaluation 40 var rootNode = new ProgramRootSymbol().CreateTreeNode(); 41 var startNode = new StartSymbol().CreateTreeNode(); 42 SymbolicExpressionTree newTree = null; 43 foreach (var node in solution.IterateNodesPrefix()) 44 if (node.Symbol.Name == "Scaling") { 45 for (var i = 0; i < node.SubtreeCount; ++i) startNode.AddSubtree(node.GetSubtree(i)); 46 rootNode.AddSubtree(startNode); 47 newTree = new SymbolicExpressionTree(rootNode); 48 break; 49 } 50 51 //calculate alpha and beta for scaling 52 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 53 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 54 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, 55 out var errorState); 56 //Set alpha and beta to the scaling nodes from ia grammar 57 foreach (var node in solution.IterateNodesPrefix()) 58 if (node.Symbol.Name == "Offset") { 59 node.RemoveSubtree(1); 60 var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha}; 61 node.AddSubtree(alphaNode); 62 } else if (node.Symbol.Name == "Scaling") { 63 node.RemoveSubtree(1); 64 var betaNode = new ConstantTreeNode(new Constant()) {Value = beta}; 65 node.AddSubtree(betaNode); 66 } 67 } 68 73 69 74 70 var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, 75 applyLinearScaling);71 false); 76 72 QualityParameter.ActualValue = new DoubleValue(quality); 77 73 return base.InstrumentedApply(); … … 85 81 var estimatedValues = 86 82 interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 87 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);88 var constraints = problemData.IntervalConstraints.EnabledConstraints;83 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 84 var constraints = problemData.IntervalConstraints.EnabledConstraints; 89 85 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 90 86 … … 93 89 94 90 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 95 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState); 91 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, 92 out var errorState); 96 93 if (errorState != OnlineCalculatorError.None) nmse = 1.0; 97 94 98 95 return nmse; 99 96 } 100 97 101 98 public override double Evaluate( 102 99 IExecutionContext context, ISymbolicExpressionTree tree, IRegressionProblemData problemData, … … 108 105 var nmse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, 109 106 EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 110 problemData, rows, 111 ApplyLinearScalingParameter.ActualValue.Value); 107 problemData, rows, false); 112 108 113 109 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
Note: See TracChangeset
for help on using the changeset viewer.