Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16738


Ignore:
Timestamp:
04/01/19 19:19:14 (6 years ago)
Author:
gkronber
Message:

#2994: another unit test, smaller fixes and checks for invalid parameters

Location:
branches/2994-AutoDiffForIntervals
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Algorithms.DataAnalysis.ConstrainedNonlinearRegression/3.4/ConstrainedNonlinearRegression.cs

    r16727 r16738  
    207207    /// <returns></returns>
    208208    public static ISymbolicRegressionSolution CreateRegressionSolution(RegressionProblemData problemData, string modelStructure, int maxIterations, bool applyLinearScaling, IRandom rand = null) {
     209      if (applyLinearScaling) throw new NotSupportedException("Linear scaling is not yet supported in NLR with constraints.");
    209210      var parser = new InfixExpressionParser();
    210211      var tree = parser.Parse(modelStructure);
     
    262263      foreach (var constraint in constraints) {
    263264        if (constraint.IsDerivation) {
     265          if (!problemData.AllowedInputVariables.Contains(constraint.Variable))
     266            throw new ArgumentException($"Invalid constraint: the variable {constraint.Variable} does not exist in the dataset.");
    264267          var df = DerivativeCalculator.Derive(treeForDerivation, constraint.Variable);
    265268
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/Interpreter.cs

    r16727 r16738  
    389389      for (int i = 0; i < paramNodes.Length; ++i) {
    390390        if (paramNodes[i] == null) continue;
    391         lowerGradient[i] = l.Gradient.Elements[paramNodes[i]];
    392         upperGradient[i] = u.Gradient.Elements[paramNodes[i]];
     391        if (l.Gradient.Elements.TryGetValue(paramNodes[i], out AlgebraicDouble value)) lowerGradient[i] = value;
     392        if (u.Gradient.Elements.TryGetValue(paramNodes[i], out value)) upperGradient[i] = value;
    393393      }
    394394      return new Interval(code[0].value.LowerBound.Value.Value, code[0].value.UpperBound.Value.Value);
     
    827827      return this;
    828828    }
     829
     830//     Exponentiation by a natural power[a, b] k:
     831//
     832// if 0∈[a, b], then
     833//   [a, b]^0  =  [0, 1]
     834//   [a, b]^2n   =  [0, max(a2n, b2n)]
     835//   [a, b]^2n+1   =  [a2n+1, b2n+1]
     836// if [a, b]>0, then
     837//   [a, b]^0  =  [1, 1]
     838//   [a, b]^k>0  =  [ak, bk]
     839// if [a, b]<0, then
     840//   [a, b]^0  =  [1, 1]
     841//   [a, b]^2n   =  [b2n, a2n]
     842//   [a, b]^2n+1   =  [a2n+1, b2n+1]
    829843
    830844    public AlgebraicInterval AssignIntPower(AlgebraicInterval a, int p) {
  • branches/2994-AutoDiffForIntervals/Tests/AutoDiffTest.cs

    r16727 r16738  
    189189      }
    190190
     191      {
     192
     193        // derivatives and intervals for flow psi problem
     194        var intervals = new Dictionary<string, Interval>();
     195        intervals.Add("x1", new Interval(60.0, 65.0));
     196        intervals.Add("x2", new Interval(30.0, 40.0));
     197        intervals.Add("x3", new Interval(5.0, 10.0));
     198        intervals.Add("x4", new Interval(0.5, 0.8));
     199        intervals.Add("x5", new Interval(0.2, 0.5));
     200
     201        var parser = new InfixExpressionParser();
     202        var formatter = new InfixExpressionFormatter();
     203
     204        var expr = parser.Parse("x1*x2*x5*(1 - sqr(x4/x5)) + x3 * log(x5/x4)");
     205
     206        var dfdx1 = DerivativeCalculator.Derive(expr, "x1");
     207        Assert.AreEqual("('x2' * 'x5' * ((SQR(('x4' / 'x5')) * (-1)) + 1))", formatter.Format(dfdx1));
     208        // x2 x5 (1 - sqr(x4/x5))
     209
     210        var dfdx2 = DerivativeCalculator.Derive(expr, "x2");
     211        Assert.AreEqual("('x1' * 'x5' * ((SQR(('x4' / 'x5')) * (-1)) + 1))", formatter.Format(dfdx2));
     212        // x1 x5 (1 - sqr(x4/x5))
     213
     214        var dfdx3 = DerivativeCalculator.Derive(expr, "x3");
     215        Assert.AreEqual("LOG(('x5' / 'x4'))", formatter.Format(dfdx3));
     216        // log(x5/x4)
     217
     218        var dfdx4 = DerivativeCalculator.Derive(expr, "x4");
     219        Assert.AreEqual("((('x1' * 'x2' * 'x5' * 'x4' * 2) / ('x5' * (-1*'x5'))) + (('x4' * 'x5' * 'x3') / ('x5' * SQR('x4') * (-1))))", formatter.Format(dfdx4));
     220        // -2*x1*x2*x5*x4/x5*1/x5 + x3*1/(x5/x4)*x5/sqr(x4)
     221
     222        var dfdx5 = DerivativeCalculator.Derive(expr, "x5");
     223        Assert.AreEqual("((('x4' * 'x3') / ('x5' * 'x4')) + ('x1' * 'x2' * ((SQR(('x4' / 'x5')) * (-1)) + 1)) + (('x1' * 'x2' * 'x5' * ('x4' * 'x4') * 2) / ('x5' * SQR('x5') * 1)))", formatter.Format(dfdx5));
     224      }
     225
     226
    191227    }
    192228  }
Note: See TracChangeset for help on using the changeset viewer.