Я реализовал генетический алгоритм для подгонки полинома, который должен делить 2 набора точек. Я генерирую первое случайное население, и результаты кажутся желаемыми, но проблема начинает расти, когда я пересекаю население. Я думаю, что перепутал что-то с кроссоверами или с «функцией фитнеса». При первом запуске программа находит хорошие решения, но на каждой итерации она становится хуже.
Пример 1 итерации:
![enter image description here](https://i.stack.imgur.com/JSSQx.png)
Пример последней итерации:
![enter image description here](https://i.stack.imgur.com/spQnw.png)
Функция, которую я использую, чтобы проверить, насколько хорош полином.
def evaluation_mutation(points, population, degree):
temp = convert_to_dec(population, degree)
result = []
counter = []
counter2 = []
for inx2 in range(len(temp)):
counter.append([])
counter2.append([])
for i in range(len(points[0])):
if (np.polyval(temp[inx2], points[0][i, 0]) < points[0][i, 0]) and points[1][i]:
if not counter[inx2]:
counter[inx2] = 1
else:
counter[inx2] = counter[inx2] + 1
elif (np.polyval(temp[inx2], points[0][i, 0]) > points[0][i, 0]) and not points[1][i]:
if not counter2[inx2]:
counter2[inx2] = 1
else:
counter2[inx2] = counter2[inx2] + 1
if counter2[inx2] and counter[inx2]:
result.append([counter[inx2], counter2[inx2]])
else:
result.append([])
return result
Полный код: https://pastebin.com/u5rr62QV