예제 #1
0
def test_Log():
    Test_Dual_Number_1 = DualNumber(1)
    assert EF.Log(Test_Dual_Number_1).val == 0 and EF.Log(Test_Dual_Number_1).der == 1
    Test_Dual_Number_1 = 1
    assert EF.Log(Test_Dual_Number_1).val == 0 and EF.Log(Test_Dual_Number_1).der == 0
    
    Test_Dual_Number_1 = DualNumber(2)
    assert EF.Log(Test_Dual_Number_1,base=10).val == np.log(2) / np.log(10)  and EF.Log(Test_Dual_Number_1,base=10).der == 1/(np.log(10)*2)
    Test_Dual_Number_1 = 2
    assert EF.Log(Test_Dual_Number_1,base=10).val == np.log(2) / np.log(10) and EF.Log(Test_Dual_Number_1,base=10).der == 0
예제 #2
0
 def Demo_gradient(x):
     x=DualNumber(x);
     y=-EF.Sin(x)*EF.Cos(x)*EF.Tan(x)+EF.Exp(x)*EF.Log(x)*EF.Sqrt(x)*2
     return y.der #y=sin(x)cos(x)tan(x)-2exp(x)log(x)sqrt(x)
예제 #3
0
def Given_function(x):
    x = DualNumber(x)
    y = EF.Sin(x) * EF.Cos(x) * EF.Tan(x) - EF.Exp(x) * EF.Log(x) * EF.Sqrt(
        x) * 2
    return y  #y=sin(x)cos(x)tan(x)-2exp(x)log(x)sqrt(x)
예제 #4
0
def rm_test_Log():
    Test_Dual_Number_1 = DualNumber(1,Reverse=True)
    assert EF.Log(Test_Dual_Number_1).val == 0 and EF.Log(Test_Dual_Number_1).der == 0
    
    Test_Dual_Number_1 = DualNumber(2,Reverse=True)
    assert EF.Log(Test_Dual_Number_1,base=10).val == np.log(2) / np.log(10)  and EF.Log(Test_Dual_Number_1,base=10).der == 0