import numpy
import theano
import theano.tensor as T
rng = numpy.random
N = 400
feats = 784
D = (rng.randn(N, feats), rng.randint(size=N, low=0,high=2) )
training_steps = 10000
x = T.matrix('x', dtype=theano.config.floatX)
y = T.vector('y')
w_1 = theano.shared(rng.randn(784, 300), name='w1')
b_1 = theano.shared(numpy.zeros((300,)), name='b1')
w_2 = theano.shared(rng.randn(300), name='w2')
b_2 = theano.shared(0., name='b2')
from theano.tensor.nnet import sigmoid
p_1 = sigmoid(-T.dot(sigmoid(-T.dot(x, w_1)-b_1), w_2)-b_2)
prediction = p_1 > 0.5
xent = -y*T.log(p_1) - (1-y)*T.log(1-p_1)
cost = xent.mean() + 0.01 * (w_2** 2).sum()
gw_1, gb_1, gw_2, gb_2 = T.grad(cost, [w_1, b_1, w_2, b_2])
train = theano.function(inputs = [x, y], outputs = [prediction, xent],
                        updates = {w_1 : w_1-0.1*gw_1, b_1 : b_1-0.1*gb_1,
                        w_2 : w_2-0.1*gw_2, b_2 : b_2-0.1*gb_2},
                        allow_input_downcast=True)
predict = theano.function(inputs=[x], outputs=prediction,
                          allow_input_downcast=True)
for i in range(training_steps):
    pred, err = train(D[0], D[1])

print("target values for D:\n{}".format(D[1]))
print("predictions on D:\n{}".format(predict(D[0])))
print(all(predict(D[0]) == D[1]))
2c281c48d5a9711a9b8bd22e2f1d2b3ceb515658
<mask token>

<mask token>
for i in range(training_steps):
    pred, err = train(D[0], D[1])
print("""target values for D:
{}""".format(D[1]))
print("""predictions on D:
{}""".format(predict(D[0])))
print(all(predict(D[0]) == D[1]))

<mask token>
rng = numpy.random
N = 400
feats = 784
D = rng.randn(N, feats), rng.randint(size=N, low=0, high=2)
training_steps = 10000
x = T.matrix('x', dtype=theano.config.floatX)
y = T.vector('y')
w_1 = theano.shared(rng.randn(784, 300), name='w1')
b_1 = theano.shared(numpy.zeros((300,)), name='b1')
w_2 = theano.shared(rng.randn(300), name='w2')
b_2 = theano.shared(0.0, name='b2')
<mask token>
p_1 = sigmoid(-T.dot(sigmoid(-T.dot(x, w_1) - b_1), w_2) - b_2)
prediction = p_1 > 0.5
xent = -y * T.log(p_1) - (1 - y) * T.log(1 - p_1)
cost = xent.mean() + 0.01 * (w_2 ** 2).sum()
gw_1, gb_1, gw_2, gb_2 = T.grad(cost, [w_1, b_1, w_2, b_2])
train = theano.function(inputs=[x, y], outputs=[prediction, xent], updates=
    {w_1: w_1 - 0.1 * gw_1, b_1: b_1 - 0.1 * gb_1, w_2: w_2 - 0.1 * gw_2,
    b_2: b_2 - 0.1 * gb_2}, allow_input_downcast=True)
predict = theano.function(inputs=[x], outputs=prediction,
    allow_input_downcast=True)
for i in range(training_steps):
    pred, err = train(D[0], D[1])
print("""target values for D:
{}""".format(D[1]))
print("""predictions on D:
{}""".format(predict(D[0])))
print(all(predict(D[0]) == D[1]))

import numpy
import theano
import theano.tensor as T
rng = numpy.random
N = 400
feats = 784
D = rng.randn(N, feats), rng.randint(size=N, low=0, high=2)
training_steps = 10000
x = T.matrix('x', dtype=theano.config.floatX)
y = T.vector('y')
w_1 = theano.shared(rng.randn(784, 300), name='w1')
b_1 = theano.shared(numpy.zeros((300,)), name='b1')
w_2 = theano.shared(rng.randn(300), name='w2')
b_2 = theano.shared(0.0, name='b2')
from theano.tensor.nnet import sigmoid
p_1 = sigmoid(-T.dot(sigmoid(-T.dot(x, w_1) - b_1), w_2) - b_2)
prediction = p_1 > 0.5
xent = -y * T.log(p_1) - (1 - y) * T.log(1 - p_1)
cost = xent.mean() + 0.01 * (w_2 ** 2).sum()
gw_1, gb_1, gw_2, gb_2 = T.grad(cost, [w_1, b_1, w_2, b_2])
train = theano.function(inputs=[x, y], outputs=[prediction, xent], updates=
    {w_1: w_1 - 0.1 * gw_1, b_1: b_1 - 0.1 * gb_1, w_2: w_2 - 0.1 * gw_2,
    b_2: b_2 - 0.1 * gb_2}, allow_input_downcast=True)
predict = theano.function(inputs=[x], outputs=prediction,
    allow_input_downcast=True)
for i in range(training_steps):
    pred, err = train(D[0], D[1])
print("""target values for D:
{}""".format(D[1]))
print("""predictions on D:
{}""".format(predict(D[0])))
print(all(predict(D[0]) == D[1]))

import numpy
import theano
import theano.tensor as T
rng = numpy.random
N = 400
feats = 784
D = (rng.randn(N, feats), rng.randint(size=N, low=0,high=2) )
training_steps = 10000
x = T.matrix('x', dtype=theano.config.floatX)
y = T.vector('y')
w_1 = theano.shared(rng.randn(784, 300), name='w1')
b_1 = theano.shared(numpy.zeros((300,)), name='b1')
w_2 = theano.shared(rng.randn(300), name='w2')
b_2 = theano.shared(0., name='b2')
from theano.tensor.nnet import sigmoid
p_1 = sigmoid(-T.dot(sigmoid(-T.dot(x, w_1)-b_1), w_2)-b_2)
prediction = p_1 > 0.5
xent = -y*T.log(p_1) - (1-y)*T.log(1-p_1)
cost = xent.mean() + 0.01 * (w_2** 2).sum()
gw_1, gb_1, gw_2, gb_2 = T.grad(cost, [w_1, b_1, w_2, b_2])
train = theano.function(inputs = [x, y], outputs = [prediction, xent],
                        updates = {w_1 : w_1-0.1*gw_1, b_1 : b_1-0.1*gb_1,
                        w_2 : w_2-0.1*gw_2, b_2 : b_2-0.1*gb_2},
                        allow_input_downcast=True)
predict = theano.function(inputs=[x], outputs=prediction,
                          allow_input_downcast=True)
for i in range(training_steps):
    pred, err = train(D[0], D[1])

print("target values for D:\n{}".format(D[1]))
print("predictions on D:\n{}".format(predict(D[0])))
print(all(predict(D[0]) == D[1]))