예제 #1
0
def crossover(parents):
    parent1, parent2 = parents
    child_network = []
    for i in range(len(parent1.network)):
        temp_layer = parent1.network[i].copy()
        for j in range(temp_layer.shape[0]):
            temp_layer[j, :] = random.choice(
                [parent1.network[i][j, :], parent2.network[i][j, :]])
        child_network.append(temp_layer)
    child = nn.neuralNet(0, 0)
    child.network = child_network
    return child
예제 #2
0
파일: main.py 프로젝트: nelsong33/NeuralNet
import numpy
from neuralNet import neuralNet

# set variables and create neural network object
input_nodes = 784
hidden_nodes = 100
output_nodes = 10
learning_rate = .3

net = neuralNet(input_nodes, hidden_nodes, output_nodes, learning_rate)

# train neural network
training_data_file = open("mnist_dataset/mnist_train.csv", 'r')

for line in training_data_file:
    all_values = line.split(',')
    inputs = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01
    targets = numpy.zeros(output_nodes) + 0.01
    targets[int(all_values[0])] = 0.99
    net.train(inputs, targets)
    pass

training_data_file.close()

# test neural network
testing_data_file = open("mnist_dataset/mnist_test.csv", 'r')

test_results = []
for line in testing_data_file:
    all_values = line.split(',')
    test_results.append([
예제 #3
0
		if line:
			line = [float(i) for i in line]
			inputs.append(line)

with open('output.txt') as f:
	outputs = []
	for line in f:
		line = line.split()
		if line:
			line = [int(i) for i in line]
			outputs.append(line)

input = np.array(inputs)
output = np.array(outputs)

nn = neuralNet(400,30,10)

# Training
# ---

# Batch training
nn.trainBatch(input,output,20)

# Live training
#tests = np.size(input,0)
#acc = 0
#for i in xrange(0, tests):
#	if (np.argmax(nn.trainLive(input[[i],:],output[i,0])) == output[i,0]):
#		acc = acc + 1
#acc = acc / float(tests) * 100
#print("Live training accuracy: %f" % (acc))
예제 #4
0
import neuralNet as neural

myNeuralNetwork = None
netShape = []

netShape.append(2)
netShape.append(5)
netShape.append(5)
netShape.append(2)

myNeuralNetwork = neural.neuralNet(netShape)
myNeuralNetwork.visualise()

fileHandle = None
fileData = None
trainingList = None
fileHandle = open( 'trainingData.txt', 'r' )
fileData = fileHandle.read()
fileHandle.close()
trainingList = fileData.split(',')

fileHandle1 = None
fileData1 = None
trainingLists = None
fileHandle1 = open('trainingTarget.txt', 'r' )
fileData1 = fileHandle1.read()
fileHandle1.close()
trainingLists = fileData1.split(',')

tl = []
for item in trainingLists:
예제 #5
0
            screen.fill(background_col)
            screen.blit(temp_ground[0], temp_ground_rect)
            if temp_dino.isBlinking:
                screen.blit(logo, logo_rect)
                screen.blit(callout, callout_rect)
            temp_dino.draw()

            pygame.display.update()

        clock.tick(FPS)
        if temp_dino.isJumping == False and temp_dino.isBlinking == False:
            gameStart = True


# Variáveis de jogo
redes = [nn.neuralNet(3, 1, [5]) for i in range(n_rex)]
dead = []
gamespeed = 12
gameOver = [False for n in range(n_rex)]
p_gameOver = False
playerDino = [Dino(44, 47) for n in range(n_rex)]
player = (Dino(44, 47, True))
keys = [non for n in range(n_rex)]

cacti = pygame.sprite.Group()
pteras = pygame.sprite.Group()
clouds = pygame.sprite.Group()
last_obstacle = pygame.sprite.Group()

dists = []
heights = []
예제 #6
0
	#for i in range(0,w):
	#	for j in range(0,h):
	#		r,g,b = [myTestingImage[i,j,0]/255.0,myTestingImage[i,j,1]/255.0,myTestingImage[i,j,2]/255.0]
	#		myImage[i,j] = [r,g,b]

	myTestingImages.append(testing[k])
	myTestingLabels.append(myTestingLabel[0])

print("Data loading completed successfully")

#Before batch training, we validate some important things

myFakeImage = np.array(([[[0.8,0.2,1.0]]]))
myFakeImage = myFakeImage.flatten()

myNN = nn.neuralNet(randomWeightsRange=randomWeightsRange,alpha=alpha,mi=mi,batchSize=batchSize)
myNN.activateNetwork(myFakeImage)
# myNN.transparent()

newWeights,Loss = myNN.batchUpdate([myFakeImage],[1])
myNN.activateNetwork(myFakeImage)
# myNN.transparent()

exit()

# Verify improvements on the testing set
sumC = 0
sum = 0
for i in range(0,int(testing.size/3072)):

	myImageFlattened = (testing[i]).flatten()