项目作者: goktug97

项目描述 :
Evolving Neural Networks Through Augmenting Topologies
高级语言: Python
项目地址: git://github.com/goktug97/NEAT.git
创建时间: 2020-03-16T16:51:24Z
项目社区:https://github.com/goktug97/NEAT

开源协议:MIT License

下载


Evolving Neural Networks Through Augmenting Topologies

Python Implementation of NEAT Genetic Algorithm

Snake

Above gif was pure luck and it is from an earlier version which allows connection to inputs and connection from outputs.

Requirements

  • Python >= 3.6

Optional

  • Matplotlib (To draw genomes)

Gym Examples

  • gym
  • mpi4py (Parallel NEAT Example)

Snake Example

Install

  1. git clone https://github.com/goktug97/NEAT
  2. cd NEAT
  3. python3 setup.py install --user

Usage

xor.py

  1. import neat
  2. xor = neat.NEAT(n_networks = 150,
  3. input_size = 2,
  4. output_size = 1,
  5. bias = True,
  6. c1 = 1.0, c2 = 1.0, c3 = 0.4,
  7. distance_threshold = 3.0,
  8. weight_mutation_rate = 0.8,
  9. node_mutation_rate = 0.03,
  10. connection_mutation_rate = 0.05,
  11. interspecies_mating_rate = 0.001,
  12. disable_rate = 0.75,
  13. stegnant_threshold = 15,
  14. input_activation = neat.steepened_sigmoid,
  15. hidden_activation = neat.steepened_sigmoid,
  16. output_activation = neat.steepened_sigmoid)
  17. truth_table = [[0, 1],[1, 0]]
  18. solution_found = False
  19. while True:
  20. print(f'Generation: {xor.generation}')
  21. rewards = []
  22. for genome in xor.population:
  23. error = 0
  24. for input_1 in range(len(truth_table)):
  25. for input_2 in range(len(truth_table[0])):
  26. output = int(round(genome([input_1, input_2])[0]))
  27. error += abs(truth_table[input_1][input_2] - output)
  28. fitness = (4 - error) ** 2
  29. rewards.append(fitness)
  30. if fitness == 16:
  31. solution_found = True
  32. break
  33. if solution_found:
  34. break
  35. xor.next_generation(rewards)
  36. import matplotlib.pyplot as plt
  37. genome.draw()
  38. plt.show()

References

  • Kenneth O. Stanley, , and Risto Miikkulainen. “Evolving Neural Networks Through Augmenting Topologies”.Evolutionary Computation 10, no.2 (2002): 99-127.