Changeset 18163


Ignore:
Timestamp:
12/21/21 08:51:49 (7 months ago)
Author:
gkronber
Message:

#2994: push of old local changes

Location:
branches/2994-AutoDiffForIntervals
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/ConstrainedNLSInternal.cs

    r17328 r18163  
    4343
    4444    public NLOpt.nlopt_result OptResult { get; private set; }
     45
     46    public int NumObjectiveFunctionEvaluations { get; private set; }
     47    public int NumObjectiveGradientEvaluations { get; private set; }
     48    public int NumConstraintEvaluations { get; private set; }
     49    public int NumConstraintGradientEvaluations { get; private set; }
    4550
    4651    private bool disposed = false;
     
    249254      double minf = double.MaxValue; /* minimum objective value upon return */
    250255      OptResult = NLOpt.nlopt_optimize(nlopt, x, ref minf);
    251 
     256       
    252257      if (OptResult < 0 && OptResult != NLOpt.nlopt_result.NLOPT_FORCED_STOP) {
    253258        // throw new InvalidOperationException($"NLOpt failed {res} {NLOpt.nlopt_get_errmsg(nlopt)}");
     
    294299      UpdateThetaValues(curX);
    295300      var sse = 0.0;
     301      NumObjectiveFunctionEvaluations++;
    296302
    297303      if (grad != null) {
     304        NumObjectiveGradientEvaluations++;
    298305        autoDiffEval.Evaluate(preparedTree, problemData.Dataset, trainingRows,
    299306          preparedTreeParameterNodes, fi_eval, jac_eval);
     
    414421    double CalculateConstraint(uint dim, double[] curX, double[] grad, IntPtr data) {
    415422      UpdateThetaValues(curX);
     423      NumConstraintEvaluations++;
    416424      var intervalEvaluator = new IntervalEvaluator();
    417425      var refIntervalEvaluator = new IntervalInterpreter();
     
    420428
    421429      if (grad != null) Array.Clear(grad, 0, grad.Length);
     430      if (grad != null) NumConstraintGradientEvaluations++;
    422431
    423432      var interval = intervalEvaluator.Evaluate(constraintData.Tree, dataIntervals, constraintData.ParameterNodes,
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/NLOptEvaluator.cs

    r17328 r18163  
    210210           constantOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, Solver,
    211211           out double qDiff, out double[] constraintsBefore, out double[] constraintsAfter,
    212            ConstantOptimizationIterations.Value, updateVariableWeights: UpdateVariableWeights, lowerEstimationLimit: EstimationLimitsParameter.ActualValue.Lower, upperEstimationLimit: EstimationLimitsParameter.ActualValue.Upper, updateConstantsInTree: UpdateConstantsInTree, counter: counter);
     212           ConstantOptimizationIterations.Value, updateVariableWeights: UpdateVariableWeights,
     213           lowerEstimationLimit: EstimationLimitsParameter.ActualValue.Lower, upperEstimationLimit: EstimationLimitsParameter.ActualValue.Upper,
     214           updateConstantsInTree: UpdateConstantsInTree, counter: counter);
    213215
    214216        AchievedQualityImprovementParameter.ActualValue = new DoubleValue(qDiff);
     
    272274      if (!updateConstantsInTree) throw new NotSupportedException("not updating tree parameters is not supported");
    273275      if (!applyLinearScaling) throw new NotSupportedException("application without linear scaling is not supported");
    274 
    275276
    276277      using (var state = new ConstrainedNLSInternal(solver, tree, maxIterations, problemData, 0, 0, 0)) {
     
    282283        if (constraintsAfter.Any(cv => cv > 1e-8)) qOpt = qBefore;
    283284        qDiff = qOpt - qBefore;
     285
     286        if(counter != null) {
     287          counter.FunctionEvaluations += state.NumObjectiveFunctionEvaluations;
     288          counter.GradientEvaluations += state.NumObjectiveGradientEvaluations;
     289        }
     290
    284291        return qOpt;
    285292      }
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/IntervalEvaluatorTest.cs

    r17319 r18163  
    188188    [TestCategory("Problems.DataAnalysis")]
    189189    [TestProperty("Time", "short")]
    190     public void IntervalEvaluatorSqrAndDiff() {
     190    public void IntervalEvaluatorSqrAndDiv() {
    191191      Dictionary<string, Interval> dataIntervals = new Dictionary<string, Interval>() {
    192192        {"R", new Interval(0.2, 0.5) },
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/IntervalInterpreterTest.cs

    r17318 r18163  
    154154    }
    155155
     156    [TestMethod]
     157    [TestCategory("Problems.DataAnalysis.Symbolic")]
     158    [TestProperty("Time", "short")]
     159    public void IntervalInterpreterAQ() {
     160      var variableRanges = new Dictionary<string, Interval>();
     161      variableRanges.Add("c1", new Interval(1, 1));
     162      variableRanges.Add("c2", new Interval(2, 2));
     163
     164      EvaluateTest("aq(c1, c2)", new Interval(1.0 / Math.Sqrt(5), 1.0 / Math.Sqrt(5)), variableRanges); // aq(a, b) = a / sqrt(1+b²)
     165    }
     166
    156167
    157168    [TestMethod]
Note: See TracChangeset for help on using the changeset viewer.