def test_tricky_right(self): x, y = ExactInterval(-1, 1), ExactInterval(-3, 2) program = x * y program.lower_grad, program.upper_grad = 0, 1 program.evaluate(10, ad=True) self.assertEqual(x.grad(), (-3, 0)) self.assertEqual(y.grad(), (-1, 0))
def test_right(self): x, y = ExactInterval(1, 2), ExactInterval(3, 4) program = x * y program.lower_grad, program.upper_grad = 0, 1 program.evaluate(10, ad=True) self.assertEqual(x.grad(), (0, 4)) self.assertEqual(y.grad(), (0, 2))
def test_simple(self): x, y = ExactInterval(1, 2), ExactInterval(2, 3) program = x + y program.lower_grad, program.upper_grad = 1, 1 program.evaluate(10, ad=True) self.assertEqual(x.grad(), (1, 1)) self.assertEqual(y.grad(), (1, 1))
def test_left(self): x, y = ExactInterval(1, 2), ExactInterval(3, 4) program = x * y program.lower_grad, program.upper_grad = 1, 0 program.evaluate(10, ad=True) self.assertEqual(x.grad(), (3, 0)) self.assertEqual(y.grad(), (1, 0))
def test_left(self): x, y = ExactInterval(4, 6), ExactInterval(1, 2) program = x / y program.lower_grad, program.upper_grad = 1, 0 program.evaluate(10, ad=True) self.assertEqual(x.grad(), (0.5, 0)) self.assertEqual(y.grad(), (0, -1))