Changeset 17660
- Timestamp:
- 07/09/20 12:57:32 (4 years ago)
- Location:
- branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r17653 r17660 178 178 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" /> 179 179 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs" /> 180 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs" /> 180 181 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator.cs" /> 181 182 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs" /> -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator.cs
r17653 r17660 99 99 100 100 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution)) 101 return double.MaxValue;101 return 1.0; 102 102 103 103 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 104 104 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState); 105 if (errorState != OnlineCalculatorError.None) nmse = double.NaN;105 if (errorState != OnlineCalculatorError.None) nmse = 1.0; 106 106 107 107 return nmse; -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs
r17653 r17660 9 9 10 10 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.SingleObjective.Evaluators { 11 [Item("Constraint ConstOptNMSE Evaluator", "")]12 [StorableType(" DED36D85-A4BA-4019-B12D-C523F7327899")]13 public class SymbolicRegressionSingleObjectiveConstraint ConstOptNmseEvaluator11 [Item("Constraint Scaling NMSE Evaluator", "")] 12 [StorableType("5B69083F-74EE-446C-A7D1-9DEAAA128AC6")] 13 public class SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator 14 14 : SymbolicRegressionSingleObjectiveEvaluator { 15 private const string UseConstOptParameterName = "Use ConstOpt";16 private const string ConstOptIterationsParameterName = "ConstOpt Iterations";17 18 public IFixedValueParameter<BoolValue> UseConstOptParamerter =>19 (IFixedValueParameter<BoolValue>) Parameters[UseConstOptParameterName];20 21 public IFixedValueParameter<IntValue> ConstOpterIterationsParameter =>22 (IFixedValueParameter<IntValue>) Parameters[ConstOptIterationsParameterName];23 24 public bool UseConstOpt {25 get => UseConstOptParamerter.Value.Value;26 set => UseConstOptParamerter.Value.Value = value;27 }28 29 public int ConstOptIterations {30 get => ConstOpterIterationsParameter.Value.Value;31 set => ConstOpterIterationsParameter.Value.Value = value;32 }33 15 34 16 [StorableConstructor] 35 protected SymbolicRegressionSingleObjectiveConstraint ConstOptNmseEvaluator(StorableConstructorFlag _) : base(_) {}17 protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(StorableConstructorFlag _) : base(_) {} 36 18 37 protected SymbolicRegressionSingleObjectiveConstraint ConstOptNmseEvaluator(38 SymbolicRegressionSingleObjectiveConstraint ConstOptNmseEvaluator original, Cloner cloner) :19 protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator( 20 SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator original, Cloner cloner) : 39 21 base(original, cloner) { } 40 22 41 23 public override IDeepCloneable Clone(Cloner cloner) { 42 return new SymbolicRegressionSingleObjectiveConstraint ConstOptNmseEvaluator(this, cloner);24 return new SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(this, cloner); 43 25 } 44 26 45 public SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator() { 46 Parameters.Add(new FixedValueParameter<BoolValue>(UseConstOptParameterName, 47 "Define whether constOpt is active or not.", new BoolValue(true))); 48 Parameters.Add(new FixedValueParameter<IntValue>(ConstOptIterationsParameterName, 49 "Define how many constOpt iterations should be performed.", new IntValue(10))); 50 } 27 public SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator() { } 51 28 52 29 public override bool Maximization => false; 53 30 54 [StorableHook(HookType.AfterDeserialization)]55 private void AfterDeserialization() {56 if (!Parameters.ContainsKey(UseConstOptParameterName)) {57 Parameters.Add(new FixedValueParameter<BoolValue>(UseConstOptParameterName,58 "Define whether constOpt is active or not.", new BoolValue(true)));59 }60 61 if (!Parameters.ContainsKey(ConstOptIterationsParameterName)) {62 Parameters.Add(new FixedValueParameter<IntValue>(ConstOptIterationsParameterName,63 "Define how many constOpt iterations should be performed.", new IntValue(10)));64 }65 }66 31 67 32 public override IOperation InstrumentedApply() { … … 71 36 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 72 37 var estimationLimits = EstimationLimitsParameter.ActualValue; 73 var applyLinearScaling = false; 74 var constantOptimizationIterations = ConstOptIterations; 75 var constantOptimizationUpdateVariableWeights = true; 76 77 //Use Const Opt 78 if(UseConstOpt) 79 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, 80 applyLinearScaling, constantOptimizationIterations, constantOptimizationUpdateVariableWeights, 81 estimationLimits.Lower, estimationLimits.Upper); 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 } 82 73 83 74 var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, … … 99 90 100 91 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution)) 101 return double.MaxValue;92 return 1.0; 102 93 103 94 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 104 95 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState); 105 if (errorState != OnlineCalculatorError.None) nmse = double.NaN;96 if (errorState != OnlineCalculatorError.None) nmse = 1.0; 106 97 107 98 return nmse;
Note: See TracChangeset
for help on using the changeset viewer.