Exemple #1
0
def parity(B=12, learning_rate=10e-5, epochs=200):
    X, Y = all_parity_pairs(B)
    N, t = X.shape

    # we want every time step to have a label
    Y_t = np.zeros(X.shape, dtype=np.int32)
    for n in xrange(N):
        ones_count = 0
        for i in xrange(t):
            if X[n, i] == 1:
                ones_count += 1
            if ones_count % 2 == 1:
                Y_t[n, i] = 1

    # for x, y in zip(X, Y_t):
    #     print "x:", x, "y:", y
    X = X.reshape(N, t, 1).astype(np.float32)

    rnn = SimpleRNN(4)
    rnn.fit(X,
            Y_t,
            learning_rate=learning_rate,
            epochs=epochs,
            activation=T.nnet.sigmoid,
            show_fig=True)
def deep16():
    X, Y = all_parity_pairs(12)
    model = ANN([128] * 16)
    model.fit(X,
              Y,
              learning_rate=10e-3,
              print_period=10,
              epochs=35,
              show_fig=True)
Exemple #3
0
def wide():  # one inner layer model
    X, Y = all_parity_pairs(12)
    model = ANN([2048])
    model.fit(X,
              Y,
              learning_rate=1e-4,
              print_period=10,
              epochs=300,
              show_fig=True)
def deep32():
    X, Y = all_parity_pairs(12)
    model = ANN([64] * 32)
    model.fit(X,
              Y,
              learning_rate=10e-3,
              print_period=10,
              epochs=25,
              show_fig=True)
def deep64():
    X, Y = all_parity_pairs(12)
    model = ANN([32] * 64)
    model.fit(X,
              Y,
              learning_rate=10e-3,
              print_period=10,
              epochs=20,
              show_fig=True)
Exemple #6
0
def deep():
    X, Y = all_parity_pairs(12)
    model = ANN([1024] * 2)
    model.fit(X,
              Y,
              learning_rate=10e-4,
              print_period=10,
              epochs=1000,
              show_fig=True)
Exemple #7
0
def wide():
    X, Y = all_parity_pairs(12)
    model = ANN([2048])
    model.fit(X,
              Y,
              learning_rate=10e-5,
              print_period=10,
              epochs=300,
              show_fig=True)
def deep():
    X, Y = all_parity_pairs(12)
    ann = AnnTheano([1024] * 2)
    ann.fit(X,
            Y,
            learning_rate=10e-4,
            print_period=10,
            epochs=70,
            show_fig=True)
def wide():
    X, Y = all_parity_pairs(12)
    ann = AnnTheano([2048])
    ann.fit(X,
            Y,
            learning_rate=10e-5,
            print_period=10,
            epochs=300,
            show_fig=True)
def deep8():
    X, Y = all_parity_pairs(12)
    model = ANN([256] * 8)
    model.fit(X,
              Y,
              learning_rate=10e-2,
              print_period=10,
              epochs=35,
              show_fig=True)
def deep4():
    X, Y = all_parity_pairs(12)
    model = ANN([512] * 4)
    model.fit(X,
              Y,
              learning_rate=10e-2,
              print_period=10,
              epochs=50,
              show_fig=True)
Exemple #12
0
def deep():
    # Challenge - find a deeper, slimmer network to solve the problem
    X, Y = all_parity_pairs(12)
    model = ANN([1024] * 2)
    model.fit(X,
              Y,
              learning_rate=10e-4,
              print_period=10,
              epochs=100,
              show_fig=True)
Exemple #13
0
def main():
	X, Y = all_parity_pairs(12)
	X = X.astype(np.float32)
	Y = Y.astype(np.int32)
	K = len(set(Y))
	Y = (indicator(Y)).astype(np.float32)
	N, D = X.shape
	model = ANN(D, K, [1024, 1024])
	init = tf.global_variables_initializer()
	with tf.Session() as session:
		session.run(init)
		model.set_session(session)
		model.fit(X, Y)
def parity(B=12, learning_rate=10e-5, epochs=200):
    X, Y = all_parity_pairs(B)
    N, t = X.shape

    Y_t = np.zeros(X.shape, dtype=np.int32)
    for n in xrange(N):
        ones_count = 0
        for i in xrange(t):
            if X[n,i] == 1:
                ones_count += 1
            if ones_count % 2 == 1:
                Y_t[n,i] = 1

    X = X.reshape(N, t, 1).astype(np.float32)

    rnn = SimpleRNN(4)
    rnn.fit(X, Y_t, learning_rate=learning_rate, epochs=epochs, activation=T.nnet.sigmoid, show_fig=True)
def parity(B=12, learning_rate=10e-5, epochs=200):
	X, Y = all_parity_pairs(B)
	N, t = X.shape

	Y_t = np.zeros(X.shape, dtype=np.int32)
	for n in range(N):
		ones_count = 0
		for i in range(t):
			if X[n,i] == 1:
				ones_count += 1
			if ones_count % 2 == 1:
				Y_t[n,i] = 1

	X = X.reshape(N, T, 1).astype(np.float32)

	rnn = SimpleRNN(4)
	rnn.fit(X, Y_t, learning_rate=learning_rate, epochs=epochs, activation=T.nnet.sigmoid, show_fig=True)
def parity(B=12, learning_rate=10e-5, epochs=200):
    X, Y = all_parity_pairs(B)
    N, t = X.shape

    # we want every time step to have a label
    Y_t = np.zeros(X.shape, dtype=np.int32)
    for n in xrange(N):
        ones_count = 0
        for i in xrange(t):
            if X[n,i] == 1:
                ones_count += 1
            if ones_count % 2 == 1:
                Y_t[n,i] = 1

    # for x, y in zip(X, Y_t):
    #     print "x:", x, "y:", y
    X = X.reshape(N, t, 1).astype(np.float32)

    rnn = SimpleRNN(4)
    rnn.fit(X, Y_t, learning_rate=learning_rate, epochs=epochs, activation=T.nnet.sigmoid, show_fig=True)
Exemple #17
0
def parity(B=4, learning_rate=1e-5, epochs=2):
    #X, Y_t = all_parity_pairs_with_sequence_labels(B)

    X, Y = all_parity_pairs(B)
    N, t = X.shape
    Y_t = np.zeros(X.shape, dtype=np.int32)
    for n in range(N):
        ones_count = 0
        for i in range(t):
            if X[n, i] == 1:
                ones_count += 1
            if ones_count % 2 == 1:
                Y_t[n, i] = 1

    X = X.reshape(N, t, 1).astype(np.float32)


    #rnn = SimpleRNN(20)
    rnn = SimpleRNN(4)
    rnn.fit(X, Y_t, learning_rate=learning_rate, epochs=epochs, activation=T.nnet.relu, show_fig=False)
def deep():
	X, Y = all_parity_pairs(12)
	model = ANN([1024]*2)
	model.fit(X, Y, learning_rate=10e-4, print_period=10, epochs=100, show_fig=True)
def wide():
    X, Y = all_parity_pairs(12)
    model = ANN([2048])
def deep():
    # Challenge - find a deeper, slimmer network to solve the problem
    X, Y = all_parity_pairs(12)
    model = ANN([1024]*2)
def wide():
    X, Y = all_parity_pairs(12)
    model = ANN([2048])
    model.fit(X, Y, learning_rate=1e-4, print_period=10, epochs=300, show_fig=True)
def deep():
    # Challenge - find a deeper, slimmer network to solve the problem
    X, Y = all_parity_pairs(12)
    model = ANN([1024]*2)
    model.fit(X, Y, learning_rate=1e-3, print_period=10, epochs=100, show_fig=True)