Changeset 17906
- Timestamp:
- 03/16/21 15:26:50 (4 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/NMSEConstraintsEvaluator.cs
r17903 r17906 33 33 34 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.MultiObjective { 35 [Item("NMSE Evaluator (multi-objective, with shape-constraints)",35 [Item("NMSE Evaluator with shape-constraints", 36 36 "Calculates the NMSE and the constraints violations of a symbolic regression solution as objectives.")] 37 37 [StorableType("8E9D76B7-ED9C-43E7-9898-01FBD3633880")] -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/ShapeConstraintsAnalyzer.cs
r17903 r17906 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 32 32 [StorableType("4318C6BD-E0A1-45FE-AC30-96E7F73B51FB")] 33 [Item("Shape -constraints analyser", "Analyzes the number of shape-constraint violations of symbolic regression models.")]33 [Item("ShapeConstraintsAnalyzer", "Analyzes the number of shape-constraint violations of symbolic regression models.")] 34 34 public class ShapeConstraintsAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer { 35 35 private const string ProblemDataParameterName = "ProblemData"; … … 106 106 var estimator = new IntervalArithBoundsEstimator(); 107 107 108 if ( constraintViolationsTable.Rows.Any())108 if (!constraintViolationsTable.Rows.Any()) 109 109 foreach (var constraint in constraints) 110 110 constraintViolationsTable.Rows.Add(new DataRow(constraint.ToString())); -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSEConstraintsEvaluator.cs
r17903 r17906 32 32 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 34 [Item("NMSE Evaluator (single-objective, with shape-constraints)", "Calculates NMSE of a symbolic regression solution and checks constraints the fitness is a combination of NMSE and constraint violations.")]34 [Item("NMSE Evaluator with shape-constraints", "Calculates NMSE of a symbolic regression solution and checks constraints the fitness is a combination of NMSE and constraint violations.")] 35 35 [StorableType("27473973-DD8D-4375-997D-942E2280AE8E")] 36 36 public class NMSEConstraintsEvaluator : SymbolicRegressionSingleObjectiveEvaluator { -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithCompiledExpressionBoundsEstimator.cs
r17902 r17906 194 194 return Expression.Divide(e1, e2); 195 195 } 196 case OpCodes.AnalyticQuotient: { 197 var a = expr(node.GetSubtree(0)); 198 var b = expr(node.GetSubtree(1)); 199 var fun = typeof(Interval).GetMethod(methodName[opCode], new[] { a.Type, b.Type }); 200 return Expression.Call(fun, a, b); 201 } 196 202 // all these cases share the same code: get method info by name, emit call expression 197 203 case OpCodes.Exp: … … 205 211 case OpCodes.SquareRoot: 206 212 case OpCodes.CubeRoot: 207 case OpCodes.Absolute: 208 case OpCodes.AnalyticQuotient: { 213 case OpCodes.Absolute: { 209 214 var arg = expr(node.GetSubtree(0)); 210 215 var fun = typeof(Interval).GetMethod(methodName[opCode], new[] { arg.Type }); -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs
r17902 r17906 39 39 var varRanges = variableRanges.GetReadonlyDictionary(); 40 40 41 if ( constraint.Variable != null&& !varRanges.ContainsKey(constraint.Variable)) {41 if (!string.IsNullOrEmpty(constraint.Variable) && !varRanges.ContainsKey(constraint.Variable)) { 42 42 throw new ArgumentException( 43 $" The given variable {constraint.Variable} in the constraint does not exist in the model.",43 $"No variable range found for variable {constraint.Variable} used in the constraints.", 44 44 nameof(constraint)); 45 45 } -
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r17902 r17906 102 102 <HintPath>..\..\bin\ALGLIB-3.7.0.dll</HintPath> 103 103 <Private>False</Private> 104 </Reference> 105 <Reference Include="HEAL.Attic, Version=1.5.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 106 <SpecificVersion>False</SpecificVersion> 107 <HintPath>..\..\bin\HEAL.Attic.dll</HintPath> 104 108 </Reference> 105 109 <Reference Include="System" /> -
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/ShapeConstraintsView.cs
r17902 r17906 50 50 this.shapeConstraintsView.Content = Content; 51 51 UpdateControl(); 52 errorOutput.Text = ""; 52 53 } 53 54 … … 77 78 protected override void SetEnabledStateOfControls() { 78 79 constraintsInput.Enabled = Content != null && !Locked && !ReadOnly; 80 parseBtn.Enabled = Content != null && !Locked && !ReadOnly; 79 81 } 80 82 … … 90 92 errorOutput.ForeColor = Color.DarkGreen; 91 93 } catch (ArgumentException ex) { 92 errorOutput.Text = ex.Message .Replace("Parameter name", "@Line");94 errorOutput.Text = ex.Message; 93 95 errorOutput.ForeColor = Color.DarkRed; 94 96 } finally { -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs
r17902 r17906 35 35 } 36 36 37 //[Storable]38 37 private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>(); 39 38 -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraint.cs
r17902 r17906 171 171 private string GenerateExpressionString() { 172 172 string expression; 173 173 string write(double val) => double.IsPositiveInfinity(val) ? "inf." : double.IsNegativeInfinity(val) ? "-inf." : $"{val}"; 174 174 if (!IsDerivative) { 175 expression = string.Format($"f in [{ Interval?.LowerBound} .. {Interval?.UpperBound}]");175 expression = string.Format($"f in [{write(Interval.LowerBound)} .. {write(Interval.UpperBound)}]"); 176 176 if (Regions != null) { 177 177 foreach (var region in Regions.GetReadonlyDictionary()) 178 expression += $", {region.Key} in [{ region.Value.LowerBound} .. {region.Value.UpperBound}]";178 expression += $", {region.Key} in [{write(region.Value.LowerBound)} .. {write(region.Value.UpperBound)}]"; 179 179 } 180 180 if (Weight != 1.0) { … … 194 194 derivationString = "³"; break; 195 195 } 196 expression = string.Format($"∂{derivationString}f/∂{Variable}{derivationString} in [{ Interval?.LowerBound} .. {Interval?.UpperBound}]");196 expression = string.Format($"∂{derivationString}f/∂{Variable}{derivationString} in [{write(Interval.LowerBound)} .. {write(Interval.UpperBound)}]"); 197 197 if (Regions != null) { 198 198 foreach (var region in Regions.GetReadonlyDictionary()) 199 expression += $", {region.Key} in [{ region.Value.LowerBound} .. {region.Value.UpperBound}]";199 expression += $", {region.Key} in [{write(region.Value.LowerBound)} .. {write(region.Value.UpperBound)}]"; 200 200 } 201 201 if (Weight != 1.0) { -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs
r17902 r17906 61 61 } else { 62 62 throw new 63 ArgumentException( "Error at your constraints definition constraints have to start with (f | d | ∂ | #)",63 ArgumentException($"Error at in definition {expr}. Constraints have to start with (f | d | ∂ | #)", 64 64 nameof(expr)); 65 65 } … … 68 68 // [124 .. 145] 69 69 private const string intervalRegex = @"\s*[\[]" + 70 @"\s*(?<lowerBound>[^\s \.;]*)" +70 @"\s*(?<lowerBound>[^\s;]*)" + 71 71 @"\s*(\.{2}|\s+|;)" + 72 72 @"\s*(?<upperBound>[^\s\]]*)" + … … 76 76 private const string weightRegex = @"\s*(weight:\s*(?<weight>\S*))?"; 77 77 public static ShapeConstraint ParseFunctionRangeConstraint(string expr) { 78 if (!expr.StartsWith("f")) throw new ArgumentException( "Invalid function range constraint(e.g. f in [1..2])", nameof(expr));78 if (!expr.StartsWith("f")) throw new ArgumentException($"Invalid function range constraint {expr} (e.g. f in [1..2])", nameof(expr)); 79 79 var start = "f".Length; 80 80 var end = expr.Length; … … 95 95 intervalRegex + 96 96 @"(" + 97 @"\s*,\s*" + variableRegex +97 @"\s*,\s*" + variableRegex + 98 98 @"\s *\bin\b" + 99 99 intervalRegex + 100 100 @")*" + 101 101 weightRegex 102 ); 102 ); 103 103 104 104 … … 125 125 regions.AddInterval(region.Key, region.Value); 126 126 else 127 throw new ArgumentException( "A constraint cannot containmultiple regions of the same variable.");127 throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable."); 128 128 } 129 129 return new ShapeConstraint(interval, regions, weight); … … 131 131 return new ShapeConstraint(interval, weight); 132 132 } else 133 throw new ArgumentException( "The inserted target constraintis not valid.", nameof(expr));133 throw new ArgumentException($"The inserted target constraint {expr} is not valid.", nameof(expr)); 134 134 } 135 135 public static ShapeConstraint ParseDerivationConstraint(string expr) { … … 149 149 @")*" + 150 150 weightRegex 151 ); 151 ); 152 152 153 153 if (match.Success) { … … 161 161 if (enumeratorNumDeriv != "" || denominatorNumDeriv != "") { 162 162 if (enumeratorNumDeriv == "" || denominatorNumDeriv == "") 163 throw new ArgumentException( "Number of derivation has to be written on both sides.", nameof(expr));163 throw new ArgumentException($"Number of derivation has to be written on both sides in {expr}.", nameof(expr)); 164 164 if (enumeratorNumDeriv != denominatorNumDeriv) 165 throw new ArgumentException( "Derivation number is not equal on both sides.", nameof(expr));165 throw new ArgumentException($"Derivation number is not equal on both sides in {expr}.", nameof(expr)); 166 166 } 167 167 … … 187 187 regions.AddInterval(region.Key, region.Value); 188 188 else 189 throw new ArgumentException( "A constraint cannot containmultiple regions of the same variable.");189 throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable."); 190 190 } 191 191 return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight); … … 193 193 return new ShapeConstraint(variable, numberOfDerivation, interval, weight); 194 194 } else 195 throw new ArgumentException( "The inserted derivation constraintis not valid.", nameof(expr));195 throw new ArgumentException($"The inserted derivation constraint {expr} is not valid.", nameof(expr)); 196 196 } 197 197 … … 220 220 var valid = double.TryParse(input, out var value); 221 221 if (!valid) { 222 throw new ArgumentException( "Invalid value (valid value format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")");222 throw new ArgumentException($"Invalid value {input} (valid value format: \"" + "+inf. | inf. | -inf. | " + FormatPatterns.GetDoubleFormatPattern() + "\")"); 223 223 } 224 224
Note: See TracChangeset
for help on using the changeset viewer.