CMA-ES / moarchiving

A bi-objective nondominated archive class
Other
2 stars 3 forks source link

AttributeError #1

Closed ttusar closed 4 years ago

ttusar commented 4 years ago

Hi :-)

Found this nice repository and wanted to use it, but encountered a problem. Here's the code to recreate it:

from moarchiving import BiobjectiveNondominatedSortedList as NDA
points = [[0, 5], [1, 4], [1.1, 3.9], [5, 0]]
ref = [6, 6]
archive = NDA(points)
archive.reference_point = ref
archive.hypervolume_improvement([2, 2])

The error:

  File "/Users/tea/anaconda3/envs/py37bbdemo/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-c0a71a8d2336>", line 6, in <module>
    archive.hypervolume_improvement([2, 2])
  File "/Users/tea/anaconda3/envs/py37bbdemo/lib/python3.7/site-packages/moarchiving/moarchiving.py", line 596, in hypervolume_improvement
    state = self._state()
  File "/Users/tea/anaconda3/envs/py37bbdemo/lib/python3.7/site-packages/moarchiving/moarchiving.py", line 819, in _state
    return len(self), self.discarded, self.hypervolume, self.reference_point
  File "/Users/tea/anaconda3/envs/py37bbdemo/lib/python3.7/site-packages/moarchiving/moarchiving.py", line 448, in hypervolume
    return self._hypervolume
AttributeError: 'BiobjectiveNondominatedSortedList' object has no attribute '_hypervolume'
nikohansen commented 4 years ago

The user interface is slightly cryptic, but setting the reference point a posteriori is not supported (because assigning the reference point possibly means the state of the archive must change).

from moarchiving import BiobjectiveNondominatedSortedList as NDA
points = [[0, 5], [1, 4], [1.1, 3.9], [5, 0]]
ref = [6, 6]
archive = NDA(points, ref)
# archive.reference_point = ref
archive.hypervolume_improvement([2, 2])

works for me.

ttusar commented 4 years ago

It works! Thanks a lot for the quick reply.