Changeset 16800 for branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Timestamp:
- 04/17/19 14:37:55 (6 years ago)
- Location:
- branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs
r16781 r16800 61 61 62 62 //var constraints = IntervalConstraintsParser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value); 63 var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints.Where(x => x. IsChecked);63 var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints.Where(x => x.Enabled); 64 64 var intervalInterpreter = new IntervalInterpreter(); 65 var variableRanges = ((RegressionProblemData) problemData).VariableRangesParameter.Value.VariableIntervals;65 var variableRanges = ((RegressionProblemData) problemData).VariableRangesParameter.Value.VariableIntervals; 66 66 67 67 … … 92 92 93 93 private static bool HasConstraintVioluations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter, 94 Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution) {94 IDictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution) { 95 95 foreach (var constraint in constraints) { 96 96 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable)) -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs
r16756 r16800 64 64 var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals; 65 65 66 67 //foreach (var constraint in constraints) {68 // if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))69 // throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));70 // if (!constraint.IsDerivation) {71 // var res = intervalInterpreter.GetSymbolicExressionTreeInterval(solution, variableRanges);72 // if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,73 // constraint.InclusiveUpperBound)) {74 // return 0;75 // }76 // } else {77 // var tree = solution;78 // for (var i = 0; i < constraint.NumberOfDerivation; ++i) {79 // tree = DerivativeCalculator.Derive(tree, constraint.Variable);80 // }81 // var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree, variableRanges);82 // if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,83 // constraint.InclusiveUpperBound)) {84 // return 0;85 // }86 // }87 //}88 // TODO89 // m = new SymbolicRegressionModel(...)90 // m.Scale();91 92 // var e = m.GetEstimatedValues (TRAINING)93 // OnlinePearsonCalc.Calculate(e, TARGET_TRAIING)94 95 // scaledTree = model.Tree;96 97 // constraints mit scaledTree berechnen (auch die Ableitungen)98 99 66 double r; 100 67 if (applyLinearScaling) { … … 142 109 143 110 private static bool CheckConstraintsViolations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter, 144 Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) {111 IDictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) { 145 112 foreach (var constraint in constraints) { 146 113 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable)) -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionConstraintAnalyzer.cs
r16780 r16800 37 37 public class SymbolicRegressionConstraintAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicDataAnalysisInterpreterOperator, ISymbolicExpressionTreeAnalyzer { 38 38 private const string ConstraintViolationsResultName = "Constraint Violations"; 39 40 39 private const string ProblemDataParameterName = "ProblemData"; 41 40 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 42 41 43 42 #region parameter properties 43 44 44 public ILookupParameter<RegressionProblemData> RegressionProblemDataParameter { 45 get { return (ILookupParameter<RegressionProblemData>) Parameters[ProblemDataParameterName]; }45 get { return (ILookupParameter<RegressionProblemData>) Parameters[ProblemDataParameterName]; } 46 46 } 47 47 48 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { 48 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>) Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }49 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>) Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } 49 50 } 51 50 52 #endregion 53 51 54 #region properties 52 55 … … 58 61 get { return SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; } 59 62 } 63 60 64 #endregion 61 65 62 public virtual bool EnabledByDefault { 63 get { return false; } 64 } 66 public override bool EnabledByDefault => false; 65 67 66 68 [StorableConstructor] … … 68 70 } 69 71 70 protected SymbolicRegressionConstraintAnalyzer(SymbolicRegressionConstraintAnalyzer original, Cloner cloner) 71 : base(original, cloner) { 72 protected SymbolicRegressionConstraintAnalyzer(SymbolicRegressionConstraintAnalyzer original, Cloner cloner) : base(original, cloner) { 72 73 } 73 74 … … 85 86 } 86 87 87 public static Dictionary<IntervalConstraint, bool> CheckConstraints(ISymbolicExpressionTree model, 88 IRegressionProblemData problemData) { 89 var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints.Where(x => x.IsChecked); 88 public static Dictionary<IntervalConstraint, bool> CheckConstraints(ISymbolicExpressionTree model, IRegressionProblemData problemData) { 89 var constraints = problemData.IntervalConstraints.Constraints.Where(x => x.Enabled); 90 90 var constraintViolations = new Dictionary<IntervalConstraint, bool>(); 91 var variableRanges = ((RegressionProblemData)problemData).VariableRanges.VariableIntervals; 92 91 var variableRanges = problemData.VariableRanges.VariableIntervals; 93 92 foreach (var constraint in constraints) { 94 93 if (!constraintViolations.ContainsKey(constraint)) { … … 100 99 } 101 100 102 public static Dictionary<IntervalConstraint, bool> CheckConstraints(ISymbolicRegressionModel model, 103 IRegressionProblemData problemData) { 101 public static Dictionary<IntervalConstraint, bool> CheckConstraints(ISymbolicRegressionModel model, IRegressionProblemData problemData) { 104 102 return CheckConstraints(model.SymbolicExpressionTree, problemData); 105 103 } 106 104 107 public static bool CheckConstraint(ISymbolicExpressionTree model, Dictionary<string, Interval> variableRanges, 108 IntervalConstraint constraint) { 105 public static bool CheckConstraint(ISymbolicExpressionTree model, IDictionary<string, Interval> variableRanges, IntervalConstraint constraint) { 109 106 var intervalInterpreter = new IntervalInterpreter(); 110 if (constraint.Variable != null) { 111 if (!constraint.IsDerivation) { 112 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(model, 113 variableRanges); 114 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, 115 constraint.InclusiveUpperBound)) { 116 return false; 117 } 118 } else { 119 var dTree = model; 120 for (var i = 0; i < constraint.NumberOfDerivation; ++i) { 121 dTree = DerivativeCalculator.Derive(dTree, constraint.Variable); 122 } 123 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(dTree, 124 variableRanges); 125 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, 126 constraint.InclusiveUpperBound)) { 127 return false; 128 } 107 if (!constraint.IsDerivation) { 108 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(model, variableRanges); 109 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, constraint.InclusiveUpperBound)) { 110 return false; 111 } 112 } else { 113 var dTree = model; 114 for (var i = 0; i < constraint.NumberOfDerivation; ++i) { 115 dTree = DerivativeCalculator.Derive(dTree, constraint.Variable); 116 } 117 118 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(dTree, variableRanges); 119 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, constraint.InclusiveUpperBound)) { 120 return false; 129 121 } 130 122 } 123 131 124 return true; 132 125 } 133 126 134 static bool CheckConstraint(ISymbolicRegressionModel model, Dictionary<string, Interval> variableRanges, IntervalConstraint constraint) {127 static bool CheckConstraint(ISymbolicRegressionModel model, IDictionary<string, Interval> variableRanges, IntervalConstraint constraint) { 135 128 return CheckConstraint(model.SymbolicExpressionTree, variableRanges, constraint); 136 129 } … … 140 133 if (!results.ContainsKey(ConstraintViolationsResultName)) { 141 134 var newDataTable = new DataTable(ConstraintViolationsResultName); 142 results.Add(new Result(ConstraintViolationsResultName, "Chart displaying the constraint violations.", 143 newDataTable)); 135 results.Add(new Result(ConstraintViolationsResultName, "Chart displaying the constraint violations.", newDataTable)); 144 136 } 145 var dataTable = (DataTable)results[ConstraintViolationsResultName].Value; 137 138 var dataTable = (DataTable) results[ConstraintViolationsResultName].Value; 146 139 var problemData = RegressionProblemData; 147 140 var constraintViolations = new Dictionary<string, int>(); 148 149 var constraints = problemData.IntervalConstraintsParameter.Value.Constraints.Where(x => x.IsChecked); 150 141 var constraints = problemData.IntervalConstraintsParameter.Value.Constraints.Where(x => x.Enabled); 151 142 if (dataTable.Rows.Count == 0) { 152 143 foreach (var constraint in constraints) { … … 163 154 foreach (var tree in this.SymbolicExpressionTree) { 164 155 var checkedConstraints = CheckConstraints(tree, problemData); 165 166 156 foreach (var kvp in checkedConstraints) { 167 if (!kvp.Value) 168 constraintViolations[kvp.Key.Expression]++; 157 if (!kvp.Value) constraintViolations[kvp.Key.Expression]++; 169 158 } 170 159 } … … 173 162 dataTable.Rows[kvp.Key].Values.Add(kvp.Value); 174 163 } 164 175 165 return base.Apply(); 176 166 } -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
r16761 r16800 21 21 22 22 using System; 23 using System.Collections; 24 using System.Collections.Generic; 23 25 using System.Linq; 24 26 using HEAL.Attic; … … 50 52 51 53 private const string IntervalEvaluationResultName = "Interval Evaluation"; 52 private const string EstimatedDerivationInterval = "Interval";53 54 54 55 public new ISymbolicRegressionModel Model { … … 151 152 estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue())); 152 153 Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults)); 154 Add(new Result(IntervalEvaluationResultName, "Results concerning the derivation of symbolic regression solution", GetIntervalEvaluations())); 153 155 CalculateResults(); 154 156 } … … 163 165 var intervalEvaluation = new NamedIntervals(); 164 166 var interpreter = new IntervalInterpreter(); 165 var variableRanges = (ProblemData as RegressionProblemData)?.VariableRangesParameter.Value.VariableIntervals;167 var variableRanges = ProblemData.VariableRanges.VariableIntervals; 166 168 167 169 if (variableRanges != null) { 168 intervalEvaluation. Add($"Target {ProblemData.TargetVariable}", new Interval(variableRanges[ProblemData.TargetVariable].LowerBound, variableRanges[ProblemData.TargetVariable].UpperBound));169 intervalEvaluation. Add("Modell Interval", interpreter.GetSymbolicExpressionTreeInterval(Model.SymbolicExpressionTree, variableRanges));170 intervalEvaluation.VariableIntervals.Add($"Target {ProblemData.TargetVariable}", new Interval(variableRanges[ProblemData.TargetVariable].LowerBound, variableRanges[ProblemData.TargetVariable].UpperBound)); 171 intervalEvaluation.VariableIntervals.Add("Modell Interval", interpreter.GetSymbolicExpressionTreeInterval(Model.SymbolicExpressionTree, variableRanges)); 170 172 171 173 foreach (var derivate in variableRanges) { … … 174 176 var derivedResultInterval = interpreter.GetSymbolicExpressionTreeInterval(derived, variableRanges); 175 177 176 intervalEvaluation. Add(" \u2202f/\u2202" + derivate.Key,178 intervalEvaluation.VariableIntervals.Add(" \u2202f/\u2202" + derivate.Key, 177 179 new Interval(derivedResultInterval.LowerBound, derivedResultInterval.UpperBound)); 178 180 }
Note: See TracChangeset
for help on using the changeset viewer.