本文整理匯總了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