Changeset 17217
- Timestamp:
- 08/13/19 19:05:35 (5 years ago)
- 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 247 247 break; 248 248 } 249 case OpCodes.Cube: { 250 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 251 result = Interval.Cube(argumentInterval); 252 break; 253 } 249 254 case OpCodes.Root: { 250 255 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); … … 258 263 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 259 264 result = Interval.SquareRoot(argumentInterval); 265 break; 266 } 267 case OpCodes.CubeRoot: { 268 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 269 result = Interval.CubicRoot(argumentInterval); 260 270 break; 261 271 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/AutoDiffIntervalInterpreterTest.cs
r17212 r17217 40 40 } 41 41 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) { 43 43 var parser = new InfixExpressionParser(); 44 44 var tree = parser.Parse(expression); … … 105 105 EvaluateTest("cos(x1+x2)", new Interval(-1, 1)); 106 106 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))); 108 108 109 109 var localVarRanges = new Dictionary<string, Interval>(); … … 182 182 EvaluateTest("sqr(x)", new Interval(Math.Pow(3, 2), Math.Pow(8, 2))); 183 183 } 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 } 184 211 } 185 212 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs
r17209 r17217 134 134 formatter.Format(DerivativeCalculator.Derive(t, "z"))); 135 135 } 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")); 136 149 } 137 150
Note: See TracChangeset
for help on using the changeset viewer.