Changeset 16758
 Timestamp:
 04/04/19 13:30:57 (10 months ago)
 Location:
 trunk
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r16740 r16758 216 216 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 217 217 result = Interval.Tangens(argumentInterval); 218 break; 219 } 220 case OpCodes.Tanh: { 221 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 222 result = Interval.HyperbolicTangent(argumentInterval); 218 223 break; 219 224 } 
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs
r16757 r16758 171 171 public static Interval Tangens(Interval a) { 172 172 return Interval.Divide(Interval.Sine(a), Interval.Cosine(a)); 173 } 174 public static Interval HyperbolicTangent(Interval a) { 175 return new Interval(Math.Tanh(a.LowerBound), Math.Tanh(a.UpperBound)); 173 176 } 174 177 
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic3.4/IntervalInterpreterTest.cs
r16757 r16758 34 34 } 35 35 36 private void EvaluateTest(string expression, Interval expectedResult, Dictionary<string, Interval> variableRanges = null ) {36 private void EvaluateTest(string expression, Interval expectedResult, Dictionary<string, Interval> variableRanges = null, double lowerDelta =0, double upperDelta = 0) { 37 37 var parser = new InfixExpressionParser(); 38 38 var tree = parser.Parse(expression); … … 44 44 result = interpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges); 45 45 46 Assert.AreEqual(expectedResult, result); 46 Assert.AreEqual(expectedResult.LowerBound, result.LowerBound, lowerDelta); 47 Assert.AreEqual(expectedResult.UpperBound, result.UpperBound, upperDelta); 47 48 } 48 49 … … 120 121 [TestCategory("Problems.DataAnalysis.Symbolic")] 121 122 [TestProperty("Time", "short")] 123 public void TestIntervalInterpreterTan() { 124 // critical values: 125 // lim tan(x) = inf for x => pi/2 126 // lim tan(x) = +inf for x => pi/2 127 var variableRanges = new Dictionary<string, Interval>(); 128 variableRanges.Add("x1", new Interval(1, 1)); 129 variableRanges.Add("x2", new Interval((Math.PI / 2), 0)); 130 variableRanges.Add("x3", new Interval(0, Math.PI / 2)); 131 variableRanges.Add("x4", new Interval(Math.PI, Math.PI)); 132 133 EvaluateTest("tan(x1)", new Interval(Math.Tan(1), Math.Tan(1)), variableRanges, 1E8, 1E8); 134 EvaluateTest("tan(x2)", new Interval(double.NegativeInfinity, 0), variableRanges, 0, 1E8); 135 EvaluateTest("tan(x3)", new Interval(0, 8.16588936419192E+15), variableRanges, 0, 1E6); // actually upper bound should be infinity. 136 EvaluateTest("tan(x4)", new Interval(double.NegativeInfinity, double.PositiveInfinity), variableRanges); 137 } 138 139 [TestMethod] 140 [TestCategory("Problems.DataAnalysis.Symbolic")] 141 [TestProperty("Time", "short")] 142 public void TestIntervalInterpreterTanh() { 143 // critical values: 144 // lim tanh(x) = 1 for x => inf 145 // lim tanh(x) = 1 for x => inf 146 var variableRanges = new Dictionary<string, Interval>(); 147 variableRanges.Add("x1", new Interval(1, 1)); 148 variableRanges.Add("x2", new Interval(double.NegativeInfinity, 0)); 149 variableRanges.Add("x3", new Interval(0, double.PositiveInfinity)); 150 151 EvaluateTest("tanh(x1)", new Interval(Math.Tanh(1), Math.Tanh(1)), variableRanges); 152 EvaluateTest("tanh(x2)", new Interval(1, 0), variableRanges); 153 EvaluateTest("tanh(x3)", new Interval(0, 1), variableRanges); 154 } 155 156 157 [TestMethod] 158 [TestCategory("Problems.DataAnalysis.Symbolic")] 159 [TestProperty("Time", "short")] 122 160 public void TestIntervalInterpreterExp() { 123 161 EvaluateTest("exp(x1x2)", new Interval(Math.Exp(3), Math.Exp(6)));
Note: See TracChangeset
for help on using the changeset viewer.