Changeset 17906


Ignore:
Timestamp:
03/16/21 15:26:50 (16 months ago)
Author:
gkronber
Message:

#3073 bugfixing

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/NMSEConstraintsEvaluator.cs

    r17903 r17906  
    3333
    3434namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.MultiObjective {
    35   [Item("NMSE Evaluator (multi-objective, with shape-constraints)",
     35  [Item("NMSE Evaluator with shape-constraints",
    3636    "Calculates the NMSE and the constraints violations of a symbolic regression solution as objectives.")]
    3737  [StorableType("8E9D76B7-ED9C-43E7-9898-01FBD3633880")]
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/ShapeConstraintsAnalyzer.cs

    r17903 r17906  
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3232  [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.")]
    3434  public class ShapeConstraintsAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer {
    3535    private const string ProblemDataParameterName = "ProblemData";
     
    106106      var estimator = new IntervalArithBoundsEstimator();
    107107
    108       if (constraintViolationsTable.Rows.Any())
     108      if (!constraintViolationsTable.Rows.Any())
    109109        foreach (var constraint in constraints)
    110110          constraintViolationsTable.Rows.Add(new DataRow(constraint.ToString()));
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSEConstraintsEvaluator.cs

    r17903 r17906  
    3232
    3333namespace 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.")]
    3535  [StorableType("27473973-DD8D-4375-997D-942E2280AE8E")]
    3636  public class NMSEConstraintsEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithCompiledExpressionBoundsEstimator.cs

    r17902 r17906  
    194194            return Expression.Divide(e1, e2);
    195195          }
     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          }
    196202        // all these cases share the same code: get method info by name, emit call expression
    197203        case OpCodes.Exp:
     
    205211        case OpCodes.SquareRoot:
    206212        case OpCodes.CubeRoot:
    207         case OpCodes.Absolute:
    208         case OpCodes.AnalyticQuotient: {
     213        case OpCodes.Absolute: {
    209214            var arg = expr(node.GetSubtree(0));
    210215            var fun = typeof(Interval).GetMethod(methodName[opCode], new[] { arg.Type });
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs

    r17902 r17906  
    3939      var varRanges = variableRanges.GetReadonlyDictionary();
    4040
    41       if (constraint.Variable != null && !varRanges.ContainsKey(constraint.Variable)) {
     41      if (!string.IsNullOrEmpty(constraint.Variable) && !varRanges.ContainsKey(constraint.Variable)) {
    4242        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.",
    4444          nameof(constraint));
    4545      }
  • trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r17902 r17906  
    102102      <HintPath>..\..\bin\ALGLIB-3.7.0.dll</HintPath>
    103103      <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>
    104108    </Reference>
    105109    <Reference Include="System" />
  • trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/ShapeConstraintsView.cs

    r17902 r17906  
    5050      this.shapeConstraintsView.Content = Content;
    5151      UpdateControl();
     52      errorOutput.Text = "";
    5253    }
    5354
     
    7778    protected override void SetEnabledStateOfControls() {
    7879      constraintsInput.Enabled = Content != null && !Locked && !ReadOnly;
     80      parseBtn.Enabled = Content != null && !Locked && !ReadOnly;
    7981    }
    8082
     
    9092          errorOutput.ForeColor = Color.DarkGreen;
    9193        } catch (ArgumentException ex) {
    92           errorOutput.Text = ex.Message.Replace("Parameter name", "@Line");
     94          errorOutput.Text = ex.Message;
    9395          errorOutput.ForeColor = Color.DarkRed;
    9496        } finally {
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs

    r17902 r17906  
    3535    }
    3636
    37     //[Storable]
    3837    private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>();
    3938
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraint.cs

    r17902 r17906  
    171171    private string GenerateExpressionString() {
    172172      string expression;
    173 
     173      string write(double val) => double.IsPositiveInfinity(val) ? "inf." : double.IsNegativeInfinity(val) ? "-inf." : $"{val}";
    174174      if (!IsDerivative) {
    175         expression = string.Format($"f in [{Interval?.LowerBound} .. {Interval?.UpperBound}]");
     175        expression = string.Format($"f in [{write(Interval.LowerBound)} .. {write(Interval.UpperBound)}]");
    176176        if (Regions != null) {
    177177          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)}]";
    179179        }
    180180        if (Weight != 1.0) {
     
    194194          derivationString = "³"; break;
    195195      }
    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)}]");
    197197      if (Regions != null) {
    198198        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)}]";
    200200      }
    201201      if (Weight != 1.0) {
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs

    r17902 r17906  
    6161      } else {
    6262        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 | ∂ | #)",
    6464                            nameof(expr));
    6565      }
     
    6868    // [124 .. 145]
    6969    private const string intervalRegex = @"\s*[\[]" +
    70                                          @"\s*(?<lowerBound>[^\s\.;]*)" +
     70                                         @"\s*(?<lowerBound>[^\s;]*)" +
    7171                                         @"\s*(\.{2}|\s+|;)" +
    7272                                         @"\s*(?<upperBound>[^\s\]]*)" +
     
    7676    private const string weightRegex = @"\s*(weight:\s*(?<weight>\S*))?";
    7777    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));
    7979      var start = "f".Length;
    8080      var end = expr.Length;
     
    9595                    intervalRegex +
    9696                    @"(" +
    97                       @"\s*,\s*"+ variableRegex +
     97                      @"\s*,\s*" + variableRegex +
    9898                      @"\s *\bin\b" +
    9999                      intervalRegex +
    100100                    @")*" +
    101101                    weightRegex
    102                     ); 
     102                    );
    103103
    104104
     
    125125              regions.AddInterval(region.Key, region.Value);
    126126            else
    127               throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
     127              throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable.");
    128128          }
    129129          return new ShapeConstraint(interval, regions, weight);
     
    131131          return new ShapeConstraint(interval, weight);
    132132      } else
    133         throw new ArgumentException("The inserted target constraint is not valid.", nameof(expr));
     133        throw new ArgumentException($"The inserted target constraint {expr} is not valid.", nameof(expr));
    134134    }
    135135    public static ShapeConstraint ParseDerivationConstraint(string expr) {
     
    149149                                  @")*" +
    150150                                weightRegex
    151                                 ); 
     151                                );
    152152
    153153      if (match.Success) {
     
    161161        if (enumeratorNumDeriv != "" || denominatorNumDeriv != "") {
    162162          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));
    164164          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));
    166166        }
    167167
     
    187187              regions.AddInterval(region.Key, region.Value);
    188188            else
    189               throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
     189              throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable.");
    190190          }
    191191          return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight);
     
    193193          return new ShapeConstraint(variable, numberOfDerivation, interval, weight);
    194194      } else
    195         throw new ArgumentException("The inserted derivation constraint is not valid.", nameof(expr));
     195        throw new ArgumentException($"The inserted derivation constraint {expr} is not valid.", nameof(expr));
    196196    }
    197197
     
    220220      var valid = double.TryParse(input, out var value);
    221221      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() + "\")");
    223223      }
    224224
Note: See TracChangeset for help on using the changeset viewer.