'Test domain for logistic.'

def test_logistic(self):

    expr = logistic(self.a)
    self.a.value = 2
    self.assertAlmostEqual(expr.grad[self.a], (np.exp(2) / (1 + np.exp(2))))
    self.a.value = 3
    self.assertAlmostEqual(expr.grad[self.a], (np.exp(3) / (1 + np.exp(3))))
    self.a.value = (-1)
    self.assertAlmostEqual(expr.grad[self.a], (np.exp((-1)) / (1 + np.exp((-1)))))
    expr = logistic(self.x)
    self.x.value = [3, 4]
    val = (np.zeros((2, 2)) + np.diag((np.exp([3, 4]) / (1 + np.exp([3, 4])))))
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), val)
    expr = logistic(self.x)
    self.x.value = [(-1e-09), 4]
    val = (np.zeros((2, 2)) + np.diag((np.exp([(-1e-09), 4]) / (1 + np.exp([(-1e-09), 4])))))
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), val)
    expr = logistic(self.A)
    self.A.value = [[1, 2], [3, 4]]
    val = (np.zeros((4, 4)) + np.diag((np.exp([1, 2, 3, 4]) / (1 + np.exp([1, 2, 3, 4])))))
    self.assertItemsAlmostEqual(expr.grad[self.A].todense(), val)
