Changeset 16713
- Timestamp:
- 03/26/19 11:37:29 (6 years ago)
- Location:
- branches/2971_named_intervals
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r16685 r16713 204 204 <Compile Include="Plugin.cs" /> 205 205 <Compile Include="SingleObjective\ConstantOptimizationAnalyzer.cs" /> 206 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionConstraintSatisfactionEvaluator.cs" /> 206 207 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" /> 207 208 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs" /> -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs
r16645 r16713 22 22 using System; 23 23 using System.Collections.Generic; 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HEAL.Attic;29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 59 59 OnlineCalculatorError errorState = OnlineCalculatorError.None; 60 60 61 IntervalConstraintsParser parser = new IntervalConstraintsParser(); 62 var constraints = parser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value); 61 var constraints = IntervalConstraintsParser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value); 63 62 var intervalInterpreter = new IntervalInterpreter(); 64 63 var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals; … … 90 89 } 91 90 92 private static bool HasConstraintVioluations( List<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,91 private static bool HasConstraintVioluations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter, 93 92 Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution) { 94 93 foreach (var constraint in constraints) { … … 96 95 throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser)); 97 96 if (!constraint.IsDerivation) { 98 var res = intervalInterpreter.GetSymbolicEx ressionTreeInterval(solution, variableRanges);97 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, variableRanges); 99 98 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, 100 99 constraint.InclusiveUpperBound)) { … … 106 105 tree = DerivativeCalculator.Derive(tree, constraint.Variable); 107 106 } 108 var res = intervalInterpreter.GetSymbolicEx ressionTreeInterval(tree, variableRanges);107 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges); 109 108 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, 110 109 constraint.InclusiveUpperBound)) { -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs
r16644 r16713 22 22 using System; 23 23 using System.Collections.Generic; 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HEAL.Attic;29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 59 59 OnlineCalculatorError errorState = OnlineCalculatorError.None; 60 60 61 IntervalConstraintsParser parser = new IntervalConstraintsParser(); 62 var constraints = parser.Parse(((RegressionProblemData) problemData).IntervalConstraintsParameter.Value.Value); 61 var constraints = IntervalConstraintsParser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value); 63 62 var intervalInterpreter = new IntervalInterpreter(); 64 var variableRanges = ((RegressionProblemData) 63 var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals; 65 64 66 65 … … 92 91 // var e = m.GetEstimatedValues (TRAINING) 93 92 // OnlinePearsonCalc.Calculate(e, TARGET_TRAIING) 94 93 95 94 // scaledTree = model.Tree; 96 95 … … 120 119 } 121 120 if (errorState != OnlineCalculatorError.None) return double.NaN; 122 return r *r;121 return r * r; 123 122 } 124 123 … … 141 140 } 142 141 143 private static bool CheckConstraintsViolations( List<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,142 private static bool CheckConstraintsViolations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter, 144 143 Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) { 145 144 foreach (var constraint in constraints) { … … 147 146 throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser)); 148 147 if (!constraint.IsDerivation) { 149 var res = intervalInterpreter.GetSymbolicEx ressionTreeInterval(solution, variableRanges);148 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, variableRanges); 150 149 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, 151 150 constraint.InclusiveUpperBound)) { … … 158 157 tree = DerivativeCalculator.Derive(tree, constraint.Variable); 159 158 } 160 var res = intervalInterpreter.GetSymbolicEx ressionTreeInterval(tree, variableRanges);159 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges); 161 160 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, 162 161 constraint.InclusiveUpperBound)) { -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionConstraintAnalyzer.cs
r16644 r16713 24 24 using System; 25 25 using System.Collections.Generic; 26 using HEAL.Attic; 26 27 using HeuristicLab.Analysis; 27 28 using HeuristicLab.Common; … … 30 31 using HeuristicLab.Optimization; 31 32 using HeuristicLab.Parameters; 32 using HEAL.Attic;33 33 34 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 86 86 public override IOperation Apply() { 87 87 var results = ResultCollectionParameter.ActualValue; 88 IntervalConstraintsParser parser = new IntervalConstraintsParser();89 88 var intervalInterpreter = new IntervalInterpreter(); 90 89 if (!results.ContainsKey(ConstraintViolationsResultName)) { … … 99 98 var constraintViolations = new Dictionary<string, int>(); 100 99 101 var constraints = 102 parser.Parse(problemData.IntervalConstraints.Value); 100 var constraints = IntervalConstraintsParser.Parse(problemData.IntervalConstraints.Value); 103 101 var variableRanges = problemData.VariableRanges.VariableIntervals; 104 102 … … 122 120 nameof(IntervalConstraintsParser)); 123 121 if (!constraint.IsDerivation) { 124 var res = intervalInterpreter.GetSymbolicEx ressionTreeInterval(tree,122 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, 125 123 variableRanges); 126 124 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, … … 134 132 } 135 133 136 var res = intervalInterpreter.GetSymbolicEx ressionTreeInterval(dTree,134 var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(dTree, 137 135 variableRanges); 138 136 if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
r16644 r16713 21 21 22 22 using System.Linq; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 28 using HeuristicLab.Optimization; 28 using HEAL.Attic;29 29 using HeuristicLab.Problems.DataAnalysis.Implementation; 30 30 … … 168 168 if (variableRanges != null) { 169 169 intervalEvaluation.Add($"Target {ProblemData.TargetVariable}", new Interval(variableRanges[ProblemData.TargetVariable].LowerBound, variableRanges[ProblemData.TargetVariable].UpperBound)); 170 intervalEvaluation.Add("Modell Interval", interpreter.GetSymbolicEx ressionTreeInterval(Model.SymbolicExpressionTree, variableRanges));170 intervalEvaluation.Add("Modell Interval", interpreter.GetSymbolicExpressionTreeInterval(Model.SymbolicExpressionTree, variableRanges)); 171 171 172 172 foreach (var derivate in variableRanges) { 173 173 if (derivate.Key != ProblemData.TargetVariable) { 174 174 var derived = DerivativeCalculator.Derive(Model.SymbolicExpressionTree, derivate.Key); 175 var derivedResultInterval = interpreter.GetSymbolicEx ressionTreeInterval(derived, variableRanges);175 var derivedResultInterval = interpreter.GetSymbolicExpressionTreeInterval(derived, variableRanges); 176 176 intervalEvaluation.Add(" ?f/?" + derivate.Key, 177 177 new Interval(derivedResultInterval.LowerBound, derivedResultInterval.UpperBound)); -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r16643 r16713 105 105 <Reference Include="EPPlus-4.0.3, Version=4.0.3.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL"> 106 106 <Private>False</Private> 107 <HintPath>..\..\..\..\trunk\bin\EPPlus-4.0.3.dll</HintPath> 107 108 </Reference> 108 109 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraintsParser.cs
r16632 r16713 5 5 6 6 namespace HeuristicLab.Problems.DataAnalysis { 7 public class IntervalConstraintsParser { 8 public IntervalConstraintsParser() {} 9 private List<IntervalConstraint> intervalConstraints = new List<IntervalConstraint>(); 10 public List<IntervalConstraint> Parse(string input) { 7 public static class IntervalConstraintsParser { 8 public static IEnumerable<IntervalConstraint> Parse(string input) { 11 9 var options = RegexOptions.Multiline | RegexOptions.IgnoreCase; 12 10 var matches = Regex.Matches(input, @"^(.*)\bin\b\s*([\[\]])(.*[^\s])(\s*\.\.\s*)([^\s].*)([\[\]])\r?\s*$", options); 13 11 14 12 for (var i = 0; i < matches.Count; ++i) { 15 if (matches[i].Groups.Count == 7) { 13 if (matches[i].Groups.Count == 7) { 16 14 var intervalConstraint = new IntervalConstraint(); 17 15 //pattern 1 = defintion … … 38 36 intervalConstraint.InclusiveLowerBound = (matches[i].Groups[2].Value == "["); 39 37 intervalConstraint.InclusiveUpperBound = (matches[i].Groups[6].Value == "]"); 40 intervalConstraint.Interval = new Interval(ParseIntervalBounds(matches[i].Groups[3].Value.Replace(" ", string.Empty)), 38 intervalConstraint.Interval = new Interval(ParseIntervalBounds(matches[i].Groups[3].Value.Replace(" ", string.Empty)), 41 39 ParseIntervalBounds(matches[i].Groups[5].Value.Replace(" ", string.Empty))); 42 40 43 intervalConstraints.Add(intervalConstraint);41 yield return intervalConstraint; 44 42 } else { 45 43 throw new ArgumentException($"The given constraint: {matches[i].Value} is not valid."); 46 44 } 47 45 } 48 49 return intervalConstraints;50 46 } 51 47 … … 59 55 return double.NegativeInfinity; 60 56 default: { 61 if (double.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) { 62 return value; 63 } else { 64 throw new ArgumentException("The given Interval in the constraint is not valid."); 57 if (double.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) { 58 return value; 59 } else { 60 throw new ArgumentException("The given Interval in the constraint is not valid."); 61 } 65 62 } 66 }67 63 } 68 64 }
Note: See TracChangeset
for help on using the changeset viewer.