예제 #1
0
 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
0
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