def test_steepestdescent_lowiterations():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.steepestdescent(X, y, gradient(),
                                             iterations=2)
    target = [0, 0.4]
    np.testing.assert_array_almost_equal(weights, target, 1)
def test_steepestdescent_alpha():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.steepestdescent(X, y, gradient(),
                                             alpha=0.001)
    target = [0.47, 0.84]
    np.testing.assert_array_almost_equal(weights, target, 1)
def test_gradientdescent_stochastic():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.gradientdescent(X, y, gradient(),
                                             stochastic=True)
    target = [0.47, 0.84]
    np.testing.assert_array_almost_equal(weights, target, 1)
def test_gradientdescent_initialweights():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.gradientdescent(X, y, gradient(),
                                             initial_weights=np.array([0.2, 0.2]))
    target = [0.47, 0.84]
    np.testing.assert_array_almost_equal(weights, target, 1)
def test_newtonsmethod_alpha():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.newtonsmethod(X, y, gradient(),
                                           hessian(), alpha=0.001)
    target = [0.3, 0.5]
    np.testing.assert_array_almost_equal(weights, target, 1)
Esempio n. 6
0
def test_gradientdescent_initialweights():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.gradientdescent(X,
                                             y,
                                             gradient(),
                                             initial_weights=np.array(
                                                 [0.2, 0.2]))
    target = [0.47, 0.84]
    np.testing.assert_array_almost_equal(weights, target, 1)
Esempio n. 7
0
def test_newtonsmethod_lowiterations():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.newtonsmethod(X,
                                           y,
                                           gradient(),
                                           hessian(),
                                           iterations=2)
    target = [0, 0]
    np.testing.assert_array_almost_equal(weights, target, 1)
Esempio n. 8
0
def test_newtonsmethod_alpha():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.newtonsmethod(X,
                                           y,
                                           gradient(),
                                           hessian(),
                                           alpha=0.001)
    target = [0.3, 0.5]
    np.testing.assert_array_almost_equal(weights, target, 1)
Esempio n. 9
0
def test_kerneldensityestimate():
    x, y = data.continuous_data_complicated()
    km = kernelmethods.KernelMethods()
    km.fit(x, y)
    kde = km.kerneldensityestimate([5], 1)
    np.testing.assert_almost_equal(kde, 0)
Esempio n. 10
0
def test_locallinearregression():
    x, y = data.continuous_data_complicated()
    km = kernelmethods.KernelMethods()
    km.fit(x, y)
    predict = km.locallinearregression(5.5, km.gaussiankernel, 0.1)
    np.testing.assert_almost_equal(predict, 5.092, 2)
Esempio n. 11
0
def test_nadarayaaverage():
    x, y = data.continuous_data_complicated()
    km = kernelmethods.KernelMethods()
    km.fit(x, y)
    predict = km.nadarayaaverage(5.5, km.gaussiankernel, 0.01)
    np.testing.assert_almost_equal(predict, 4.237, 2)
Esempio n. 12
0
def test_kernelmethods_fit():
    x, y = data.continuous_data_complicated()
    km = kernelmethods.KernelMethods()
    km.fit(x, y)
    assert km.learned
Esempio n. 13
0
def test_steepestdescent_alpha():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.steepestdescent(X, y, gradient(), alpha=0.001)
    target = [0.47, 0.84]
    np.testing.assert_array_almost_equal(weights, target, 1)
Esempio n. 14
0
def test_gradientdescent_stochastic():
    x, y = data.continuous_data_complicated()
    X = np.column_stack((np.ones(np.shape(x)[0]), x))
    weights = descentmethods.gradientdescent(X, y, gradient(), stochastic=True)
    target = [0.47, 0.84]
    np.testing.assert_array_almost_equal(weights, target, 1)