Exemple #1
0
 def test_log_sparse_jac(self):
     val = np.array([1, 2, 3])
     J = sps.csc_matrix(np.array([[3, 2, 1], [5, 6, 1], [2, 3, 5]]))
     a = Ad_array(val, J)
     b = af.log(a)
     jac = np.dot(np.diag(1 / val), J.A)
     self.assertTrue(np.all(b.val == np.log(val)) and np.all(b.jac == jac))
Exemple #2
0
    def test_log_vector(self):
        val = np.array([1, 2, 3])
        J = sps.csc_matrix(np.array([[3, 2, 1], [5, 6, 1], [2, 3, 5]]))
        a = Ad_array(val, J)
        b = af.log(a)
        jac = sps.diags(1 / val) * J

        self.assertTrue(
            np.all(b.val == np.log(val)) and np.all(b.jac.A == jac))
Exemple #3
0
    def test_log_scalar_times_ad_var(self):
        val = np.array([1, 2, 3])
        J = sps.diags(np.array([1, 1, 1]))
        a = Ad_array(val, J)
        c = 2
        b = af.log(c * a)
        jac = sps.diags(1 / val) * J

        self.assertTrue(
            np.allclose(b.val, np.log(c * val))
            and np.allclose(b.jac.A, jac.A))
        self.assertTrue(np.all(a.val == [1, 2, 3]) and np.all(a.jac.A == J.A))
Exemple #4
0
 def test_log_advar(self):
     a = Ad_array(2, 3)
     b = af.log(a)
     self.assertTrue(b.val == np.log(2) and b.jac == 1 / 2 * 3)
     self.assertTrue(a.val == 2 and a.jac == 3)
Exemple #5
0
 def test_log_scalar(self):
     a = Ad_array(2, 0)
     b = af.log(a)
     self.assertTrue(b.val == np.log(2) and b.jac == 0)
     self.assertTrue(a.val == 2 and a.jac == 0)