view sandbox/simple_autoassociator/graph.py @ 393:36baeb7125a4

Made sandbox directory
author Joseph Turian <turian@gmail.com>
date Tue, 08 Jul 2008 18:46:26 -0400
parents simple_autoassociator/graph.py@e2cb8d489908
children 8cc11ac97087
line wrap: on
line source

"""
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_unsummed = binary_crossentropy(y, x)
loss = t.sum(loss_unsummed)

(gw1, gb1, gw2, gb2, gy) = t.grad(loss, [w1, b1, w2, b2, y])

import theano.compile

inputs  = [x, w1, b1, w2, b2]
outputs = [y, h, loss, loss_unsummed, gw1, gb1, gw2, gb2, gy]
trainfn = theano.compile.function(inputs, outputs)