コード例 #1
0
def demoClassification():
    # Teach network XOR function
    #pat = [
    #    [[0,0], [0]],
    #    [[0,1], [1]],
    #    [[1,0], [1]],
    #    [[1,1], [0]]
    #]

    print "loading training.txt"
    pat = dewload.dew_load_train_file("./txt/training.txt")
    print "pat = "
    print pat
    pat2 = dewnormal.dew_normal_big_set_for_ol(pat)

    print "paterrn from Training.txt"
    print pat2

    # create a network with two input, two hidden, and one output nodes

    #load and retrain

    loa = True
    if not loa:
        ggg = []
        ggg = loadweight("./txt/weight_1.txt")
        n = NN(ggg[0][0], ggg[0][1], ggg[0][2], ggg[0][3], regression=False)
        n.wi = ggg[1][0]
        n.wo = ggg[1][1]
        n.wo2 = ggg[1][2]
    else:
        n = NN(67, 10, 11, 8, regression=False)
    # train it with some patterns then test it.
    #print pat2
    n.train(pat2, 1000, 0.1, 0.2)

    #n.test(pat2, verbose = True)
    n.weights()

    saveweight("./txt/weight_1.txt", n)
    #save
    #txtx = []
    #txtx = n.wi , n.wo
    #dewweight.dew_write_weight_file("./txt/weight_1.txt",txtx)

    #predict = [
    #	[[1,0],[1]]
    #    ]
    #   n.test(predict, verbose = True)

    try:
        plot(inputs, outputs, actual)
        #plot(pat, pat, pat)
        print "Press a key to quit."
        value = raw_input()
    except:
        print "Must have matplotlib to plot."
コード例 #2
0
def demotesting():
    # Teach network XOR function
    #pat = [
    #    [[0,0], [0]],
    #    [[0,1], [1]],
    #    [[1,0], [1]],
    #    [[1,1], [0]]
    #]


    pat = dewload.dew_load_train_file("./txt/training.txt")

    print pat
    pat2 = dewnormal.dew_normal_big_set_for_ol(pat)

    print "paterrn from Training.txt"
    print pat2

    # create a network with two input, two hidden, and one output nodes
    n = NN(67, 4, 1, regression = False)

    #load
    n.wi, n.wo = loadweight("./txt/weight_1.txt",n)
    # train it with some patterns then test it.
    #n.train(pat2, 500, 0.1, 0.2)

    #n.test(pat2, verbose = True)
    n.weights()

    print "offline test pat2 after training"
    print n.test(pat2)



    #predict = [
#	[[1,0],[1]]
#    ]
    n.test(pat2, verbose = True)

    try:
        plot(inputs, outputs, actual)
        #plot(pat, pat, pat)
        print "Press a key to quit."
        value = raw_input()
    except:
        print "Must have matplotlib to plot."