Changeset 16589 for branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators
- Timestamp:
- 02/05/19 14:50:21 (6 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs
r16582 r16589 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 [Item("Pearson R² Evaluator", "Calculates the square of the pearson correlation coefficient (also known as coefficient of determination) of a symbolic regression solution.")]31 [Item("Pearson R² Constraint Evaluator", "Calculates the square of the pearson correlation coefficient (also known as coefficient of determination) of a symbolic regression solution.")] 31 32 [StorableClass] 32 public class SymbolicRegressionSingleObjective PearsonRSquaredEvaluator : SymbolicRegressionSingleObjectiveEvaluator {33 public class SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 33 34 [StorableConstructor] 34 protected SymbolicRegressionSingleObjective PearsonRSquaredEvaluator(bool deserializing) : base(deserializing) { }35 protected SymbolicRegressionSingleObjective PearsonRSquaredEvaluator(SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator original, Cloner cloner)35 protected SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator(bool deserializing) : base(deserializing) { } 36 protected SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator(SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator original, Cloner cloner) 36 37 : base(original, cloner) { 37 38 } 38 39 public override IDeepCloneable Clone(Cloner cloner) { 39 return new SymbolicRegressionSingleObjective PearsonRSquaredEvaluator(this, cloner);40 return new SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator(this, cloner); 40 41 } 41 42 42 public SymbolicRegressionSingleObjective PearsonRSquaredEvaluator() : base() { }43 public SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator() : base() { } 43 44 44 45 public override bool Maximization { get { return true; } } … … 58 59 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 59 60 OnlineCalculatorError errorState; 61 62 IntervalConstraintsParser parser = new IntervalConstraintsParser(); 63 var constraints = parser.Parse(((RegressionProblemData) problemData).IntervalConstraintsParameter.Value.Value); 64 var intervalInterpreter = new IntervalInterpreter(); 65 var variableRanges = ((RegressionProblemData) problemData).VariableRangesParameter.Value.VariableIntervals; 66 67 68 foreach (var constraint in constraints) { 69 if (!variableRanges.ContainsKey(constraint.Variable)) 70 throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser)); 71 if (!constraint.IsDerivation) { 72 var res = intervalInterpreter.GetSymbolicExressionTreeInterval(solution, variableRanges); 73 if (!IntervalInBoundaries(constraint.Interval, res, constraint.InclusiveLowerBound, 74 constraint.InclusiveUpperBound)) { 75 return 0; 76 } 77 } else { 78 var tree = solution; 79 for (var i = 0; i < constraint.NumberOfDerivation; ++i) { 80 tree = DerivativeCalculator.Derive(tree, constraint.Variable); 81 } 82 var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree, variableRanges); 83 if (!IntervalInBoundaries(constraint.Interval, res, constraint.InclusiveLowerBound, 84 constraint.InclusiveUpperBound)) { 85 return 0; 86 } 87 } 88 } 89 60 90 61 91 double r; … … 86 116 return r2; 87 117 } 118 119 private static bool IntervalInBoundaries(Interval i1, Interval i2, bool inclusiveLower, bool inclusiveUpper) { 120 if (inclusiveLower) { 121 if (i2.LowerBound < i1.LowerBound) 122 return false; 123 } else { 124 if (i2.LowerBound <= i1.LowerBound) 125 return false; 126 } 127 128 if (inclusiveUpper) { 129 if (i2.UpperBound > i1.UpperBound) 130 return false; 131 } else { 132 if (i2.UpperBound >= i1.UpperBound) 133 return false; 134 } 135 136 return true; 137 } 88 138 } 89 139 }
Note: See TracChangeset
for help on using the changeset viewer.