Mercurial > pylearn
annotate simple_autoassociator.py/graph.py @ 386:a474341861fa
Added a simple AA
author | Joseph Turian <turian@gmail.com> |
---|---|
date | Tue, 08 Jul 2008 02:27:00 -0400 |
parents | sparse_random_autoassociator/graph.py@edec18614a70 |
children | 98ca97cc9910 |
rev | line source |
---|---|
370
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
1 """ |
386 | 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 | 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 | 9 x = t.dvector() |
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 | 12 w2 = t.dmatrix() |
13 b2 = t.dvector() | |
14 h = sigmoid(dot(x, w1) + b1) | |
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 |
386 | 17 loss = t.sum(binary_crossentropy(y, x)) |
370
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
18 |
386 | 19 (gw1, gb1, gw2, gb2) = t.grad(loss, [w1, b1, w2, b2]) |
370
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
20 |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
21 import theano.compile |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
22 |
386 | 23 inputs = [x, w1, b1, w2, b2] |
24 outputs = [y, loss, gw1, gb1, gw2, gb2] | |
370
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
25 trainfn = theano.compile.function(inputs, outputs) |