Changeset 17751
- Timestamp:
- 09/20/20 22:21:24 (4 years ago)
- Location:
- branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator.cs
r17733 r17751 115 115 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 116 116 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState); 117 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, out double error))117 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, false, out double error)) 118 118 { 119 119 if (double.IsNaN(error) || double.IsInfinity(error)) -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintEvaluator.cs
r17750 r17751 1 1 using System; 2 using System.CodeDom; 2 3 using System.Collections.Generic; 3 4 using System.Linq; … … 26 27 private const string PenaltyMultiplierParameterName = "Constraints Penalty Multiplier"; 27 28 29 private const string UseIntervalSplittingParameterName = "Use Interval Splitting"; 30 28 31 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter => 29 32 (IFixedValueParameter<BoolValue>) Parameters[UseConstantOptimizationParameterName]; … … 37 40 public IFixedValueParameter<DoubleValue> PenaltyMultiplierParameter => 38 41 (IFixedValueParameter<DoubleValue>) Parameters[PenaltyMultiplierParameterName]; 42 43 public IFixedValueParameter<BoolValue> UseIntervalSplittingParameter => 44 (IFixedValueParameter<BoolValue>) Parameters[UseIntervalSplittingParameterName]; 39 45 40 46 public bool UseConstantOptimization { … … 56 62 get => PenaltyMultiplierParameter.Value.Value; 57 63 set => PenaltyMultiplierParameter.Value.Value = value; 64 } 65 66 public bool UseIntervalSplitting { 67 get => UseIntervalSplittingParameter.Value.Value; 68 set => UseIntervalSplittingParameter.Value.Value = value; 58 69 } 59 70 … … 80 91 Parameters.Add(new FixedValueParameter<DoubleValue>(PenaltyMultiplierParameterName, 81 92 "Specify how hard constraints violations should be punished", new DoubleValue(1.0))); 93 Parameters.Add(new FixedValueParameter<BoolValue>(UseIntervalSplittingParameterName, 94 "Define whether interval splitting is used or not.", new BoolValue(false))); 82 95 } 83 96 … … 103 116 "Specify how hard constraints violations should be punished", new DoubleValue(1.0))); 104 117 } 118 119 if (!Parameters.ContainsKey(UseIntervalSplittingParameterName)) { 120 Parameters.Add(new FixedValueParameter<BoolValue>(UseIntervalSplittingParameterName, 121 "Define whether interval splitting is used or not.", new BoolValue(false))); 122 } 105 123 } 106 124 … … 112 130 113 131 public override IOperation InstrumentedApply() { 114 var rows 115 var solution 116 var problemData 117 var interpreter 118 var estimationLimits 132 var rows = GenerateRowsToEvaluate(); 133 var solution = SymbolicExpressionTreeParameter.ActualValue; 134 var problemData = ProblemDataParameter.ActualValue; 135 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 136 var estimationLimits = EstimationLimitsParameter.ActualValue; 119 137 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 120 138 … … 127 145 //Check for interval arithmetic grammar 128 146 //remove scaling nodes for linear scaling evaluation 129 var rootNode= new ProgramRootSymbol().CreateTreeNode();130 var 131 SymbolicExpressionTree newTree 147 var rootNode = new ProgramRootSymbol().CreateTreeNode(); 148 var startNode = new StartSymbol().CreateTreeNode(); 149 SymbolicExpressionTree newTree = null; 132 150 foreach (var node in solution.IterateNodesPrefix()) 133 151 if (node.Symbol.Name == "Scaling") { … … 140 158 //calculate alpha and beta for scaling 141 159 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 142 var targetValues 160 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 143 161 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, 144 162 out var errorState); … … 159 177 var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, 160 178 UseSoftConstraints, 161 PenaltyMultiplier );179 PenaltyMultiplier, UseIntervalSplitting); 162 180 QualityParameter.ActualValue = new DoubleValue(quality); 163 181 … … 170 188 double upperEstimationLimit, 171 189 IRegressionProblemData problemData, IEnumerable<int> rows, bool useSoftConstraints, 172 double penaltyMultiplier ) {190 double penaltyMultiplier, bool useSplitting) { 173 191 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 174 var targetValues 175 var constraints 176 var variableRanges 177 192 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 193 var constraints = problemData.IntervalConstraints.EnabledConstraints; 194 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 195 178 196 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 179 197 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, 180 198 out var errorState); 181 199 182 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, 200 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, useSplitting, 183 201 out var error)) { 184 202 if (useSoftConstraints) { … … 188 206 nmse += penaltyMultiplier * error; 189 207 } 190 208 191 209 nmse = Math.Min(1.0, nmse); 192 210 } else { … … 206 224 IEnumerable<int> rows) { 207 225 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 208 EstimationLimitsParameter.ExecutionContext 209 ApplyLinearScalingParameter.ExecutionContext 226 EstimationLimitsParameter.ExecutionContext = context; 227 ApplyLinearScalingParameter.ExecutionContext = context; 210 228 211 229 var nmse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, 212 230 EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 213 problemData, rows, UseSoftConstraints, PenaltyMultiplier );231 problemData, rows, UseSoftConstraints, PenaltyMultiplier, UseIntervalSplitting); 214 232 215 233 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 216 EstimationLimitsParameter.ExecutionContext 217 ApplyLinearScalingParameter.ExecutionContext 234 EstimationLimitsParameter.ExecutionContext = null; 235 ApplyLinearScalingParameter.ExecutionContext = null; 218 236 219 237 return nmse; -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs
r17733 r17751 85 85 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 86 86 87 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, out double error))87 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, false, out double error)) 88 88 return 1.0; 89 89 -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs
r17735 r17751 191 191 // calculate result interval 192 192 if (!constraint.IsDerivative) { 193 resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, new ReadOnlyDictionary<string, Interval>(regionRanges) );193 resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, new ReadOnlyDictionary<string, Interval>(regionRanges), 0); 194 194 } 195 195 else { … … 201 201 } 202 202 203 resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, new ReadOnlyDictionary<string, Interval>(regionRanges) );203 resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, new ReadOnlyDictionary<string, Interval>(regionRanges), 0); 204 204 } 205 205 … … 226 226 public static bool ConstraintsSatisfied(IEnumerable<IntervalConstraint> constraints, 227 227 IReadOnlyDictionary<string, Interval> variableRanges, 228 ISymbolicExpressionTree solution, 228 ISymbolicExpressionTree solution, bool useSplitting, 229 229 out double error) { 230 var intervalInterpreter = new IntervalInterpreter() ;230 var intervalInterpreter = new IntervalInterpreter() {UseIntervalSplitting = useSplitting}; 231 231 error = 0.0; 232 232 var satisfied = true;
Note: See TracChangeset
for help on using the changeset viewer.