Mercurial > pylearn
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simple_autoassociator.py/graph.py Tue Jul 08 02:27:00 2008 -0400 @@ -0,0 +1,25 @@ +""" +Theano graph for a simple autoassociator. +@todo: Make nearly everything private. +""" + +from pylearn.nnet_ops import sigmoid, binary_crossentropy +from theano import tensor as t +from theano.tensor import dot +x = t.dvector() +w1 = t.dmatrix() +b1 = t.dvector() +w2 = t.dmatrix() +b2 = t.dvector() +h = sigmoid(dot(x, w1) + b1) +y = sigmoid(dot(h, w2) + b2) + +loss = t.sum(binary_crossentropy(y, x)) + +(gw1, gb1, gw2, gb2) = t.grad(loss, [w1, b1, w2, b2]) + +import theano.compile + +inputs = [x, w1, b1, w2, b2] +outputs = [y, loss, gw1, gb1, gw2, gb2] +trainfn = theano.compile.function(inputs, outputs)