[英]Python NEAT not learning further after a certain point
似乎我的程序正在嘗試學習直到某個點,然后它就感到滿意並且根本停止改進和改變。 在我的測試中,它通常最多達到 -5 的值,然后無論我讓它運行多久,它都會保持在那里。 結果集也不會改變。
只是為了跟蹤它,我做了我自己的日志記錄,看看哪個做得最好。 1 和 0 的數組指的是 AI 做出正確選擇的頻率 (1),以及 AI 做出錯誤選擇的頻率 (0)。
我的目標是讓 AI 重復高於 0.5 然后低於 0.5 的模式,不一定要找到奇數。 這只是一個小小的測試,看看我是否可以讓 AI 使用一些基本數據正常工作,然后再做一些更高級的事情。
但不幸的是它不起作用,我不確定為什么。
編碼:
import os
import neat
def main(genomes, config):
networks = []
ge = []
choices = []
for _, genome in genomes:
network = neat.nn.FeedForwardNetwork.create(genome, config)
networks.append(network)
genome.fitness = 0
ge.append(genome)
choices.append([])
for x in range(25):
for i, genome in enumerate(ge):
output = networks[i].activate([x])
# print(str(x) + " - " + str(i) + " chose " + str(output[0]))
if output[0] > 0.5:
if x % 2 == 0:
ge[i].fitness += 1
choices[i].append(1)
else:
ge[i].fitness -= 5
choices[i].append(0)
else:
if not x % 2 == 0:
ge[i].fitness += 1
choices[i].append(1)
else:
ge[i].fitness -= 5
choices[i].append(0)
pass
# Optional death function, if I use this there are no winners at any point.
# if ge[i].fitness <= 20:
# ge[i].fitness -= 100
# ge.pop(i)
# choices.pop(i)
# networks.pop(i)
if len(ge) > 0:
fittest = -1
fitness = -999999
for i, genome in enumerate(ge):
if ge[i].fitness > fitness:
fittest = i
fitness = ge[i].fitness
print("Best: " + str(fittest) + " with fitness " + str(fitness))
print(str(choices[fittest]))
else:
print("Done with no best.")
def run(config_path):
config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet,
neat.DefaultStagnation, config_path)
pop = neat.Population(config)
#pop.add_reporter(neat.StdOutReporter(True))
#stats = neat.StatisticsReporter()
#pop.add_reporter(stats)
winner = pop.run(main, 100)
if __name__ == "__main__":
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, "config-feedforward.txt")
run(config_path)
整潔的配置:
[NEAT]
fitness_criterion = max
fitness_threshold = 100000
pop_size = 5000
reset_on_extinction = False
[DefaultGenome]
# node activation options
activation_default = tanh
activation_mutate_rate = 0.0
activation_options = tanh
# node aggregation options
aggregation_default = sum
aggregation_mutate_rate = 0.0
aggregation_options = sum
# node bias options
bias_init_mean = 0.0
bias_init_stdev = 1.0
bias_max_value = 30.0
bias_min_value = -30.0
bias_mutate_power = 0.5
bias_mutate_rate = 0.7
bias_replace_rate = 0.1
# genome compatibility options
compatibility_disjoint_coefficient = 1.0
compatibility_weight_coefficient = 0.5
# connection add/remove rates
conn_add_prob = 0.5
conn_delete_prob = 0.5
# connection enable options
enabled_default = True
enabled_mutate_rate = 0.1
feed_forward = True
initial_connection = full
# node add/remove rates
node_add_prob = 0.2
node_delete_prob = 0.2
# network parameters
num_hidden = 0
num_inputs = 1
num_outputs = 1
# node response options
response_init_mean = 1.0
response_init_stdev = 0.0
response_max_value = 30.0
response_min_value = -30.0
response_mutate_power = 0.0
response_mutate_rate = 0.0
response_replace_rate = 0.0
# connection weight options
weight_init_mean = 0.0
weight_init_stdev = 1.0
weight_max_value = 30
weight_min_value = -30
weight_mutate_power = 0.5
weight_mutate_rate = 0.8
weight_replace_rate = 0.1
[DefaultSpeciesSet]
compatibility_threshold = 3.0
[DefaultStagnation]
species_fitness_func = max
max_stagnation = 20
species_elitism = 2
[DefaultReproduction]
elitism = 2
survival_threshold = 0.2
很抱歉地告訴您,這種方法行不通。 請記住,神經網絡通常是通過進行矩陣乘法然后將最大值設為 0 來構建的(這稱為 RELU),因此在每一層上基本上是線性的並帶有一個截止值(不,選擇像 sigmoid 這樣的不同激活不會有幫助) . 您希望網絡產生 >.5、<.5、>.5、<.5、... 25 次。 想象一下用 RELU 組件構建它需要什么。 你至少需要一個大約 25 層深的網絡,如果沒有持續的漸進式發展,NEAT 不會產生這么大的網絡。 不過你們相處的很好,你們所做的就相當於學習了多年研究的模算子。 這是一篇成功的帖子,盡管沒有使用 NEAT。 Keras:制作一個神經網絡來找到一個數字的模數
你可以用 NEAT 取得的唯一真正進步是給網絡更多的特征作為輸入,例如給它x%2
作為輸入,它會很快學習,盡管這顯然是“作弊”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.