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

OptimizationType.MAXIMIZATION does not work with GWO #246

Closed
timzatko opened this issue Apr 4, 2020 · 8 comments
Closed

OptimizationType.MAXIMIZATION does not work with GWO #246

timzatko opened this issue Apr 4, 2020 · 8 comments
Labels
bug Something isn't working
Milestone

Comments

@timzatko
Copy link

timzatko commented Apr 4, 2020

Hi!

OptimizationType.MAXIMIZATION does not work when used, I tried it with GWO but it seems to be buggy also with other algorithms.

Steps to reproduce

requirements.txt

NiaPy==2.0.0rc5

Code - taken from here, changed only the optimization type

# encoding=utf8
# This is temporary fix to import module from parent folder
# It will be removed when package is published on PyPI
import sys
sys.path.append('../')
# End of fix

from NiaPy.algorithms.basic import GreyWolfOptimizer
from NiaPy.task import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

# we will run Grey Wolf Optimizer for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10, nFES=10000, optType=OptimizationType.MAXIMIZATION, benchmark=Sphere())
    algo = GreyWolfOptimizer(NP=40)
    best = algo.run(task)
    print(best)

Expected behavior

It should not throw any error.

Actual behavior

TypeError                                 Traceback (most recent call last)
<ipython-input-11-bed1e1b95f2d> in <module>
     14     task = StoppingTask(D=10, nFES=10000, optType=OptimizationType.MAXIMIZATION, benchmark=Sphere())
     15     algo = GreyWolfOptimizer(NP=40)
---> 16     best = algo.run(task)
     17     print(best)

/opt/conda/lib/python3.7/site-packages/NiaPy/algorithms/algorithm.py in run(self, task)
    346         try:
    347             # task.start()
--> 348             r = self.runTask(task)
    349             return r[0], r[1] * task.optType.value
    350         except (FesException, GenException, TimeException, RefException):

/opt/conda/lib/python3.7/site-packages/NiaPy/algorithms/algorithm.py in runTask(self, task)
    326         algo, xb, fxb = self.runYield(task), None, inf
    327         while not task.stopCond():
--> 328             xb, fxb = next(algo)
    329             task.nextIter()
    330         return xb, fxb

/opt/conda/lib/python3.7/site-packages/NiaPy/algorithms/algorithm.py in runYield(self, task)
    306         yield xb, fxb
    307         while True:
--> 308             pop, fpop, dparams = self.runIteration(task, pop, fpop, xb, fxb, **dparams)
    309             xb, fxb = self.getBest(pop, fpop, xb, fxb)
    310             yield xb, fxb

/opt/conda/lib/python3.7/site-packages/NiaPy/algorithms/basic/gwo.py in runIteration(self, task, pop, fpop, xb, fxb, A, A_f, B, B_f, D, D_f, **dparams)
    109                 for i, w in enumerate(pop):
    110                         A1, C1 = 2 * a * self.rand(task.D) - a, 2 * self.rand(task.D)
--> 111                         X1 = A - A1 * fabs(C1 * A - w)
    112                         A2, C2 = 2 * a * self.rand(task.D) - a, 2 * self.rand(task.D)
    113                         X2 = B - A2 * fabs(C2 * B - w)

TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'

System configuration

Using docker jupyter/scipy-notebook.

@GregaVrbancic
Copy link
Contributor

Hi @timzatko!

Thank you for reporting the issue. Based on the provided information I would suggest you upgrade the NiaPy to version 2.0.0rc10.

Please report back if you still facing the problem with the 2.0.0rc10 version.

@timzatko
Copy link
Author

timzatko commented Apr 5, 2020

In 2.0.0rc10 the output for the same code is:

(None, None)
(None, None)
(None, None)
(None, None)
(None, None)

@timzatko
Copy link
Author

timzatko commented Apr 5, 2020

Btw, then the README is incorrect as it states that the latest version is 2.0.0rc5.

@GregaVrbancic GregaVrbancic added bug Something isn't working and removed answered labels Apr 5, 2020
@GregaVrbancic
Copy link
Contributor

Thanks for the feedback, we will update the README. Regarding the issue, could you @kb2623 take a look at this?

@GregaVrbancic GregaVrbancic added this to the 2.0 milestone Apr 5, 2020
@kb2623
Copy link
Contributor

kb2623 commented Apr 6, 2020

Hi to all, found the problem and solved it.

@GregaVrbancic
Copy link
Contributor

Thank you @kb2623!

@timzatko feel free to try out a fixed version of NiaPy installing from git using the pip install git+https://github.com/NiaOrg/NiaPy.git command.

@GregaVrbancic
Copy link
Contributor

@all-contributors add @timzatko for a bug report

@allcontributors
Copy link
Contributor

@GregaVrbancic

I've put up a pull request to add @timzatko! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants