objectives.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:NumpyDL 作者: oujago 项目源码 文件源码
def forward(self, outputs, targets):
        """SoftmaxCategoricalCrossEntropy forward propagation.

        .. math:: L_i = - \\sum_j{t_{i,j} \\log(p_{i,j})}

        Parameters
        ----------
        outputs : numpy.array
            Predictions in (0, 1), such as softmax output of a neural network,
            with data points in rows and class probabilities in columns.
        targets : numpy.array
            Either targets in [0, 1] matching the layout of `outputs`, or
            a vector of int giving the correct class index per data point.

        Returns
        -------
        numpy 1D array
            An expression for the item-wise categorical cross-entropy.
        """
        outputs = np.clip(outputs, self.epsilon, 1 - self.epsilon)
        return np.mean(-np.sum(targets * np.log(outputs), axis=1))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号