Example #1
0
def main():
    m = readMatrix('matrix_games/5x5.txt')
    numR, numC = m.shape
    
    Population.initPopulation = initPopulation
    Population.evolve = evolve
    p = Population(30, 2)
    p.initPopulation(numC, numR)
    p.evolve(m)
Example #2
0
def main():     
    pygame.init() 
    window = pygame.display.set_mode((d_width, d_height)) 
    
    circles = getCircles()
    for circle in circles: 
        pygame.draw.circle(window, (255, 255, 255), circle[0], circle[1], 1)
        
    Population.initPopulation = initPopulation
    Population.evolve = evolve
    p = Population(80, 3)
    p.initPopulation()
    p.evolve(window, circles)
        
    #pygame.display.flip()
    
    while True: 
        for event in pygame.event.get(): 
            if event.type == pygame.QUIT: 
                sys.exit(0)
Example #3
0
def testNeuralNetWithGA():
    net = NeuralNet(2, 2, 1)
    t_model = utils.readTrainModel(os.path.join(utils.getResourcesPath(), 'logic_gates/NAND.txt'))
    Population.initPopulation = initPopulation
    Population.evolve = evolve
    p = Population(70, 9)
    p.initPopulation()
    p.evolve(net, t_model)
    

    print(net.getOutputs([0, 0]))
    print(net.getOutputs([0, 1]))
    print(net.getOutputs([1, 0]))
    print(net.getOutputs([1, 1]))
    print(net.getError(t_model))
    
#testPerceptron()
#testNeuralNet()
#testNeuralNetWithGA()
#numberRecognition()
Example #4
0
def main():     
    pygame.init()     
    maze = readMaze('mazes/9x15.txt')
    numR, numC = maze.shape
    window = pygame.display.set_mode((numC * square_l, numR * square_l))
    renderMaze(window, maze)
    
    Population.initPopulation = initPopulation
    Population.evolve = evolve
    p = Population(50, 30)
    p.mutation_rate = 0.1
    p.elites_num = 5
    p.initPopulation()
    p.evolve(window, maze)
    print("done")
    
    while True: 
        for event in pygame.event.get(): 
            if event.type == pygame.QUIT: 
                sys.exit(0)
Example #5
0
def main(): 
    global fitnessHistory  
    Population.initPopulation = initPopulation
    Population.evolve = evolve
    p = Population(30, 1)
    #fig = plt.figure()
    
    for i in range(1):
        colors = ['b', 'r', 'g']
        p.initPopulation()
        p.evolve()
        
        #ax = fig.add_subplot(111)
        #ax.plot(np.arange(len(fitnessHistory)), fitnessHistory, c=colors[i])
        fitnessHistory = []
    
    h = np.array(history)
    h = np.rot90(h, 1)
    print(h)
    plt.imshow(h, cmap='Greys', aspect='auto', interpolation='nearest')
    plt.show()