Пример #1
0
def main(): 
    fn_list = [(np.dot,'dot product')]

    sigmas = list(np.linspace(4, 6,3))

    for sigma in sigmas:
        new_fn = partial(gaussian_rbf, sigma=sigma)
        infotext = "RBF sigma = " + str(sigma)
        fn_list.append((new_fn,infotext))

    polys = [3,5]
    for poly in polys:
        new_fn = partial(poly_kernel, p=poly)
        infotext = "Poly p = " + str(poly)
        fn_list.append((new_fn, infotext))

    gsk = [.5, 1, 5]
    for gauss in gsk:
        kernel = b.gaussk(gauss)
        eta = .1
        r = 15
        bhatta_k = BhattaVectorWrapper(kernel, eta, r).bhatta
        infotext = "bhatta w/ gaussk {}".format(gauss)
        fn_list.append((bhatta_k, infotext))
    for (fn, descriptor) in fn_list:
        print2("Kernel " + descriptor + ": Error rate: " + str(perceptron_kernel(fn)))
Пример #2
0
def main():
    fn_list = [(np.dot, 'dot product')]

    sigmas = list(np.linspace(4, 6, 3))

    for sigma in sigmas:
        new_fn = partial(gaussian_rbf, sigma=sigma)
        infotext = "RBF sigma = " + str(sigma)
        fn_list.append((new_fn, infotext))

    polys = [3, 5]
    for poly in polys:
        new_fn = partial(poly_kernel, p=poly)
        infotext = "Poly p = " + str(poly)
        fn_list.append((new_fn, infotext))

    gsk = [.5, 1, 5]
    for gauss in gsk:
        kernel = b.gaussk(gauss)
        eta = .1
        r = 15
        bhatta_k = BhattaVectorWrapper(kernel, eta, r).bhatta
        infotext = "bhatta w/ gaussk {}".format(gauss)
        fn_list.append((bhatta_k, infotext))
    for (fn, descriptor) in fn_list:
        print2("Kernel " + descriptor + ": Error rate: " +
               str(perceptron_kernel(fn)))
Пример #3
0
    X2 = matrix(X2)
    X1x = X1[:,0]
    X1y = X1[:,1]
    X2x = X2[:,0]
    X2y = X2[:,1]
    #plt.figure()

    #nk_b = nk_bhatta(X1, X2, 0)
    #kvals = "Non-kernelized: " + "{:.2f}\n".format(nk_b).lstrip('0')
    table_vals = []
    for eta in etas:
        sig_vals = []
        for sigma in sigmas:
            if verbose: print "Evaluating {:s} for e={:.2f} s={:.2f}"\
                .format(title_text, eta, sigma)
            kappa = bhatta.eig_bhatta(X1, X2, bhatta.gaussk(sigma), eta, 25)
            sig_vals.append(kappa)
        table_vals.append(sig_vals)

    plt.figure()

    plt.plot(X1x, X1y, 'ro', X2x, X2y, 'bo')
    plt.axis([xmin, xmax, ymin, ymax])

    col_labels = [r'$\sigma = %.2f$' % sig for sig in sigmas]
    row_labels = [r'$\eta = %.2f$'   % eta for eta in etas]

    #kval_x, kval_y = xmin + x_range * .8, ymin + y_range * .7
    gen1_x, gen1_y = xmin + x_range * .02, ymin + y_range * .8
    gen2_x, gen2_y = xmin + x_range * .02, ymin + y_range * .6
Пример #4
0
    X2 = matrix(X2)
    X1x = X1[:, 0]
    X1y = X1[:, 1]
    X2x = X2[:, 0]
    X2y = X2[:, 1]
    #plt.figure()

    #nk_b = nk_bhatta(X1, X2, 0)
    #kvals = "Non-kernelized: " + "{:.2f}\n".format(nk_b).lstrip('0')
    table_vals = []
    for eta in etas:
        sig_vals = []
        for sigma in sigmas:
            if verbose:                print "Evaluating {:s} for e={:.2f} s={:.2f}"\
        .format(title_text, eta, sigma)
            kappa = bhatta.eig_bhatta(X1, X2, bhatta.gaussk(sigma), eta, 25)
            sig_vals.append(kappa)
        table_vals.append(sig_vals)

    plt.figure()

    plt.plot(X1x, X1y, 'ro', X2x, X2y, 'bo')
    plt.axis([xmin, xmax, ymin, ymax])

    col_labels = [r'$\sigma = %.2f$' % sig for sig in sigmas]
    row_labels = [r'$\eta = %.2f$' % eta for eta in etas]

    #kval_x, kval_y = xmin + x_range * .8, ymin + y_range * .7
    gen1_x, gen1_y = xmin + x_range * .02, ymin + y_range * .8
    gen2_x, gen2_y = xmin + x_range * .02, ymin + y_range * .6