python - 遗传算法 - 继承问题
问题描述
我已经实现了一个遗传算法来拟合应该划分 2 组点的多项式。我生成了第一个随机人口,结果似乎符合预期,但是当我跨越人口时问题开始增长。我想我把交叉或“健身功能”搞砸了。在第一次运行中,程序找到了很好的解决方案,但每次迭代都变得最糟糕。
我用来检查多项式有多好的函数。
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
解决方案
推荐阅读
- websphere - WebSphere ND 8.5 配置文件
- mysql - 在 GROUP BY 之前 LEFT JOIN + ORDER BY
- asp.net-mvc - Asp.net core 2中的View和Page有什么区别?
- sqlite - 在本机 Android 应用程序中使用 MDM 的设备上的 Sqlite 数据库突然关闭
- javascript - 在处理表单时显示 gif 图像
- python - python win32com outlook,无法检索发件人信息。
- prestashop - Prestashop 产品列表不包括售罄
- php - 如何将字符串中的 ASCII 字符转换为普通字符?
- php - 在 Codeigniter 中创建一个匹配以某事开头的所有内容的路由
- python - Python Pandas 计算