#NEWLINE# def get_reconstruction_cost( self , updates , pre_sigmoid_nv ) : #NEWLINE# #INDENT# 'Approximation to the reconstruction error\n\n        Note that this function requires the pre-sigmoid activation as\n        input.  To understand why this is so you need to understand a\n        bit about how Theano works. Whenever you compile a Theano\n        function, the computational graph that you pass as input gets\n        optimized for speed and stability.  This is done by changing\n        several parts of the subgraphs with others.  One such\n        optimization expresses terms of the form log(sigmoid(x)) in\n        terms of softplus.  We need this optimization for the\n        cross-entropy since sigmoid of numbers larger than 30. (or\n        even less then that) turn to 1. and numbers smaller than\n        -30. turn to 0 which in terms will force theano to compute\n        log(0) and therefore we will get either -inf or NaN as\n        cost. If the value is expressed in terms of softplus we do not\n        get this undesirable behaviour. This optimization usually\n        works fine, but here we have a special case. The sigmoid is\n        applied inside the scan op, while the log is\n        outside. Therefore Theano will only see log(scan(..)) instead\n        of log(sigmoid(..)) and will not apply the wanted\n        optimization. We can not go and replace the sigmoid in scan\n        with something else also, because this only needs to be done\n        on the last step. Therefore the easiest and more efficient way\n        is to get also the pre-sigmoid activation as an output of\n        scan, and apply both the log and sigmoid outside scan such\n        that Theano can catch and optimize the expression.\n\n        ' #NEWLINE# cross_entropy = T . mean ( T . sum ( ( ( self . input * T . log ( T . nnet . sigmoid ( pre_sigmoid_nv ) ) ) + ( ( 1 - self . input ) * T . log ( ( 1 - T . nnet . sigmoid ( pre_sigmoid_nv ) ) ) ) ) , axis = 1 ) ) #NEWLINE# return cross_entropy