Changeset 16851 for branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators
- Timestamp:
- 04/19/19 14:35:08 (6 years ago)
- Location:
- branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs
r16844 r16851 58 58 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 59 59 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 60 OnlineCalculatorError errorState = OnlineCalculatorError.None;61 60 62 //var constraints = IntervalConstraintsParser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value); 63 var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints.Where(x => x.Enabled); 64 var intervalInterpreter = new IntervalInterpreter(); 65 var variableRanges = ((RegressionProblemData) problemData).VariableRangesParameter.Value.VariableIntervals; 66 61 var constraints = problemData.IntervalConstraints.Constraints.Where(x => x.Enabled); 62 var variableRanges = problemData.VariableRanges.VariableIntervals; 67 63 68 64 var r2 = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, applyLinearScaling, 10); 69 if ( HasConstraintVioluations(constraints, intervalInterpreter, variableRanges, tree)) {65 if (SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree)) { 70 66 r2 = 0; 71 67 } -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs
r16800 r16851 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; … … 59 60 OnlineCalculatorError errorState = OnlineCalculatorError.None; 60 61 61 //var constraints = IntervalConstraintsParser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value); 62 var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints; 63 var intervalInterpreter = new IntervalInterpreter(); 64 var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals; 62 var constraints = problemData.IntervalConstraints.Constraints.Where(x => x.Enabled); 63 var variableRanges = problemData.VariableRanges.VariableIntervals; 64 var tree = solution; 65 65 66 66 double r; … … 70 70 var model = new SymbolicRegressionModel(problemData.TargetVariable, solution, interpreter, lowerEstimationLimit, upperEstimationLimit); 71 71 model.Scale(problemData); 72 var e = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices); 73 var scaledTree = model.SymbolicExpressionTree; 72 tree = model.SymbolicExpressionTree; 74 73 errorState = rCalculator.ErrorState; 75 if (CheckConstraintsViolations(constraints, intervalInterpreter, variableRanges, scaledTree, out var val)) { 76 r = val; 77 } else { 78 r = rCalculator.R; 79 } 74 r = rCalculator.R; 80 75 } else { 81 76 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 82 if (CheckConstraintsViolations(constraints, intervalInterpreter, variableRanges, solution, out var val)) { 83 r = val; 84 } else { 85 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 86 } 77 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 87 78 } 79 80 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree)) { 81 return 0; 82 } 83 88 84 if (errorState != OnlineCalculatorError.None) return double.NaN; 89 85 return r * r; … … 107 103 return r2; 108 104 } 109 110 private static bool CheckConstraintsViolations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,111 IDictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) {112 foreach (var constraint in constraints) {113 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))114 throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));115 if (!constraint.IsDerivation) {116 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, variableRanges);117 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,118 constraint.InclusiveUpperBound)) {119 r = 0;120 return true;121 }122 } else {123 var tree = solution;124 for (var i = 0; i < constraint.NumberOfDerivation; ++i) {125 tree = DerivativeCalculator.Derive(tree, constraint.Variable);126 }127 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges);128 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,129 constraint.InclusiveUpperBound)) {130 r = 0;131 return true;132 }133 }134 }135 r = 1;136 return false;137 }138 105 } 139 106 } -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs
r16644 r16851 22 22 using HeuristicLab.Common; 23 23 using HEAL.Attic; 24 25 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 26 25 [StorableType("7EB90F03-4385-474F-BDE7-3B133E8FEAAB")]
Note: See TracChangeset
for help on using the changeset viewer.