Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge case error when n_obj=1 in AGE-MOEA2 #619

Closed
muazhari opened this issue Jul 17, 2024 · 4 comments
Closed

Edge case error when n_obj=1 in AGE-MOEA2 #619

muazhari opened this issue Jul 17, 2024 · 4 comments

Comments

@muazhari
Copy link
Contributor

Reproducible codes:

import ray
from pymoo.util.ref_dirs import get_reference_directions, LayerwiseRieszEnergyReferenceDirectionFactory
from pymoo.algorithms.moo.ctaea import CTAEA
from pymoo.algorithms.moo.age2 import AGEMOEA2
from pymoo.core.variable import Binary, Choice, Integer, Real
from pymoo.core.problem import LoopedElementwiseEvaluation, RayParallelization
from pymoo.algorithms.moo.nsga2 import RankAndCrowding, NSGA2, RankAndCrowdingSurvival
from pymoo.core.mixed import MixedVariableGA, MixedVariableMating, MixedVariableDuplicateElimination, \
    MixedVariableSampling
from pymoo.optimize import minimize

from pymoo.core.problem import ElementwiseProblem




class MultiObjectiveMixedVariableProblem(ElementwiseProblem):

    def __init__(self, **kwargs):
        vars = {
            "z": Real(bounds=(-5 * 10 ** 3, 5 * 10 ** 3)),
        }
        super().__init__(vars=vars, n_obj=1, **kwargs)

    def _evaluate(self, X, out, *args, **kwargs):
        z = X["z"]

        f1 = z ** 2
        out["F"] = [f1]


runner = LoopedElementwiseEvaluation()
problem = MultiObjectiveMixedVariableProblem(elementwise_runner=runner)
algorithm = AGEMOEA2(
    sampling=MixedVariableSampling(),
    mating=MixedVariableMating(eliminate_duplicates=MixedVariableDuplicateElimination()),
    eliminate_duplicates=MixedVariableDuplicateElimination(),
)

res = minimize(
    problem,
    algorithm,
    verbose=True,
    seed=1
)

Error logs:

/home/muazhari/miniconda3/bin/conda run -p /home/muazhari/miniconda3 --no-capture-output python /mnt/c/Data/Apps/playground/seven_test.py 
/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/algorithms/moo/age2.py:85: RuntimeWarning: divide by zero encountered in log
  f = np.log(f)
Traceback (most recent call last):
  File "/mnt/c/Data/Apps/playground/seven_test.py", line 40, in <module>
    res = minimize(
          ^^^^^^^^^
  File "/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/optimize.py", line 67, in minimize
    res = algorithm.run()
          ^^^^^^^^^^^^^^^
  File "/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/core/algorithm.py", line 138, in run
    self.next()
  File "/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/core/algorithm.py", line 159, in next
    self.advance(infills=infills)
  File "/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/core/algorithm.py", line 214, in advance
    self._initialize_advance(infills=infills, **kwargs)
  File "/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/algorithms/base/genetic.py", line 80, in _initialize_advance
    self.pop = self.survival.do(self.problem, infills, n_survive=len(infills), algorithm=self, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/core/survival.py", line 55, in do
    survivors = self._do(problem, pop, *args, n_survive=n_survive, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/algorithms/moo/age.py", line 128, in _do
    crowd_dist[front_no == 0], p, normalization = self.survival_score(front1, ideal_point)
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/muazhari/miniconda3/lib/python3.11/site-packages/pymoo/algorithms/moo/age.py", line 170, in survival_score
    distances = self.pairwise_distances(front, p) / nn[:, None]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ZeroDivisionError: division by zero
ERROR conda.cli.main_run:execute(124): `conda run python /mnt/c/Data/Apps/playground/seven_test.py` failed. (See above for error)

Process finished with exit code 1
@blankjul
Copy link
Collaborator

any reason you want to apply this algorithm on a single-objective problem?

I have not implemented AGE-MOEA2 myself becaues it was a contribution by a researcher. It seems to fail because always only one individual is in a front (degenerated case when MOO applied to SOO)

@muazhari
Copy link
Contributor Author

any reason you want to apply this algorithm on a single-objective problem?

I have not implemented AGE-MOEA2 myself becaues it was a contribution by a researcher. It seems to fail because always only one individual is in a front (degenerated case when MOO applied to SOO)

Okay, if it can't.

@muazhari
Copy link
Contributor Author

There are other errors even though contextual to many objective problems in this #620.

@blankjul
Copy link
Collaborator

I have tagged the user who contributed the implementation in the other issue. I will close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants