示例#1
0
def test_sparse_solution():
    Phi, y, w_gen = generate_fake_data(100, 20, .5)
    model = LinARD(100)
    model.train(Phi, y)

    assert np.sum(abs(model.coef_) > 0) > .4
    assert np.sum(abs(model.coef_) > 0) > .6
示例#2
0
def test_recover_sparseness():
    Phi, y, w_gen = generate_fake_data(10000, 20, .5)
    model = LinARD(200)
    model.train(Phi, y)

    # allow for up to 3 random mistake
    print "This test is based on randomness. It may occasionally fail," \
        " but you should get suspicious if it fails twice in a row."
    assert np.sum((abs(model.coef_) < 1e-7) == (abs(w_gen) > 1e-7)) <= 3
示例#3
0
def test_more_data_better():
    Phi, y, w_gen = generate_fake_data(20000, 20, .5)
    model_small_data = LinARD(100)
    model_big_data = LinARD(100)
    model_small_data.train(Phi[:1000], y[:1000])
    model_big_data.train(Phi[:15000], y[:15000])

    y_small = model_small_data.predict(Phi[15000:])
    y_big = model_big_data.predict(Phi[15000:])

    assert np.sum((y[15000:]-y_small)**2) > np.sum((y[15000:]-y_big)**2)