Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18219 for branches


Ignore:
Timestamp:
02/19/22 01:02:08 (3 years ago)
Author:
dpiringe
Message:

#3138

  • fixed a bug with NaN values for constraint validations
  • added a result collection for all shape constraint violations in SymbolicRegressionSolution
Location:
branches/3138_Shape_Constraints_Transformations/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3138_Shape_Constraints_Transformations/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSESingleObjectiveConstraintsEvaluator.cs

    r18213 r18219  
    210210
    211211    public static IEnumerable<Tuple<ShapeConstraint, double>> CalculateShapeConstraintsViolations(
     212      IShapeConstrainedRegressionProblemData problemData, ISymbolicExpressionTree tree) =>
     213      CalculateShapeConstraintsViolations(problemData, tree,
     214        new SymbolicDataAnalysisExpressionTreeLinearInterpreter(),
     215        new IntervalArithBoundsEstimator(),
     216        new MersenneTwister());
     217
     218    public static IEnumerable<Tuple<ShapeConstraint, double>> CalculateShapeConstraintsViolations(
    212219      IShapeConstrainedRegressionProblemData problemData, ISymbolicExpressionTree tree,
    213220      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IBoundsEstimator estimator,
     
    234241        var enabledConstraints = extendedConstraint.ShapeConstraints.EnabledConstraints;
    235242        if (enabledConstraints.Any()) {
    236           var extendedConstraintExprValues = interpreter.GetSymbolicExpressionTreeValues(extendedConstraint.Tree, tmpDataset, problemData.AllIndices);
     243          var extendedConstraintExprValues = interpreter.GetSymbolicExpressionTreeValues(extendedConstraint.Tree, tmpDataset, problemData.AllIndices)
     244                                                        .Where(x => !double.IsNaN(x));
     245          extendedConstraintExprValues = !extendedConstraintExprValues.Any() ?
     246            new double[] {double.NegativeInfinity, double.PositiveInfinity} :
     247            extendedConstraintExprValues;
    237248          var extendedConstraintExprInterval = new Interval(extendedConstraintExprValues.Min(), extendedConstraintExprValues.Max());
    238249
     
    258269              dict[problemData.TargetVariable] = allEstimatedValues.ToList();
    259270              tmpDataset = new Dataset(dict.Keys, dict.Values);
    260               extendedConstraintExprValues = interpreter.GetSymbolicExpressionTreeValues(extendedConstraint.Tree, tmpDataset, problemData.AllIndices);
     271              extendedConstraintExprValues = interpreter.GetSymbolicExpressionTreeValues(extendedConstraint.Tree, tmpDataset, problemData.AllIndices)
     272                                                        .Where(x => !double.IsNaN(x));
     273              extendedConstraintExprValues = !extendedConstraintExprValues.Any() ?
     274                new double[] { double.NegativeInfinity, double.PositiveInfinity } :
     275                extendedConstraintExprValues;
    261276              extendedConstraintExprInterval = new Interval(extendedConstraintExprValues.Min(), extendedConstraintExprValues.Max());
    262277            }
  • branches/3138_Shape_Constraints_Transformations/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r17911 r18219  
    4747    private const string TestNaNEvaluationsResultName = "Test NaN Evaluations";
    4848
     49    private const string ConstraintViolationsResultsResultName = "Constraint Violations";
     50
    4951    private const string ModelBoundsResultName = "Model Bounds";
    5052
     
    6466      get { return ((IntValue)this[ModelDepthResultName].Value).Value; }
    6567      private set { ((IntValue)this[ModelDepthResultName].Value).Value = value; }
     68    }
     69
     70    private ResultCollection ConstraintViolationsResultCollection {
     71      get => (ResultCollection)this[ConstraintViolationsResultsResultName].Value;
    6672    }
    6773
     
    136142      estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue()));
    137143      Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults));
     144
     145      Add(new Result(ConstraintViolationsResultsResultName, "Constraint Violations", new ResultCollection()));
    138146
    139147      if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree))
     
    168176        }
    169177      }
     178
     179      if(!ContainsKey(ConstraintViolationsResultsResultName)) {
     180        Add(new Result(ConstraintViolationsResultsResultName, "Constraint Violations", new ResultCollection()));
     181        CalculateResults();
     182      }
    170183    }
    171184
     
    192205      if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree))
    193206        ModelBoundsCollection = CalculateModelIntervals(this);
     207
     208      if(ProblemData is IShapeConstrainedRegressionProblemData scpd) {
     209        var violations = NMSESingleObjectiveConstraintsEvaluator.CalculateShapeConstraintsViolations(scpd, Model.SymbolicExpressionTree);
     210        foreach (var violation in violations) {
     211          ConstraintViolationsResultCollection.Add(new Result(violation.Item1.ToString(), new DoubleValue(violation.Item2)));
     212        }
     213      }
    194214    }
    195215
Note: See TracChangeset for help on using the changeset viewer.