def main2(): infrastructure = np.array([2, 3, 2]) initial_values = np.array([1, 0]) network = neural.Network() nodeCount = infrastructure.sum() for i in range(0, infrastructure.__len__()): for layerCount in range(0, infrastructure[i]): node = neural.Node() if i == 0: node.value = initial_values[i] node.bias = randint(-10, 10) network.add_node("layer" + str(i + 1) + "node" + str(layerCount), node) network.show_network()
# -*- coding: utf-8 -*- """ Created on Tue Mar 6 14:14:54 2018 @author: jia335 Some default brains to start with """ import neuralnetwork as NN ''' The basic brain I used at the start. Not very clever. ''' simpleBrain = NN.Network() simpleBrain.createNetwork([3, 2], [2, 2]) ''' Moves towards nearest food (hopefully) ''' naiveBrain = NN.Network() naiveBrain.addInputs(3) naiveBrain.addOutputs(2) naiveBrain.addSynapse(naiveBrain.inputs[1], naiveBrain.outputs[1]) naiveBrain.addSynapse(naiveBrain.inputs[0], naiveBrain.outputs[0]) for syn in naiveBrain.synapses: syn.weight = 1 for out in naiveBrain.outputs: out.type = 'Sum' brains = {'Simple Brain': simpleBrain, 'Naive Brain': naiveBrain}
import mnist_loader import numpy as np import matplotlib.pyplot as plt import neuralnetwork as network def plot(pixels): pixels = np.array(pixels, dtype='float32') # Reshape the array into 28 x 28 array (2-dimensional array) pixels = pixels.reshape((28, 28)) # Plot plt.imshow(pixels, cmap='gray') plt.show() training_data, validation_data, test_data = mnist_loader.load_data_wrapper() arr, label = test_data[-1] net = network.Network([784, 100, 10]) net.default_weight_initializer() net.stochastic_gradient_descent(training_data, 30, 10, 0.5, evaluation_data=test_data, monitor_evaluation_accuracy=True) print net.predict(arr)
ball = Ball(WHITE) ball.rect.x = 240 ball.rect.y = 150 all_sprites_list.add(ball) ball_list.add(ball) # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() pop=[neuralnetwork.Network([5,3]) for i in range(20)] brain=neuralnetwork.createandtrain(pop,100) score_reached = False # Setting the score display score1 = 0 score1_font = pygame.font.Font(None, 50) score1_surf = score1_font.render(str(score1) , 1, (255, 255, 255)) score1_pos = [30, 10] score2 = 0 score2_font = pygame.font.Font(None, 50) score2_surf = score2_font.render(str(score2), 1, (255, 255, 255)) score2_pos = [360, 10]
import eigen_face_loader trainingData, testData = eigen_face_loader.load_data() import neuralnetwork net = neuralnetwork.Network([len(trainingData), 200, 15]) net.SGD(trainingData, 50, 5, .09, 15, test_data = testData)
import neuralnetwork import pickle #Creating, Training and Saving network = neuralnetwork.Network([2, 3, 1], [0.2, 0.1], 0.5) andGateTrainingSet = { (0, 0): (0, ), (0, 1): (0, ), (1, 0): (0, ), (1, 1): (1, ) } network.debug(True) #periodically shows the average error of the training set network.training(andGateTrainingSet) pickle.dump(network, open("filename.p", "wb")) #Loading and Using loadedNetwork = pickle.load(open("filename.p", "rb")) loadedNetwork.forwardPass((0, 1)) result = loadedNetwork.getOutput() print( result ) #outputs [0.001156001503972413] which is close to the intended output (0)
''' import mnist_loader trainingData, validation_data, testData = mnist_loader.load_data_wrapper() import copyCode net = copyCode.Network([len(trainingData), 100, 10]) net.SGD(trainingData, 100, 30, .1, test_data = testData) ''' import mnist_loader trainingData, test_data = mnist_loader.load_data_wrapper() import neuralnetwork net = neuralnetwork.Network([784, 30, 10]) net.SGD(trainingData, 10, 10, 3.0, 10, test_data=test_data)
import neuralnetwork as net import mnist_loader #loading MNIST handwritten number image data training_data, validation_data, test_data = mnist_loader.load_data_wrapper() training_data = list(training_data) #Pre-training visual example of data mnist_loader.show_data() #Creating network with 784 input sigmoid neurons, 30 hidden, 10 output net = net.Network([784, 30, 10]) net.SGD(training_data, 30, 10, 3.0, test_data=test_data)