Beispiel #1
0
def test_functions():
    value = random.randint(-100, 100)
    value2 = random.randint(1, 100)
    assert round(c.sin(value)) == round(math.sin(
        value)), "Sin function is not working, you studied this in 10.."
    assert round(c.cos(value)) == round(math.cos(
        value)), "Cos function is not working, you studied this in 10.."
    assert round(c.tan(value)) == round(math.tan(
        value)), "Tan function is not working, you studied this in 10.."
    assert round(c.tanh(value)) == round(math.tanh(
        value)), "Tanh function is not working, you studied this in 10.."
    assert round(c.sigmoid(value)) == round(
        (1 / (1 + math.exp(-value))
         )), "Sigmoid function is not working, this is the basic of DNN.."
    assert round(c.relu(value)) == round(max(
        0, value)), "Relu function is not working, this is the basic of DNN,,"
    assert round(c.log(value2)) == round(math.log(
        value2)), "Log function is not working, you studied this in 10.."
    assert round(c.e(value)) == round(math.exp(
        value)), "Exp function is not working, you studied this in 10.."
    assert [
        0.0003282279149649954, 0.0024252944769113903, 0.01792063694632493,
        0.0008922159768423478, 0.9784336246849563
    ] == c.softmax([1, 3, 5, 2,
                    9]), "Softmax not working bro.. how will you make NN then"
def test_softmax():
    """
    Test the method softmax in the calculator package
    :return: None
    """
    output = calculator.softmax([1, 2, 3])
    assert output == [0.033120396946264216, 0.06624079389252843, 0.09936119083879263]
    output = derivatives.derivative_softmax([1, 2],  [1, 1])
    assert output == [-1, 0]
Beispiel #3
0
def test_all_function_check():
    import calculator
    assert calculator.sin(math.pi / 2) == 1
    assert calculator.cos(math.pi) == -1
    assert calculator.tan(0) == 0
    assert calculator.tanh(0) == 0
    assert calculator.softmax([1,
                               2]) == [0.2689414213699951, 0.7310585786300049]
    assert calculator.e(0) == 1
    assert calculator.log(10, base=10) == 1
    assert calculator.relu(10) == 10
    assert calculator.relu(-10) == 0
    assert calculator.sigmoid(0) == 0.5
Beispiel #4
0
def test():

    abs_tol = 0.001
    rel_tol = 0.001

    test_value = 25

    # =================  testing sin =====================

    assert math.isclose(
        calculator.sin(test_value), -0.132, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {calculator.sin(test_value)}',
                           f'expected : {-0.132}')

    assert math.isclose(
        derivatives.sin(test_value), 0.991, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {derivatives.sin(test_value)}',
                           f'expected : {0.991}')

    # =================  testing cosine =====================

    assert math.isclose(
        calculator.cos(test_value), 0.991, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {calculator.cos(test_value)}',
                           f'expected : {0.991}')

    assert math.isclose(
        derivatives.cos(test_value), 0.132, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {derivatives.cos(test_value)}',
                           f'expected : {0.132}')

    # =================  testing exponential =====================

    assert math.isclose(
        calculator.exp(test_value),
        72004899337,
        rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {calculator.exp(test_value)}',
                           f'expected : {72004899337}')

    assert math.isclose(
        derivatives.exp(test_value),
        72004899337,
        rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {derivatives.exp(test_value)}',
                           f'expected : {72004899337}')

    # =================  testing log =====================
    assert math.isclose(
        calculator.log(test_value), 3.218, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {calculator.log(test_value)}',
                           f'expected : {3.218}')

    assert math.isclose(
        derivatives.log(test_value), 0.04, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {derivatives.log(test_value)}',
                           f'expected : {0.04}')
    # =================  testing relu =====================
    assert math.isclose(
        calculator.relu(test_value), 25, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {calculator.relu(test_value)}',
                           f'expected : {25}')

    assert math.isclose(
        derivatives.relu(test_value), 1, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {derivatives.relu(test_value)}',
                           f'expected : {1}')

    # =================  testing sigmoid =====================

    assert math.isclose(
        calculator.sigmoid(test_value),
        0.999,
        rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {calculator.sigmoid(test_value)}',
                           f'expected : {0.999}')

    assert math.isclose(
        derivatives.sigmoid(test_value),
        1.388794386457827062508E-11,
        rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {derivatives.sigmoid(test_value)}',
                           f'expected : {1.388794386457827062508E-11}')

    # =================  testing Softmax =====================

    assert math.isclose(
        calculator.softmax(test_value), 1, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {calculator.softmax(test_value)}',
                           f'expected : {1}')

    # assert math.isclose(derivatives.softmax(test_value),  0.04 ,
    #                     rel_tol=abs_tol,
    #                     abs_tol=abs_tol),(f'actual : {derivatives.softmax(test_value)}',
    #                     f'expected : {0.04}' )

    # =================  testing tan =====================

    assert math.isclose(
        calculator.tan(test_value), -0.133, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {calculator.tan(test_value)}',
                           f'expected : {-0.133}')

    assert math.isclose(
        derivatives.tan(test_value), 2.017, rel_tol=abs_tol,
        abs_tol=abs_tol), (f'actual : {derivatives.tan(test_value)}',
                           f'expected : {2.017}')
Beispiel #5
0
def test_softmax_import():
    softmax_output = calculator.softmax([1, 5])
    assert np.allclose(softmax_output, np.array(
        [0.01798621,
         0.98201379])), "softmax function in calculor has wrong implementation"
def test_function_dsoftmax():
    assert derivatives.dsoftmax(calculator.softmax([num,num])).all() == np.array([[ 0.25, -0.25], [-0.25,  0.25]]).all(), 'dSoftmax implemenation failed'
def test_function_softmax():
    assert calculator.softmax([num,num]) == [0.5, 0.5], 'Softmax implemenation failed'
Beispiel #8
0
def test_softmax_min_args():
    with pytest.raises(ValueError):
        calc.softmax(1)
Beispiel #9
0
def test_softmax():
    out = (0.09003057317038046, 0.24472847105479767, 0.6652409557748219)
    exp_out = calc.softmax(1, 2, 3)
    for i, j in zip(out, exp_out):
        assert math.isclose(i, j), 'Check your softmax function'
def test_type_error():

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.sin("60")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.cos("-45")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.tan("4.5")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.tanh("50")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.relu("1.3")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.sigmoid("2.4")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.euler("4")

    with pytest.raises(TypeError, match=r".*invalid type*"):
        calculator.softmax([10, "2", "3"])

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.log("5", 10)

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        calculator.log(3, "10")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_sin("45")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_cos("4.5")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_tan("45")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_tanh([1, 3])

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_euler("10")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_sigmoid("3")

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_relu("-5")

    with pytest.raises(TypeError, match=r".*invalid type*"):
        derivatives.d_softmax([20, "3", 5])

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_log("5", 20)

    with pytest.raises(TypeError, match=r".*Input value of invalid type*"):
        derivatives.d_log(5, "20")
Beispiel #11
0
def test_softmax_len():
     assert calculator.softmax(mmatrix_single) == 'ERROR!!, more than one value is required'
Beispiel #12
0
def test_softmax():
    print(calculator.softmax(mmatrix))
Beispiel #13
0
def test_sigmoid():
    assert [0.8807970779778823,
            0.11920292202211755] == list(calculator.softmax([5, 3]))
Beispiel #14
0
def test_softmax():
    assert calculator.softmax(5) == 1.0
Beispiel #15
0
def test_softmax():
    # assert (calc.softmax([4,5,6,7]) == softmax([4,5,6,7])).any()
    assert np.allclose(calc.softmax([4, 5, 6, 7]), softmax([4, 5, 6, 7]))