-
Notifications
You must be signed in to change notification settings - Fork 80
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
CuckooSearch's runIteration is incompatible with other algorithms runIteration #281
Comments
To expand this issue: many NIA optimizers were changed in the latest version to extend the standard required arguments when calling runIteration. Earlier versions forced all the NIA parameter settings at the construction, not in the runIteration call... This change makes NiaPy unusable in other frameworks, where generic runIteration calls are made... |
Have a good day @karakatic . Would you recommend to move out these parameters to constructor function instead of being at the |
This parameter should not be and issue, because in NiaPy/NiaPy/algorithms/algorithm.py Line 296 in a135cc0
Method Many advanced IDEs report this as an issue, as for some other incompatible type problems, but Python code still runs. Parameter NiaPy/NiaPy/algorithms/basic/cs.py Line 132 in a135cc0
If this parameter is set when constructing an instance of CuckooSearch class, then the code for updating parameters (method setParametes ) should be updated. But this parameter is not a default parameter of Cuckoo Search algorithm, based on article Yang, Xin-She, and Suash Deb. "Cuckoo search via Lévy flights." Nature & Biologically Inspired Computing, 2009. NaBIC 2009. World Congress on. IEEE, 2009 , so I did not set this parameter at creation of Cuckoo Search algorithm instance.
|
IDEs report this as a problem because it seemingly goes against the Liskov substitution principle of object oriented programming. But it actually doesn't because of keyword arguments. Also, runIteration is essentially a private/protected method, I see no use case where you would need to call runIteration directly in your code. In this particular case though, I don't think pa_v should be an additional parameter, because it stays the same through all iterations. It should just be set in the constructor/setParameters method. If it's optional there should be a flag in setParameters, something like @karakatic Can you provide an example of this causing problems? If it's an issue we would just need to change every algorithms NiaPy/NiaPy/algorithms/basic/bfoa.py Lines 193 to 214 in 0fa51cb
We could also just do this to remove the warnings. |
As I described in my previous comment, for the algorithms that had extra arguments in the run_iteration method, I removed them and popped them from the keyword arguments inside run_iteration. In the case of CS, the pa_v parameter was actually static, it represents the number of nests abandoned each iteration i. e. pa * population_size, where pa is the probability of a nest being abandoned. So I just added an attribute self.num_abandoned in init which stores that value so no additional parameters are actually needed. |
CuckooSearch's runIteration is incompatible with other algorithms' runIteration. It is because of the required argument pa_v. This makes it impossible to use it in the experiments with generic method calls.
NiaPy/NiaPy/algorithms/basic/cs.py
Line 135 in a135cc0
The text was updated successfully, but these errors were encountered: