DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.69k stars 1.11k forks source link

Hypervolume dimention limit #654

Open MrRezaei opened 2 years ago

MrRezaei commented 2 years ago

I recently finished implementing NSGA-III-Part-II. Then I was trying to calculate hypervolume for my pareto front but I couldn't make it work with hypervolume(., .). As you know the NSGA-III paper works better with multi-dimensional (>2) objective functions. So I had to calculate the hypervolume for a 3 dimensional problem but I couldn't get it working. The sample code included in the repo shows an example of hypervolume calculation:

pointset = [(a, a) for a in numpy.arange(1, 0, -0.01)] ref = numpy.array([2, 2]) print("Python version: %f" % hypervolume(pointset, ref))

And it works fine. But when I change the dimensionality of the objective space to 3 or more:

pointset = [(a, a, a) for a in np.arange(1, 0, -0.01)] ref = np.array([2, 2, 2]) print("Python version: %f" % hypervolume(pointset, ref))

I get the following error:

in: _HyperVolume.hvRecursive(self, dimIndex, length, bounds) 63 p = sentinel 64 q = p.prev[dimIndex] ---> 65 while q.cargo != None: 66 if q.ignore < dimIndex: 67 q.ignore = 0 ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Did I do anything wrong? Or maybe your implementation only works with 2 dimensional objectives? (Which in this case, It's silly to call it hyper-volume because it can be interpreted as a surface area in 2d space.) Please help me understand this. Thanks

aabmets commented 2 years ago

@MrRezaei As I have currently just finished the complete refactor of the DEAP library in my fork named "DEAP-er", I know exactly what causes this problem and how to fix it, but there is no point in creating a bugfix pull request to this DEAP library, because it has been abandoned by the maintainers.

If you wish to fix it yourself, then just replace != in line number 65 with the keywords is not.

MrRezaei commented 2 years ago

Thanks a lot. I didn't try your fix but I developed my own code to compute HyperVolume and HyperVolumeRatio in a more simple way and I intend to publish it later. (I might wait for the code of NSGA-III-part-II and publish the HV code alongside that.)