'This function computes the cost of this layer.
:param state_below: theano variable representing the input to the
softmax layer
:param target: theano variable representing the target for this
layer
:return: mean cross entropy'

def get_cost(self, state_below, target=None, mask=None, temp=1, reg=None, scale=None, sum_over_time=True, use_noise=True, additional_inputs=None):

    class_probs = self.fprop(state_below, temp=temp, use_noise=use_noise, additional_inputs=additional_inputs)
    pvals = class_probs
    assert target, 'Computing    the    cost    requires    a    target'
    if (target.ndim == 3):
        target = target.reshape(((target.shape[0] * target.shape[1]), target.shape[2]))
    assert ('float' in target.dtype)
    cost = ((class_probs - target) ** 2)
    if mask:
        mask = mask.flatten()
        cost = (cost * TT.cast(mask, theano.config.floatX))
    if (sum_over_time is None):
        sum_over_time = self.sum_over_time
    if sum_over_time:
        if (state_below.ndim == 3):
            sh0 = TT.cast(state_below.shape[0], theano.config.floatX)
            sh1 = TT.cast(state_below.shape[1], theano.config.floatX)
            self.cost = (cost.sum() / sh1)
        else:
            self.cost = cost.sum()
    else:
        self.cost = cost.mean()
    if scale:
        self.cost = (self.cost * scale)
    if reg:
        self.cost = (self.cost + reg)
    self.out = self.cost
    self.mask = mask
    self.cost_scale = scale
    return self.cost
