Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/19/19 14:35:08 (6 years ago)
Author:
chaider
Message:

#2791 Refactored Constraint Evaluator and Analyzer

Location:
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs

    r16844 r16851  
    5858      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
    5959      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    60       OnlineCalculatorError errorState = OnlineCalculatorError.None;
    6160
    62       //var constraints = IntervalConstraintsParser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value);
    63       var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints.Where(x => x.Enabled);
    64       var intervalInterpreter = new IntervalInterpreter();
    65       var variableRanges = ((RegressionProblemData) problemData).VariableRangesParameter.Value.VariableIntervals;
    66 
     61      var constraints = problemData.IntervalConstraints.Constraints.Where(x => x.Enabled);
     62      var variableRanges = problemData.VariableRanges.VariableIntervals;
    6763
    6864      var r2 = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, applyLinearScaling, 10);
    69       if (HasConstraintVioluations(constraints, intervalInterpreter, variableRanges, tree)) {
     65      if (SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree)) {
    7066        r2 = 0;
    7167      }
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs

    r16800 r16851  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HEAL.Attic;
    2526using HeuristicLab.Common;
     
    5960      OnlineCalculatorError errorState = OnlineCalculatorError.None;
    6061
    61       //var constraints = IntervalConstraintsParser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value);
    62       var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints;
    63       var intervalInterpreter = new IntervalInterpreter();
    64       var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals;
     62      var constraints = problemData.IntervalConstraints.Constraints.Where(x => x.Enabled);
     63      var variableRanges = problemData.VariableRanges.VariableIntervals;
     64      var tree = solution;
    6565
    6666      double r;
     
    7070        var model = new SymbolicRegressionModel(problemData.TargetVariable, solution, interpreter, lowerEstimationLimit, upperEstimationLimit);
    7171        model.Scale(problemData);
    72         var e = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices);
    73         var scaledTree = model.SymbolicExpressionTree;
     72        tree = model.SymbolicExpressionTree;
    7473        errorState = rCalculator.ErrorState;
    75         if (CheckConstraintsViolations(constraints, intervalInterpreter, variableRanges, scaledTree, out var val)) {
    76           r = val;
    77         } else {
    78           r = rCalculator.R;
    79         }
     74        r = rCalculator.R;
    8075      } else {
    8176        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    82         if (CheckConstraintsViolations(constraints, intervalInterpreter, variableRanges, solution, out var val)) {
    83           r = val;
    84         } else {
    85           r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    86         }
     77        r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    8778      }
     79
     80      if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree)) {
     81        return 0;
     82      }
     83
    8884      if (errorState != OnlineCalculatorError.None) return double.NaN;
    8985      return r * r;
     
    107103      return r2;
    108104    }
    109 
    110     private static bool CheckConstraintsViolations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,
    111       IDictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) {
    112       foreach (var constraint in constraints) {
    113         if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))
    114           throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));
    115         if (!constraint.IsDerivation) {
    116           var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, variableRanges);
    117           if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    118             constraint.InclusiveUpperBound)) {
    119             r = 0;
    120             return true;
    121           }
    122         } else {
    123           var tree = solution;
    124           for (var i = 0; i < constraint.NumberOfDerivation; ++i) {
    125             tree = DerivativeCalculator.Derive(tree, constraint.Variable);
    126           }
    127           var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges);
    128           if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    129             constraint.InclusiveUpperBound)) {
    130             r = 0;
    131             return true;
    132           }
    133         }
    134       }
    135       r = 1;
    136       return false;
    137     }
    138105  }
    139106}
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r16644 r16851  
    2222using HeuristicLab.Common;
    2323using HEAL.Attic;
    24 
    2524namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    2625  [StorableType("7EB90F03-4385-474F-BDE7-3B133E8FEAAB")]
Note: See TracChangeset for help on using the changeset viewer.