annotate simple_autoassociator/graph.py @ 392:e2cb8d489908

More debugging
author Joseph Turian <turian@gmail.com>
date Tue, 08 Jul 2008 18:45:35 -0400
parents ec8aadb6694d
children
rev   line source
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
1 """
386
a474341861fa Added a simple AA
Joseph Turian <turian@gmail.com>
parents: 384
diff changeset
2 Theano graph for a simple autoassociator.
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
3 @todo: Make nearly everything private.
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
4 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
5
383
344d1f874af7 Small fix
Joseph Turian <turian@gmail.com>
parents: 382
diff changeset
6 from pylearn.nnet_ops import sigmoid, binary_crossentropy
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
7 from theano import tensor as t
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
8 from theano.tensor import dot
386
a474341861fa Added a simple AA
Joseph Turian <turian@gmail.com>
parents: 384
diff changeset
9 x = t.dvector()
a474341861fa Added a simple AA
Joseph Turian <turian@gmail.com>
parents: 384
diff changeset
10 w1 = t.dmatrix()
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
11 b1 = t.dvector()
386
a474341861fa Added a simple AA
Joseph Turian <turian@gmail.com>
parents: 384
diff changeset
12 w2 = t.dmatrix()
a474341861fa Added a simple AA
Joseph Turian <turian@gmail.com>
parents: 384
diff changeset
13 b2 = t.dvector()
a474341861fa Added a simple AA
Joseph Turian <turian@gmail.com>
parents: 384
diff changeset
14 h = sigmoid(dot(x, w1) + b1)
a474341861fa Added a simple AA
Joseph Turian <turian@gmail.com>
parents: 384
diff changeset
15 y = sigmoid(dot(h, w2) + b2)
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
16
388
98ca97cc9910 Debugging simple AA
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
17 loss_unsummed = binary_crossentropy(y, x)
98ca97cc9910 Debugging simple AA
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
18 loss = t.sum(loss_unsummed)
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
19
392
e2cb8d489908 More debugging
Joseph Turian <turian@gmail.com>
parents: 389
diff changeset
20 (gw1, gb1, gw2, gb2, gy) = t.grad(loss, [w1, b1, w2, b2, y])
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
21
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
22 import theano.compile
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
23
386
a474341861fa Added a simple AA
Joseph Turian <turian@gmail.com>
parents: 384
diff changeset
24 inputs = [x, w1, b1, w2, b2]
392
e2cb8d489908 More debugging
Joseph Turian <turian@gmail.com>
parents: 389
diff changeset
25 outputs = [y, h, loss, loss_unsummed, gw1, gb1, gw2, gb2, gy]
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
26 trainfn = theano.compile.function(inputs, outputs)