jMetal / jMetalPy

A framework for single/multi-objective optimization with metaheuristics
https://jmetal.github.io/jMetalPy/index.html
MIT License
498 stars 150 forks source link

Problem when performing experiments with the same algorithm for tunning transformation operators #29

Closed moar82 closed 5 years ago

moar82 commented 5 years ago

In metaheuristics, it is necessary to tunning the parameters of an algorithm, when tackling new problems. In particular, I'm working with NSGA-II, and I'd like to tune the probability of executing transformation operators (CX for example).

Take as a example the following code:

from jmetal.algorithm import NSGAII
from jmetal.component.comparator import RankingAndCrowdingDistanceComparator
from jmetal.operator import NullMutation, SBX, BinaryTournamentSelection
from jmetal.problem import ZDT1, ZDT2
from jmetal.component.quality_indicator import HyperVolume
from jmetal.util.laboratory import experiment, display

algorithm = [
    (NSGAII, {'population_size': 100, 'max_evaluations': 25000, 'mutation': NullMutation(), 'crossover': SBX(1.0, 20),
              'selection': BinaryTournamentSelection(RankingAndCrowdingDistanceComparator())}),
    (NSGAII, {'population_size': 100, 'max_evaluations': 25000, 'mutation': NullMutation(), 'crossover': SBX(0.7, 20),
              'selection': BinaryTournamentSelection(RankingAndCrowdingDistanceComparator())})

]
metric = [HyperVolume(reference_point=[1, 1])]
problem = [(ZDT1, {}), (ZDT2, {})]

results = experiment(algorithm, metric, problem)
display(results)

Then I get the error below. The error in the debugger is exactly in the function def _sort_by_dimension(self, nodes, i): from the quality_indicator module.

I attached the snapshot of the variable decorated, one line before. For me it seems valid, but I do not understand why the exception?

snapshot

Connected to pydev debugger (build 182.3911.33)
2018-08-31 12:38:19,292 [MainThread  ] [DEBUG]  Problem is not instantiated by default
2018-08-31 12:38:19,292 [MainThread  ] [DEBUG]  Algorithm jmetal.algorithm.multiobjective.nsgaii.NSGAII is not instantiated by default
2018-08-31 12:38:19,293 [MainThread  ] [INFO ]  Running experiment: problem <jmetal.problem.multiobjective.zdt.ZDT1 object at 0x7fbcc1b676d8>, algorithm jmetal.algorithm.multiobjective.nsgaii.NSGAII
2018-08-31 12:39:52,314 [MainThread  ] [DEBUG]  Algorithm jmetal.algorithm.multiobjective.nsgaii.NSGAII is not instantiated by default
2018-08-31 12:39:52,317 [MainThread  ] [INFO ]  Running experiment: problem <jmetal.problem.multiobjective.zdt.ZDT1 object at 0x7fbcc1b676d8>, algorithm jmetal.algorithm.multiobjective.nsgaii.NSGAII
2018-08-31 12:41:20,350 [MainThread  ] [DEBUG]  Waiting
2018-08-31 12:41:20,351 [MainThread  ] [DEBUG]  Problem is not instantiated by default
2018-08-31 12:41:20,351 [MainThread  ] [INFO ]  Running experiment: problem <jmetal.problem.multiobjective.zdt.ZDT2 object at 0x7fbce01e46d8>, algorithm <NSGAII(Thread-6, initial)>
2018-08-31 12:42:45,406 [MainThread  ] [INFO ]  Running experiment: problem <jmetal.problem.multiobjective.zdt.ZDT2 object at 0x7fbce01e46d8>, algorithm <NSGAII(Thread-8, initial)>
2018-08-31 12:44:12,156 [MainThread  ] [DEBUG]  Waiting
Backend TkAgg is interactive backend. Turning interactive mode on.
Traceback (most recent call last):
  File "/home/moar82/Apps/pycharm-community-2018.2.1/helpers/pydev/pydevd.py", line 1664, in <module>
    main()
  File "/home/moar82/Apps/pycharm-community-2018.2.1/helpers/pydev/pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/moar82/Apps/pycharm-community-2018.2.1/helpers/pydev/pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/moar82/Apps/pycharm-community-2018.2.1/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/moar82/jMetalPy/examples/experiment/NSGAII-SMPSO for ZDT1.py", line 19, in <module>
    results = experiment(algorithm, metric, problem)
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/util/laboratory.py", line 55, in experiment
    result[algorithm.get_name()].setdefault('metric', dict()).update({metric.get_name(): metric.compute(front)})
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/component/quality_indicator.py", line 75, in compute
    self._pre_process(relevant_points)
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/component/quality_indicator.py", line 165, in _pre_process
    self._sort_by_dimension(nodes, i)
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/component/quality_indicator.py", line 174, in _sort_by_dimension
    decorated.sort()
TypeError: '<' not supported between instances of 'Node' and 'Node'

Process finished with exit code 1

Thanks for the support!

benhid commented 5 years ago

Hello @moar82! Fixed in 83c3968. This was an issue with the algorithm used to compute the hypervolume, that seems to be sorting the list of nodes using the wrong key. Now should be working as intended.