python - HyperVolume 函数在 Python 3 中不起作用

标签 python deap

基于发现的 HyperVolume 函数 here (直接下载 link ),我试图返回我的算法的超体积指标。但是,即使测试代码也不起作用:

from hv import HyperVolume
referencePoint = [2, 2, 2]
hyperVolume = HyperVolume(referencePoint)
front = [[1, 0, 1], [0, 1, 0]]
result = hyperVolume.compute(front)

我收到的错误似乎与我使用 Python 3 而该函数本身使用 Python 2 有关。有没有办法解决这个问题? Python 3 中是否有类似的功能实现?

我还查看了 this one in deap ,但似乎有同样的问题。

LE:有人要求我提供具体错误,因此我会在解决这些错误时保留这些错误的日志

  1. 名称 xrange 未定义 - 通过替换为范围来修复
  2. TypeError: unorderable types: Node() < Node()

最佳答案

使用2to3将hv.py转换为hv3.py:

$ 2to3 hv.py > hv3.py.patch
$ cp hv.py hv3.py
$ patch < hv3.py.patch

然后将导入行更改为

from hv3 import HyperVolume

如果想要2to3改变修改原文件,需要传递-w选项,如documentation所示

$ 2to3 -w hv.py

关于python - HyperVolume 函数在 Python 3 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38057598/

相关文章:

python - 是否可以让算法.eaSimple 返回包含运行时所有统计数据的日志?

python - 使用 Python 3 的 FTP 文本文件为空

python - 如何快速索引 NetCDF 文件

python - 在启动时启动 python 脚本 - Raspbian

python - Conda 和 Anaconda 有什么区别?

python - 为什么pip无法安装最新版本的deap?

python - Pylint 不喜欢 string.format() 并且希望我使用 f-strings。这可以修复吗?

python - “numpy.ndarray”对象没有属性 'fitness'

python - 在 DEAP 中实现适用于 pandas DataFrame 的 GP