Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17217


Ignore:
Timestamp:
08/13/19 19:05:35 (5 years ago)
Author:
gkronber
Message:

#2994: more test cases to understand specific problems when optimizing with constraints

Location:
branches/2994-AutoDiffForIntervals
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r17209 r17217  
    247247            break;
    248248          }
     249        case OpCodes.Cube: {
     250            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     251            result = Interval.Cube(argumentInterval);
     252            break;
     253          }
    249254        case OpCodes.Root: {
    250255            result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     
    258263            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    259264            result = Interval.SquareRoot(argumentInterval);
     265            break;
     266          }
     267        case OpCodes.CubeRoot: {
     268            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     269            result = Interval.CubicRoot(argumentInterval);
    260270            break;
    261271          }
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/AutoDiffIntervalInterpreterTest.cs

    r17212 r17217  
    4040    }
    4141
    42     private void EvaluateTest(string expression, Interval expectedResult, IDictionary<string, Interval> variableRanges = null, double lowerDelta = 0, double upperDelta = 0) {
     42    private void EvaluateTest(string expression, Interval expectedResult, IDictionary<string, Interval> variableRanges = null, double lowerDelta = 1e-6, double upperDelta = 1e-6) {
    4343      var parser = new InfixExpressionParser();
    4444      var tree = parser.Parse(expression);
     
    105105      EvaluateTest("cos(x1+x2)", new Interval(-1, 1));
    106106      EvaluateTest("cos(x1+x2)", new Interval(-1, 1), variableRanges);
    107       EvaluateTest("cos(1+2)", new Interval(Math.Sin(3 + Math.PI / 2), Math.Sin(3 + Math.PI / 2)));
     107      EvaluateTest("cos(1+2)", new Interval(Math.Cos(3), Math.Cos(3)));
    108108
    109109      var localVarRanges = new Dictionary<string, Interval>();
     
    182182      EvaluateTest("sqr(x)", new Interval(Math.Pow(3, 2), Math.Pow(8, 2)));
    183183    }
     184
     185
     186
     187    [TestMethod]
     188    [TestCategory("Problems.DataAnalysis")]
     189    [TestProperty("Time", "short")]
     190    public void TestDivisionAndSqr() {
     191      Dictionary<string, Interval> dataIntervals = new Dictionary<string, Interval>() {
     192        {"R", new Interval(0.2, 0.5) },
     193        {"r", new Interval(0.5, 0.8) },
     194      };
     195
     196      EvaluateTest("R*R", new Interval(0.2 * 0.2, 0.5 * 0.5), dataIntervals);
     197      EvaluateTest("sqr(R)", new Interval(0.2 * 0.2, 0.5 * 0.5), dataIntervals);
     198
     199      EvaluateTest("r*r", new Interval(0.5 * 0.5, 0.8 * 0.8), dataIntervals);
     200      EvaluateTest("sqr(r)", new Interval(0.5 * 0.5, 0.8 * 0.8), dataIntervals);
     201
     202      EvaluateTest("R/r", new Interval(0.2 / 0.8, 0.5 / 0.5), dataIntervals);
     203
     204      EvaluateTest("R/(r*r)", new Interval(0.2 / (0.8 * 0.8), 0.5 / (0.5 * 0.5)), dataIntervals);
     205      EvaluateTest("R/sqr(r)", new Interval(0.2 / (0.8 * 0.8), 0.5 / (0.5 * 0.5)), dataIntervals);
     206
     207      EvaluateTest("R*R/sqr(r)", new Interval(0.2 * 0.2 / (0.8 * 0.8), 0.5 * 0.5 / (0.5 * 0.5)), dataIntervals);
     208      EvaluateTest("sqr(R)/sqr(r)", new Interval(0.2 * 0.2 / (0.8 * 0.8), 0.5 * 0.5 / (0.5 * 0.5)), dataIntervals);
     209      EvaluateTest("sqr(R/r)", new Interval(0.2 * 0.2 / (0.8 * 0.8), 0.5 * 0.5 / (0.5 * 0.5)), dataIntervals);
     210    }
    184211  }
    185212}
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs

    r17209 r17217  
    134134          formatter.Format(DerivativeCalculator.Derive(t, "z")));
    135135      }
     136
     137      // more cases from applications
     138      Assert.AreEqual("(2*'R')", Derive("R*R", "R"));
     139      Assert.AreEqual("(2*'r')", Derive("sqr(r)", "r"));
     140
     141      Assert.AreEqual("('R' / (SQR('r') * (-1)))", Derive("R/r", "r"));
     142      Assert.AreEqual("(('r' * 'R' * (-2)) / (SQR('r') * SQR('r')))", Derive("R/(r*r)", "r"));
     143      Assert.AreEqual("(('r' * 'R' * (-2)) / SQR(SQR('r')))", Derive("R/sqr(r)", "r"));
     144
     145      Assert.AreEqual("(('r' * ('R' * 'R') * (-2)) / SQR(SQR('r')))", Derive("R*R/sqr(r)", "r"));
     146      Assert.AreEqual("(('r' * SQR('R') * (-2)) / SQR(SQR('r')))", Derive("sqr(R)/sqr(r)", "r"));
     147      Assert.AreEqual("((('R' * 'R') * 2) / ('r' * SQR('r') * (-1)))", Derive("sqr(R/r)", "r"));
     148      Assert.AreEqual("((('R' * 'R') / ('r' * SQR('r') * (-1))) + (('R' * 'R') / ('r' * SQR('r') * (-1))))", Derive("(R/r)*(R/r)", "r"));
    136149    }
    137150
Note: See TracChangeset for help on using the changeset viewer.