Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16713


Ignore:
Timestamp:
03/26/19 11:37:29 (6 years ago)
Author:
bburlacu
Message:

#2971: Make IntervalConstraintsParser class static, adapt code. Add SymbolicRegressionConstraintSatisfactionEvaluator.

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  
    204204    <Compile Include="Plugin.cs" />
    205205    <Compile Include="SingleObjective\ConstantOptimizationAnalyzer.cs" />
     206    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionConstraintSatisfactionEvaluator.cs" />
    206207    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" />
    207208    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs" />
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs

    r16645 r16713  
    2222using System;
    2323using System.Collections.Generic;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    5959      OnlineCalculatorError errorState = OnlineCalculatorError.None;
    6060
    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);
    6362      var intervalInterpreter = new IntervalInterpreter();
    6463      var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals;
     
    9089    }
    9190
    92     private static bool HasConstraintVioluations(List<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,
     91    private static bool HasConstraintVioluations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,
    9392      Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution) {
    9493      foreach (var constraint in constraints) {
     
    9695          throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));
    9796        if (!constraint.IsDerivation) {
    98           var res = intervalInterpreter.GetSymbolicExressionTreeInterval(solution, variableRanges);
     97          var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, variableRanges);
    9998          if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    10099            constraint.InclusiveUpperBound)) {
     
    106105            tree = DerivativeCalculator.Derive(tree, constraint.Variable);
    107106          }
    108           var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree, variableRanges);
     107          var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges);
    109108          if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    110109            constraint.InclusiveUpperBound)) {
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs

    r16644 r16713  
    2222using System;
    2323using System.Collections.Generic;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    5959      OnlineCalculatorError errorState = OnlineCalculatorError.None;
    6060
    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);
    6362      var intervalInterpreter = new IntervalInterpreter();
    64       var variableRanges = ((RegressionProblemData) problemData).VariableRangesParameter.Value.VariableIntervals;
     63      var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals;
    6564
    6665
     
    9291      // var e = m.GetEstimatedValues (TRAINING)
    9392      // OnlinePearsonCalc.Calculate(e, TARGET_TRAIING)
    94      
     93
    9594      // scaledTree = model.Tree;
    9695
     
    120119      }
    121120      if (errorState != OnlineCalculatorError.None) return double.NaN;
    122       return r*r;
     121      return r * r;
    123122    }
    124123
     
    141140    }
    142141
    143     private static bool CheckConstraintsViolations(List<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,
     142    private static bool CheckConstraintsViolations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,
    144143      Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) {
    145144      foreach (var constraint in constraints) {
     
    147146          throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));
    148147        if (!constraint.IsDerivation) {
    149           var res = intervalInterpreter.GetSymbolicExressionTreeInterval(solution, variableRanges);
     148          var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, variableRanges);
    150149          if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    151150            constraint.InclusiveUpperBound)) {
     
    158157            tree = DerivativeCalculator.Derive(tree, constraint.Variable);
    159158          }
    160           var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree, variableRanges);
     159          var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges);
    161160          if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    162161            constraint.InclusiveUpperBound)) {
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionConstraintAnalyzer.cs

    r16644 r16713  
    2424using System;
    2525using System.Collections.Generic;
     26using HEAL.Attic;
    2627using HeuristicLab.Analysis;
    2728using HeuristicLab.Common;
     
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    32 using HEAL.Attic;
    3333
    3434namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    8686    public override IOperation Apply() {
    8787      var results = ResultCollectionParameter.ActualValue;
    88       IntervalConstraintsParser parser = new IntervalConstraintsParser();
    8988      var intervalInterpreter = new IntervalInterpreter();
    9089      if (!results.ContainsKey(ConstraintViolationsResultName)) {
     
    9998      var constraintViolations = new Dictionary<string, int>();
    10099
    101       var constraints =
    102         parser.Parse(problemData.IntervalConstraints.Value);
     100      var constraints = IntervalConstraintsParser.Parse(problemData.IntervalConstraints.Value);
    103101      var variableRanges = problemData.VariableRanges.VariableIntervals;
    104102
     
    122120              nameof(IntervalConstraintsParser));
    123121          if (!constraint.IsDerivation) {
    124             var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree,
     122            var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree,
    125123              variableRanges);
    126124            if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
     
    134132            }
    135133
    136             var res = intervalInterpreter.GetSymbolicExressionTreeInterval(dTree,
     134            var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(dTree,
    137135              variableRanges);
    138136            if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r16644 r16713  
    2121
    2222using System.Linq;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    2627using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2728using HeuristicLab.Optimization;
    28 using HEAL.Attic;
    2929using HeuristicLab.Problems.DataAnalysis.Implementation;
    3030
     
    168168      if (variableRanges != null) {
    169169        intervalEvaluation.Add($"Target {ProblemData.TargetVariable}", new Interval(variableRanges[ProblemData.TargetVariable].LowerBound, variableRanges[ProblemData.TargetVariable].UpperBound));
    170         intervalEvaluation.Add("Modell Interval", interpreter.GetSymbolicExressionTreeInterval(Model.SymbolicExpressionTree, variableRanges));
     170        intervalEvaluation.Add("Modell Interval", interpreter.GetSymbolicExpressionTreeInterval(Model.SymbolicExpressionTree, variableRanges));
    171171
    172172        foreach (var derivate in variableRanges) {
    173173          if (derivate.Key != ProblemData.TargetVariable) {
    174174            var derived = DerivativeCalculator.Derive(Model.SymbolicExpressionTree, derivate.Key);
    175             var derivedResultInterval = interpreter.GetSymbolicExressionTreeInterval(derived, variableRanges);
     175            var derivedResultInterval = interpreter.GetSymbolicExpressionTreeInterval(derived, variableRanges);
    176176            intervalEvaluation.Add(" ?f/?" + derivate.Key,
    177177              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  
    105105    <Reference Include="EPPlus-4.0.3, Version=4.0.3.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
    106106      <Private>False</Private>
     107      <HintPath>..\..\..\..\trunk\bin\EPPlus-4.0.3.dll</HintPath>
    107108    </Reference>
    108109    <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  
    55
    66namespace 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) {
    119      var options = RegexOptions.Multiline | RegexOptions.IgnoreCase;
    1210      var matches = Regex.Matches(input, @"^(.*)\bin\b\s*([\[\]])(.*[^\s])(\s*\.\.\s*)([^\s].*)([\[\]])\r?\s*$", options);
    1311
    1412      for (var i = 0; i < matches.Count; ++i) {
    15         if (matches[i].Groups.Count == 7) { 
     13        if (matches[i].Groups.Count == 7) {
    1614          var intervalConstraint = new IntervalConstraint();
    1715          //pattern 1 = defintion
     
    3836          intervalConstraint.InclusiveLowerBound = (matches[i].Groups[2].Value == "[");
    3937          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)),
    4139            ParseIntervalBounds(matches[i].Groups[5].Value.Replace(" ", string.Empty)));
    4240
    43           intervalConstraints.Add(intervalConstraint);
     41          yield return intervalConstraint;
    4442        } else {
    4543          throw new ArgumentException($"The given constraint: {matches[i].Value} is not valid.");
    4644        }
    4745      }
    48 
    49       return intervalConstraints;
    5046    }
    5147
     
    5955          return double.NegativeInfinity;
    6056        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            }
    6562          }
    66         }
    6763      }
    6864    }
Note: See TracChangeset for help on using the changeset viewer.