本文整理汇总了Python中NN.nnCostFunction方法的典型用法代码示例。如果您正苦于以下问题:Python NN.nnCostFunction方法的具体用法?Python NN.nnCostFunction怎么用?Python NN.nnCostFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NN
的用法示例。
在下文中一共展示了NN.nnCostFunction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: costFunc
# 需要导入模块: import NN [as 别名]
# 或者: from NN import nnCostFunction [as 别名]
def costFunc(p):
return NN.nnCostFunction(p, conf.INPUT_LAYER_SIZE,
conf.HIDDEN_LAYER_SIZE, conf.NUM_LABELS,
X, y, conf.PART8_LEARN_RATE)
示例2: Cost
# 需要导入模块: import NN [as 别名]
# 或者: from NN import nnCostFunction [as 别名]
if __name__ == '__main__':
print "Part 1: Loading Data\n"
X, y = utils.loadData(conf.FILE_X, conf.FILE_Y)
print "Part 2: Loading Parameters\n"
W1, W2 = utils.loadParams(conf.FILE_W1, conf.FILE_W2)
# Unroll parameters
W = np.hstack((W1.flatten(0), W2.flatten(0)))
W = W.reshape((len(W), 1))
print "Part 3: Compute Cost(Feedforward)\n"
LEARN_RATE = 0
J, _ = NN.nnCostFunction(W, conf.INPUT_LAYER_SIZE, conf.HIDDEN_LAYER_SIZE,
conf.NUM_LABELS, X, y, LEARN_RATE)
print ("Cost at parameters (loaded from w1.txt and w2.txt): %f"
"\n(this value should be about 0.287629)\n") % J
print "Part 4: Implement Regularization\n"
LEARN_RATE = 1
J, _ = NN.nnCostFunction(W, conf.INPUT_LAYER_SIZE, conf.HIDDEN_LAYER_SIZE,
conf.NUM_LABELS, X, y, LEARN_RATE)
print ("Cost at parameters (loaded from w1.txt and w2.txt): %f"
"\n(this value should be about 0.383770)\n") % J
print "Part 5: Sigmoid Gradient\n"
g = Sigmoid.dy_dz(Sigmoid.y(np.array([-1, -0.5, 0, 0.5, 1])))
print "Sigmoid gradient evaluated at [-1 -0.5 0 0.5 1]:", g