本文整理汇总了Python中error.Error.total_error方法的典型用法代码示例。如果您正苦于以下问题:Python Error.total_error方法的具体用法?Python Error.total_error怎么用?Python Error.total_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类error.Error
的用法示例。
在下文中一共展示了Error.total_error方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gradient
# 需要导入模块: from error import Error [as 别名]
# 或者: from error.Error import total_error [as 别名]
def test_gradient(self, xL, xR, cat):
epsilon = 10**(-8)
a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb = self.forward_pass(xL, xR)
grad3, grad2L, grad2LR, grad2R, grad1L, grad1R = self.backward_pass(a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb, cat)
expected_gradient = grad1L[0,8];
e=Error()
self.w1l[0,8] += epsilon
a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb = self.forward_pass(xL, xR)
e_plus = e.total_error(a3,cat, self.k)[0]
self.w1l[0,8] -= (2*epsilon)
a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb = self.forward_pass(xL, xR)
e_minus = e.total_error(a3,cat, self.k)[0]
self.w1l[0,8] += epsilon
difference = (e_plus-e_minus)
approx_grad = difference/(2*epsilon)
print "Derivative = "+str(approx_grad)
print "Gradient = "+str(expected_gradient)
print "Difference "+str(approx_grad-expected_gradient)