예제 #1
0
    def test_log_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.log(FADiff.new_scal(0.3))
        assert x.val == pytest.approx(-1.2039728)

        y = 2
        assert Elems.log(y) == pytest.approx(np.log(y) / np.log(np.e))
예제 #2
0
    def test_arctan_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.arctan(FADiff.new_scal(0.5))
        assert x.val == pytest.approx(0.4636476090008061)

        y = -0.4
        assert Elems.arctan(y) == np.arctan(y)
예제 #3
0
    def test_tanh_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.tanh(FADiff.new_scal(1))
        assert x.val == pytest.approx(0.7615941559557649)

        y = 2
        assert Elems.tanh(y) == np.tanh(y)
예제 #4
0
    def test_sinh_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.sinh(FADiff.new_scal(0.4))
        assert x.val == pytest.approx(0.4107523258028155)

        y = -0.4
        assert Elems.sinh(y) == np.sinh(y)
예제 #5
0
 def test_tan_reverse(self):
     FADiff.set_mode('reverse')
     x = Elems.tan(FADiff.new_scal(3))
     assert x.val == pytest.approx(-0.1425465430742778)
     assert x.der == pytest.approx(1.020319516942427)
     y = 2
     assert Elems.tan(y) == np.tan(y)
예제 #6
0
    def test_exp(self):
        x = Elems.exp(FADiff.new_scal(3))
        assert x.val == pytest.approx(20.085536923187668)
        assert x.der == pytest.approx(20.085536923187668)

        y = 10
        assert Elems.exp(y) == np.exp(y)
예제 #7
0
 def test_logistic_reverse(self):
     FADiff.set_mode('reverse')
     x = FADiff()
     x = x.new_scal(2)
     x = Elems.logistic(x)
     assert x.val == pytest.approx(0.8807970779778823)
     y = 4
     assert Elems.logistic(y) == pytest.approx(0.9820137900379085)
예제 #8
0
    def test_cos_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.cos(FADiff.new_scal(3))
        assert x.val == pytest.approx(-0.9899924966004454)
        assert x.der == pytest.approx(-0.1411200080598672)

        y = 2
        assert Elems.cos(y) == np.cos(y)
예제 #9
0
    def test_exp_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.exp(FADiff.new_scal(3))
        assert x.val == pytest.approx(20.085536923187668)
        assert x.der == pytest.approx(20.085536923187668)

        y = 10
        assert Elems.exp(y) == np.exp(y)
예제 #10
0
    def test_cosh_reverse(self):
        FADiff.set_mode('reverse')

        x = Elems.cosh(FADiff.new_scal(0.3))
        assert x.val == pytest.approx(1.04533851)
        assert x.der == pytest.approx(0.30452029)

        y = 4
        assert Elems.cosh(y) == np.cosh(y)
예제 #11
0
    def test_arccos_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.arccos(FADiff.new_scal(0.3))
        assert x.val == pytest.approx(1.2661036727794992)
        with pytest.warns(RuntimeWarning):
            Elems.arccos(19)

        y = -0.4
        assert Elems.arccos(y) == np.arccos(y)
예제 #12
0
    def test_arcsin_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.arcsin(FADiff.new_scal(0.3))
        assert x.val == pytest.approx(0.30469265)
        with pytest.warns(RuntimeWarning):
            Elems.arcsin(-19)

        y = -0.4
        assert Elems.arcsin(y) == np.arcsin(y)
예제 #13
0
    def test_sqrt_reverse(self):
        FADiff.set_mode('reverse')
        x = Elems.sqrt(FADiff.new_scal(3))
        assert x.val == pytest.approx(1.7320508075688772)

        y = 2
        assert Elems.sqrt(y) == np.sqrt(y)

        z = Elems.sqrt(FADiff.new_scal(-1))
        with pytest.raises(AssertionError):
            assert z.val == 1
예제 #14
0
    def test_sin_reverse(self):
        x = FADiff()
        x.set_mode('reverse')
        x = x.new_scal(3)

        a = Elems.sin(x)
        assert a.val == pytest.approx(0.1411200080598672)
        assert a.der == pytest.approx(-0.9899924966004454)

        y = 2
        assert Elems.sin(y) == np.sin(y)
예제 #15
0
      f'{x.der}')              #   derivatives for input vars used in calculation
print(f'y.val --> '                  
      f'{y.val}')              # Should be [5]
print(f'y._der --> '           # '_der' is a dictionary containing the 
      f'{y._der}')             #   partial derivatives for a var
print(f'y.der --> '
      f'{y.der}')              # Should be [1]
print(f'z.val --> '                  
      f'{z.val}')              # Should be [3]
print(f'z._der --> '           # '_der' is a dictionary containing the 
      f'{z._der}')             #   partial derivatives for a var
print(f'z.der --> '
      f'{z.der}')              # Should be [1]

print(f'\ncheck = x * y + ef.sin(x)')
check = x * y + ef.sin(x)
print(f'check.val --> '
      f'{check.val}')                    # Should be [10.909...]
print(f'check.der --> '
      f'{check.der}')                 # Should be [4.583..., 2]
print(f'check._der.get(x) --> '
      f'{check._der.get(x)}')         # Should be 4.583...
print(f'check._der.get(y) --> '  
      f'{check._der.get(y)}')         # Should be 2

print(f'\ncheck = ef.sin(x + y)')
check = ef.sin(x + y)
print(f'check.val --> ' 
      f'{check.val}')                    # Should be [0.656...]
print(f'check.der --> '
      f'{check.der}')