LoginSignup
2
3

More than 3 years have passed since last update.

【NEAT】python3(anaconda3)を使ってNEATを実装してみた(5/5)

Last updated at Posted at 2020-02-16

前回は交配をして新たな子供の世代を作りました。この最終記事では、今までと同じ操作をwhileを用いて一気に操作します。

whileでループ

while 1:
    '''種に分ける'''
    species.speciate(population, generation)

    '''成績を計算'''
    FeedForwardNetwork.eval_genomes(list(population.items()))

    best = None
    for g in population.values():

        if best is None or g.fitness > best.fitness:
            best = g

    if best_genome is None or best.fitness > best_genome.fitness:
        best_genome = best

    fv = max(g.fitness for g in population.values())
    if fv >= fitness_threshold:
        print('\nBest individual in generation {0} meets fitness threshold - complexity: {1!r}'.format(generation, best.size()))
        break

    '''交配'''
    popus = DefaultReproduction()
    population = popus.reproduce( species, pop_size, generation)

    generation += 1

'''水準を超えた成績最優秀ネットワークの発表'''
winner=best_genome

print('\nBest genome:\n{!s}'.format(winner))

print('\nOutput:')
winner_net = FeedForwardNetwork.create(winner)
for xi, xo in zip(xor_inputs, xor_outputs):
    output = winner_net.activate(xi)
    print("  input {!r}, expected output {!r}, got {!r}".format(xi, xo, output))

スクリーンショット 2020-02-16 19.56.11.png

NodesとConnectionsの数が最初に比べてかなり大きくなりました。これを図にすると、次のようになります。
image (9).png

1,2,3のNodesは中間層として存在します。論文を見ると、中間層がないと出力の精度は良くならないらしいので、その点で中間層ができていることは納得がいきます。

以上でNEATの説明を終わります!

今回は比較的挑戦しやすいと考えている排他的論理和について触れましたが、さらにSingle-Pole-Balancingなども挑戦したいと考えています。

ここまで続いた全5回の記事はここで終了となります。少しでも読者様のお役に立てれば嬉しいです。ここでまで読んでくださった方がいれば本当にありがとうございます。

何か誤りやご指摘があれがぜひコメントください。よろしくお願いします。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3