Example #1
0
def test_winnow():
    alpha = [1.01, 1.1, 1.1]
    for n in range(3):
        w1, theta1, _ = algorithms.winnow(np.tile(d_y[n], 20),
                                          np.tile(d_x[n], (20, 1)), alpha[n],
                                          m_val[n])
        correct1 = verify(w1, theta1, dxx[n], dyy[n])
        print("TESTwinnow with m = " + str(m_val[n]) + ", alpha = " +
              str(alpha[n]))
        print(correct1)
Example #2
0
def run_winnow():
    alpha = [1.1, 1.01, 1.005, 1.0005, 1.0001]
    best = [0, 0, 0, 0]
    for c in range(len(alpha)):
        w_500, theta_500, _ = algorithms.winnow(D1_500_y, D1_500_x, alpha[c],
                                                500)
        w_1000, theta_1000, _ = algorithms.winnow(D1_1000_y, D1_1000_x,
                                                  alpha[c], 1000)
        correct_500 = verify(w_500, theta_500, D2_500_x, D2_500_y)
        print("winnow with n = 500, alpha = " + str(alpha[c]))
        print(correct_500)
        correct_1000 = verify(w_1000, theta_1000, D2_1000_x, D2_1000_y)
        print("winnow with n = 1000, alpha = " + str(alpha[c]))
        print(correct_1000)
        if (correct_500 + correct_1000) / 2.0 > (best[0] + best[1]) / 2.0:
            best[0] = correct_500
            best[1] = correct_1000
            best[2] = alpha[c]
    print("bestresult: correct_500 = " + str(best[0]) + " correct_1000 = " +
          str(best[1]) + " alpha = " + str(best[2]))
Example #3
0
def plot_mistake_1000():
    _, __, error1 = algorithms.perceptron(D_1000_y, D_1000_x)
    _, __, error2 = algorithms.perceptron_m(D_1000_y, D_1000_x, 0.005)
    _, __, error3 = algorithms.winnow(D_1000_y, D_1000_x, 1.1, 1000)
    _, __, error4 = algorithms.winnow_m(D_1000_y, D_1000_x, 1.1, 2.0, 1000)
    _, __, error5 = algorithms.adagrad(D_1000_y, D_1000_x, 0.25)
    p1, = plt.plot(error1, color="blue", label="perceptron")
    p2, = plt.plot(error2, color="red", label="perceptron with margin")
    p3, = plt.plot(error3, color="orange", label="winnow")
    p4, = plt.plot(error4, color="green", label="winnow with margin")
    p5, = plt.plot(error5, color="black", label="adagrad")
    plt.legend(handles=[p1, p2, p3, p4, p5], loc=2)
    plt.title("mistake bound n=1000")
    plt.show()
Example #4
0
def run_winnow():
    alpha = [1.1, 1.01, 1.005, 1.0005, 1.0001]
    for n in range(3):
        best = [0, 0, 0, 0]
        for c in range(len(alpha)):
            w1, theta1, _ = algorithms.winnow(d1y[n], d1x[n], alpha[c],
                                              m_val[n])
            correct1 = verify(w1, theta1, d2x[n], d2y[n])
            print("winnow with m = " + str(m_val[n]) + ", alpha = " +
                  str(alpha[c]))
            print(correct1)
            if correct1 > best[0]:
                best[0] = correct1
                best[1] = alpha[c]
        print("bestresult m = " + str(m_val[n]) + ": correct1 = " +
              str(best[0]) + " alpha = " + str(best[1]))