예제 #1
0
파일: ann_test.py 프로젝트: DaniM/mscthesis
        Y[i,((y[i]-1)%num_labels)] = 1;
    y = Y;

    # Unroll parameters
    nn_params = np.concatenate((Theta1.flatten(),Theta2.flatten()),axis=2)
    
    results5 = [-9.2783e-003,8.8991e-003,-8.3601e-003,7.6281e-003,-6.7480e-003]
    
    J,grad = ANN.costFunction(nn_params, input_layer_size, hidden_layer_size, num_labels, X, y)
    
    print grad[0:5],results5
    print grad


#test if the sigmoid grad is working properly
print ANN.sigmoidGrad(0)
print ANN.sigmoidGrad(np.zeros((3,3)))

input_layer_size  = 400;  # 20x20 Input Images of Digits
hidden_layer_size = 25;   # 25 hidden units
num_labels = 10;          # 10 labels, from 1 to 10   
                          # (note that we have mapped "0" to label 10)

#load the precalculated weights to check cost function is working
theta1 = np.loadtxt(open("testfiles/Theta1.txt","rb"),delimiter=",")
theta2 = np.loadtxt(open("testfiles/Theta2.txt","rb"),delimiter=",")
X = np.loadtxt(open("testfiles/ann_test_data.txt","rb"),delimiter=",")
y = np.loadtxt(open("testfiles/ann_test_output.txt","rb"),delimiter=",")

m = X.shape[0]
# Add ones to the X data matrix