提交 f06bd5d1 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Indentation and whitespace.

上级 c63fe0ea
......@@ -505,4 +505,3 @@ class Test_check_isfinite(unittest.TestCase):
print infs
f(infs)
return
......@@ -7,35 +7,35 @@ from theano.tensor.nnet import sigmoid
class NNet(object):
def __init__(self,
input = tensor.dvector('input'),
target = tensor.dvector('target'),
n_input=1, n_hidden=1, n_output=1, lr=1e-3, **kw):
super(NNet, self).__init__(**kw)
def __init__(self,
input = tensor.dvector('input'),
target = tensor.dvector('target'),
n_input=1, n_hidden=1, n_output=1, lr=1e-3, **kw):
super(NNet, self).__init__(**kw)
self.input = input
self.target = target
self.lr = shared(lr, 'learning_rate')
self.w1 = shared(numpy.zeros((n_hidden, n_input)), 'w1')
self.w2 = shared(numpy.zeros((n_output, n_hidden)), 'w2')
print self.lr.type
self.input = input
self.target = target
self.lr = shared(lr, 'learning_rate')
self.w1 = shared(numpy.zeros((n_hidden, n_input)), 'w1')
self.w2 = shared(numpy.zeros((n_output, n_hidden)), 'w2')
print self.lr.type
self.hidden = sigmoid(tensor.dot(self.w1, self.input))
self.output = tensor.dot(self.w2, self.hidden)
self.cost = tensor.sum((self.output - self.target)**2)
self.hidden = sigmoid(tensor.dot(self.w1, self.input))
self.output = tensor.dot(self.w2, self.hidden)
self.cost = tensor.sum((self.output - self.target)**2)
self.sgd_updates = {
self.w1: self.w1 - self.lr * tensor.grad(self.cost, self.w1),
self.w2: self.w2 - self.lr * tensor.grad(self.cost, self.w2)}
self.sgd_updates = {
self.w1: self.w1 - self.lr * tensor.grad(self.cost, self.w1),
self.w2: self.w2 - self.lr * tensor.grad(self.cost, self.w2)}
self.sgd_step = pfunc(
params = [self.input, self.target],
outputs = [self.output, self.cost],
updates = self.sgd_updates)
self.sgd_step = pfunc(
params = [self.input, self.target],
outputs = [self.output, self.cost],
updates = self.sgd_updates)
self.compute_output = pfunc([self.input], self.output)
self.compute_output = pfunc([self.input], self.output)
self.output_from_hidden = pfunc([self.hidden], self.output)
self.output_from_hidden = pfunc([self.hidden], self.output)
class TestNnet(unittest.TestCase):
......@@ -56,4 +56,3 @@ class TestNnet(unittest.TestCase):
# Just call functions to make sure they do not crash.
out = nnet.compute_output(input)
out = nnet.output_from_hidden(numpy.ones(10))
......@@ -62,4 +62,3 @@ class T_solve(unittest.TestCase):
self.assertTrue(numpy.all(are < 1.0e-5), (are, Ax, b))
#print A,b
#print numpy.dot(A,x)
......@@ -39,7 +39,7 @@ class test_ScalarOps(unittest.TestCase):
#so this is not a silent bug.
def tes_mod(self):
"""
We add this test as not all language and C implementation give the same
We add this test as not all language and C implementation give the same
signe to the result. This check that the c_code of `Mod` is implemented
as Python. That is what we want.
"""
......@@ -161,7 +161,7 @@ class test_logical(unittest.TestCase):
fn = gof.DualLinker().accept(Env([x,y], [x & y])).make_function()
for a,b in ((0,1), (0,0), (1,0), (1,1)):
self.assertTrue(fn(a,b) == (a & b), (a,b))
def test_not(self):
x, y, z = ints('xyz')
fn = gof.DualLinker().accept(Env([x,y], [invert(x)])).make_function()
......@@ -196,7 +196,3 @@ class test_div(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
......@@ -240,4 +240,3 @@ class test_true_dot(unittest.TestCase):
w = w - (lr * gw)
self.assertTrue(origloss > loss)
......@@ -16,7 +16,7 @@ class TestSignalConv2D(unittest.TestCase):
utt.seed_rng()
def validate(self, image_shape, filter_shape, verify_grad=True):
image_dim = len(image_shape)
filter_dim = len(filter_shape)
input = T.TensorType('float64', [False]*image_dim)()
......@@ -33,12 +33,12 @@ class TestSignalConv2D(unittest.TestCase):
return conv.conv2d(input, filters)
output = sym_conv2d(input, filters)
theano_conv = theano.function([input, filters], output)
# initialize input and compute result
image_data = numpy.random.random(image_shape)
filter_data = numpy.random.random(filter_shape)
theano_output = theano_conv(image_data, filter_data)
############# REFERENCE IMPLEMENTATION ############
out_shape2d = numpy.array(image_shape[-2:]) -\
numpy.array(filter_shape[-2:]) + 1
......
......@@ -45,7 +45,7 @@ class test_casting(unittest.TestCase):
f = function([a],basic._convert_to_complex128(a))
#we need to compare with the same type.
assert a.type.values_eq_approx(b.data, f(a.data))
f = function([b],basic._convert_to_complex128(b))
assert b.type.values_eq_approx(b.data, f(b.data))
......@@ -77,7 +77,7 @@ class test_casting(unittest.TestCase):
f = function([a],basic._convert_to_complex64(a))
assert a.type.values_eq_approx(b.data, f(a.data))
def test_bug_complext_10_august_09(self):
v0 = dmatrix()
v1 = basic._convert_to_complex128(v0)
......
......@@ -9,7 +9,7 @@ class Test_inc_subtensor(unittest.TestCase):
What could be tested:
- increment vs set
- thing incremented: scalar, vector, matrix,
- thing incremented: scalar, vector, matrix,
- increment/set: constant, scalar, vector, matrix
- indices: scalar vs slice, constant vs variable, out of bound, ...
- inplace
......@@ -50,7 +50,7 @@ class Test_inc_subtensor(unittest.TestCase):
expected_result[:,:val_sl2_end] = val_inc
else:
expected_result[:,:val_sl2_end] += val_inc
self.assertTrue(numpy.array_equal(result, expected_result))
return
......@@ -68,20 +68,17 @@ class Test_inc_subtensor(unittest.TestCase):
# vector
utt.verify_grad(
inc_slice(slice(2,4,None)),
(numpy.asarray([0,1,2,3,4,5.]),
(numpy.asarray([0,1,2,3,4,5.]),
numpy.asarray([9,9.]),))
# matrix
utt.verify_grad(
inc_slice(slice(1,2,None), slice(None, None, None)),
(numpy.asarray([[0,1],[2,3],[4,5.]]),
(numpy.asarray([[0,1],[2,3],[4,5.]]),
numpy.asarray([[9,9.]]),))
#single element
utt.verify_grad(
inc_slice(2, 1),
(numpy.asarray([[0,1],[2,3],[4,5.]]),
(numpy.asarray([[0,1],[2,3],[4,5.]]),
numpy.asarray(9.),))
......@@ -9,7 +9,7 @@ class Test_incsubtensor(unittest.TestCase):
What could be tested:
- increment vs set
- thing incremented: scalar, vector, matrix,
- thing incremented: scalar, vector, matrix,
- increment/set: constant, scalar, vector, matrix
- indices: scalar vs slice, constant vs variable, out of bound, ...
- inplace
......@@ -47,7 +47,7 @@ class Test_incsubtensor(unittest.TestCase):
expected_result[:,:val_sl2_end] = val_inc
else:
expected_result[:,:val_sl2_end] += val_inc
self.assertTrue(numpy.array_equal(result, expected_result))
return
......@@ -65,20 +65,17 @@ class Test_incsubtensor(unittest.TestCase):
# vector
utt.verify_grad(
inc_slice(slice(2,4,None)),
(numpy.asarray([0,1,2,3,4,5.]),
(numpy.asarray([0,1,2,3,4,5.]),
numpy.asarray([9,9.]),))
# matrix
utt.verify_grad(
inc_slice(slice(1,2,None), slice(None, None, None)),
(numpy.asarray([[0,1],[2,3],[4,5.]]),
(numpy.asarray([[0,1],[2,3],[4,5.]]),
numpy.asarray([[9,9.]]),))
#single element
utt.verify_grad(
inc_slice(2, 1),
(numpy.asarray([[0,1],[2,3],[4,5.]]),
(numpy.asarray([[0,1],[2,3],[4,5.]]),
numpy.asarray(9.),))
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论