def cost(self, readouts, outputs):
        """
        All steps or single step

        :param readouts: output of hidden layer [batch_size,input_dim] or
         [steps,batch_size,input_dim]
        :param outputs: sketch cordinates of next time period batch_size,3] or
         [steps, batch_size,3]
        :return: NLL [batch_size] or [steps,batch_size]
        """
        nll_ndim = readouts.ndim - 1
        nll_shape = readouts.shape[:-1]
        # if we have steps flatten steps,bacth_size to steps*batch_size
        outputs = outputs.reshape((-1,3))
        mean, sigma, corr, weight, penup = self.components(readouts)

        # duplicate the output over all mix_dim
        d = outputs[:,:2].dimshuffle((0, 'x', 1)) - mean  # 25
        # [batch_size,mix_dim]
        sigma2 = sigma[:,:,0] * sigma[:,:,1] + self.epsilon  # 25
        z = d ** 2 / sigma ** 2
        # [batch_size,mix_dim]
        z = z.sum(axis=-1) - 2 * corr * (d[:,:,0] * d[:,:,1]) / sigma2  # 25
        corr1 = 1 - corr ** 2 + self.epsilon  # 24
        n = - z / (2 * corr1)  # 24 [batch_size,mix_dim]
        nmax = n.max(axis=-1, keepdims=True)
        n = n - nmax
        n = T.exp(n) / (2*np.pi*sigma2*T.sqrt(corr1))  # 24
        # [batch_size]
        nll = -T.log((n * weight).sum(axis=-1, keepdims=True) + self.epsilon)
        nll -= nmax
        nll += T.nnet.binary_crossentropy(penup, outputs[:,2:])  # 26

        return nll.reshape(nll_shape, ndim=nll_ndim)
dataset/ETHPy150Open udibr/sketch/sketch.py/SketchEmitter.cost/original