def test_log_ds(a, s): output = ad.log(a, s) assert output.value == math.log(a.value, s) m = 1 / math.log(s)**2 ma = math.log(s) / a.value assert output.derivatives == pytest.approx({ 'x': m * ma * 3, 'y': m * ma * 4 })
def test_log_sd(s, b): output = ad.log(s, b) assert output.value == math.log(s, b.value) m = 1 / math.log(b.value)**2 mb = -math.log(s) / b.value assert output.derivatives == pytest.approx({ 'x': m * mb * 1.2, 'y': m * mb * 9.5, 'z': m * mb * 5 })
def test_log_ms(m_array, s): output = ad.log(m_array, s) for i in range(len(m_array.value)): assert output.value[i] == math.log(m_array.value[i], s) m = 1 / math.log(s)**2 ma = math.log(s) / m_array.value[i] assert output.derivatives['x'][i] == pytest.approx( m * ma * m_array.derivatives['x'][i]) assert output.derivatives['y'][i] == pytest.approx( m * ma * m_array.derivatives['y'][i])
def test_log_dd(a, b): output = ad.log(a, b) assert output.value == math.log(a.value, b.value) m = 1 / math.log(b.value)**2 ma = math.log(b.value) / a.value mb = -math.log(a.value) / b.value assert output.derivatives == pytest.approx({ 'x': m * ma * 3 + m * mb * 1.2, 'y': m * ma * 4 + m * mb * 9.5, 'z': m * mb * 5 })
def test_log_dm(b, p_array): output = ad.log(b, p_array) for i in range(len(p_array.value)): assert output.value[i] == math.log(b.value, p_array.value[i]) m = 1 / math.log(p_array.value[i])**2 ma = math.log(p_array.value[i]) / b.value mb = -math.log(b.value) / p_array.value[i] assert output.derivatives['x'][i] == pytest.approx( m * ma * b.derivatives['x'] + m * mb * p_array.derivatives['x'][i]) assert output.derivatives['y'][i] == pytest.approx( m * ma * b.derivatives['y'] + m * mb * p_array.derivatives['y'][i])
def test_log_md(m_array, b): output = ad.log(m_array, b) for i in range(len(m_array.value)): assert output.value[i] == math.log(m_array.value[i], b.value) m = 1 / math.log(b.value)**2 ma = math.log(b.value) / m_array.value[i] mb = -math.log(m_array.value[i]) / b.value assert output.derivatives['x'][i] == pytest.approx( m * ma * m_array.derivatives['x'][i] + m * mb * b.derivatives['x']) assert output.derivatives['y'][i] == pytest.approx( m * ma * m_array.derivatives['y'][i] + m * mb * b.derivatives['y'])
def test_log_mm(m_array, p_array): output = ad.log(m_array, p_array) for i in range(len(m_array.value)): assert output.value[i] == math.log(m_array.value[i], p_array.value[i]) m = 1 / math.log(p_array.value[i])**2 ma = math.log(p_array.value[i]) / m_array.value[i] mb = -math.log(m_array.value[i]) / p_array.value[i] assert output.derivatives['x'][i] == pytest.approx( m * ma * m_array.derivatives['x'][i] + m * mb * p_array.derivatives['x'][i]) assert output.derivatives['y'][i] == pytest.approx( m * ma * m_array.derivatives['y'][i] + m * mb * p_array.derivatives['y'][i])
def test_log_change(a, b): a_d = a.derivatives b_d = b.derivatives output = ad.log(a, b) assert a_d == a.derivatives assert b_d == b.derivatives
def test_log_ss(s, s2): output = ad.log(s, s2) assert output.value == math.log(s, s2) assert output.derivatives == {}
def test7(x): output = ad.log(ad.arccos(ad.exp(-3/x)),x**(1/3)) assert output.value == 1.2853017513220446 assert output.derivatives['x'] == -1.47926913780827
def test6(x): output = ad.log(3*x,math.e)/(x**x) assert output.value == 0.44793986730701374 assert output.derivatives['x'] == -0.6334281233912664
def test5(x): output = math.e**(-(x+ad.cos(3*x)**2)**0.5)*ad.sin(x*ad.log(1+x**2,math.e)) assert output.value == -0.013972848911640818 assert output.derivatives['x'] == -0.5684464955717082
def test3(x): output = (c*x + ad.log(b,x))**(x**(1/2)+1/x) assert output.value == 60.621261109269476 assert output.derivatives['x'] == 29.37478740554978