from network import ANN from compare import * from train import Trainer import numpy as np x = np.array([[4, 5.5], [4.5, 1], [9, 2.5], [6,2], [10, 10]], dtype = float) y = np.array([[70], [89], [85], [75], [10]], dtype = float) N = ANN(2, 5, 1, 0.000001) x = x / np.amax(x) y = y / np.amax(y) print "y -> net(y)" print y, "\n------------\n", N.forward(x) ag = analyticalGrad(N, x, y) ng = numericalGrad (N, x, y) print "Analytical grad: ", sum(ag), ", ", ag.shape print "Numerical grad: ", sum(ng), ", ", ng.shape T = Trainer(N) T.train(x,y) ag = analyticalGrad(N, x, y) ng = numericalGrad (N, x, y) print "Analytical grad: ", sum(ag), ", ", ag.shape print "Numerical grad: ", sum(ng), ", ", ng.shape
training_features = np.asarray(training_features) # Build training labels training_labels = [] for i in range (len(training)): training_labels.append( list(np.asarray( list(training[i][1]), dtype = int ))) training_labels = np.asarray(training_labels) print ("\nWeight W2:", nn.W2) #print ("\nTraining features: \n", pd.DataFrame(training_features)) #print ("\nTrue: \n", pd.DataFrame(training_labels)) output = nn.forward(training_features) #probs of last layer print ("\nOutput: ", output) msqe = nn.get_mean_squared_error_for_epoch(output, training_labels) #array with all squared errors for all examples print ("\nMean Squared Error: ", msqe) #nn.a1 is the output from the hidden layer #nn.w2 is the weights from the hidden to the output layer #dJdW1, dJdW2 = nn.costFunctionPrime(output, training_labels, training_features) #dJdW1, dJdW2 = nn.costFunctionPrime(output, training_labels, training_features) #print ("\ndJdW2: ", dJdW2) #print ("\ndJdW2 w/ learning rate: ", dJdW2*l_rate)