Changeset 16589 for branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Timestamp:
- 02/05/19 14:50:21 (6 years ago)
- Location:
- branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r16556 r16589 183 183 <Compile Include="SingleObjective\ConstantOptimizationAnalyzer.cs" /> 184 184 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" /> 185 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs" /> 185 186 <Compile Include="SingleObjective\SymbolicRegressionSolutionsAnalyzer.cs" /> 186 187 <Compile Include="SymbolicRegressionPhenotypicDiversityAnalyzer.cs" /> -
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 } -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
r16556 r16589 49 49 private const string TestNaNEvaluationsResultName = "Test NaN Evaluations"; 50 50 51 private const string EstimatedDerivatesResultName = "Derivates of the Model";51 private const string IntervalEvaluationResultName = "Interval Evaluation"; 52 52 private const string EstimatedDerivationInterval = "Interval"; 53 53 … … 101 101 } 102 102 103 private ResultCollection EstimatedDerivateResultCollection => 104 (ResultCollection) this[EstimatedDerivatesResultName].Value; 105 106 public NamedIntervals EstimationInterval => 107 (NamedIntervals) EstimatedDerivateResultCollection[EstimatedDerivationInterval].Value; 103 private NamedIntervals IntervalEvaluaitonCollection => 104 (NamedIntervals) this[IntervalEvaluationResultName].Value; 105 108 106 109 107 … … 132 130 RecalculateResults(); 133 131 134 var estimationDerivatesResult = new ResultCollection();135 Add(new Result( EstimatedDerivatesResultName, "Results concerning the derivation of symbolic regression solution", estimationDerivatesResult));136 CalculateDerivates(estimationDerivatesResult);132 var namedIntervalCollection = new NamedIntervals(); 133 Add(new Result(IntervalEvaluationResultName, "Results concerning the derivation of symbolic regression solution", namedIntervalCollection)); 134 GetIntervalEvaulations(namedIntervalCollection); 137 135 } 138 136 … … 155 153 CalculateResults(); 156 154 157 var estimationDerivatesResult = new ResultCollection();158 Add(new Result( EstimatedDerivatesResultName, "Results concerning the derivation of symbolic regression solution", estimationDerivatesResult));159 CalculateDerivates(estimationDerivatesResult);155 var namedIntervalCollection = new NamedIntervals(); 156 Add(new Result(IntervalEvaluationResultName, "Results concerning the derivation of symbolic regression solution", namedIntervalCollection)); 157 GetIntervalEvaulations(namedIntervalCollection); 160 158 } 161 159 } … … 166 164 } 167 165 168 private void CalculateDerivates(ResultCollection estimationDerivatesResults) {166 private void GetIntervalEvaulations(NamedIntervals intervalEvaluation) { 169 167 var interpreter = new IntervalInterpreter(); 170 var variableRanges = (ProblemData as RegressionProblemData).VariableRangesParameter.Value.VariableIntervals; 171 var customIntervals = new Dictionary<string, Interval>(); 172 var intervals = new NamedIntervals(); 173 174 foreach (var variable in variableRanges) { 175 customIntervals.Add(variable.Key, new Interval(variable.Value.LowerBound, variable.Value.UpperBound)); 176 } 177 178 foreach (var derivate in customIntervals) { 179 if (derivate.Key != ProblemData.TargetVariable) { 180 var derived = DerivativeCalculator.Derive(Model.SymbolicExpressionTree, derivate.Key); 181 var derivedResultInterval = interpreter.GetSymbolicExressionTreeInterval(derived, customIntervals); 182 intervals.Add(" ∂f/∂" + derivate.Key, 183 new Interval(derivedResultInterval.LowerBound, derivedResultInterval.UpperBound)); 168 var variableRanges = (ProblemData as RegressionProblemData)?.VariableRangesParameter.Value.VariableIntervals; 169 170 if (variableRanges != null) { 171 intervalEvaluation.Add($"Target {ProblemData.TargetVariable}", new Interval(variableRanges[ProblemData.TargetVariable].LowerBound, variableRanges[ProblemData.TargetVariable].UpperBound)); 172 intervalEvaluation.Add("Modell Interval", interpreter.GetSymbolicExressionTreeInterval(Model.SymbolicExpressionTree, variableRanges)); 173 174 foreach (var derivate in variableRanges) { 175 if (derivate.Key != ProblemData.TargetVariable) { 176 var derived = DerivativeCalculator.Derive(Model.SymbolicExpressionTree, derivate.Key); 177 var derivedResultInterval = interpreter.GetSymbolicExressionTreeInterval(derived, variableRanges); 178 intervalEvaluation.Add(" ∂f/∂" + derivate.Key, 179 new Interval(derivedResultInterval.LowerBound, derivedResultInterval.UpperBound)); 180 } 184 181 } 185 182 } 186 estimationDerivatesResults.AddOrUpdateResult("Derived Intervals", intervals);187 188 183 } 189 184
Note: See TracChangeset
for help on using the changeset viewer.