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

__init__() missing 3 required positional arguments: 'D', 'nFES', and 'benchmark' #244

Closed
fakhrulfa opened this issue Dec 9, 2019 · 8 comments
Labels
question Further information is requested

Comments

@fakhrulfa
Copy link

Hi,

I tried your example of Flower Pollination Algorithm code, but i got an error like this :

     11 for i in range(5):
     12     task = StoppingTask(D=10, nFES=10000, benchmark=Sphere())
---> 13     algo = FlowerPollinationAlgorithm(NP=20, p=0.5)
     14     best = algo.run(task=algo)
     15     print(best)

TypeError: __init__() missing 3 required positional arguments: 'D', 'nFES', and 'benchmark'

Here's the code :

# 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

import random
from NiaPy.algorithms.basic import FlowerPollinationAlgorithm
from NiaPy.task import StoppingTask
from NiaPy.benchmarks import Sphere

#we will run Flower Pollination Algorithm for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10, nFES=10000, benchmark=Sphere())
    algo = FlowerPollinationAlgorithm(NP=20, p=0.5)
    best = algo.run(task=algo)
    print(best)

Hope you can help, thanks!

@GregaVrbancic
Copy link
Contributor

Hi @fakhrulfa,

which version of NiaPy are you using? If not already, please install the latest release candidate version pip install NiaPy==2.0.0rc10.

If you are still facing some issues with the latest RC version installed, please let us know.

@GregaVrbancic GregaVrbancic added the question Further information is requested label Dec 10, 2019
@fakhrulfa
Copy link
Author

fakhrulfa commented Dec 12, 2019

Thanks, its work!

but, when i tried to run this code. i got an output like this :

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

How to add the random number(import random) to the code, wheres the parameter that can contain the random number ?

@GregaVrbancic
Copy link
Contributor

Could you provide us with a code example, which you are trying to run?

@fakhrulfa
Copy link
Author

Heres the code, same as code that i used before.

import random
from NiaPy.algorithms.basic import FlowerPollinationAlgorithm
from NiaPy.task import StoppingTask
from NiaPy.benchmarks import Sphere

#we will run Flower Pollination Algorithm for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10, nFES=10000, benchmark=Sphere())
    algo = FlowerPollinationAlgorithm(NP=20, p=0.5)
    best = algo.run(task=algo)
    print(best)

@GregaVrbancic
Copy link
Contributor

You have a problem in line best = algo.run(task=algo), where it should be best = algo.run(task=task), like in the example https://github.com/NiaOrg/NiaPy/blob/master/examples/run_fpa.py .

@fakhrulfa
Copy link
Author

ow, okay, thanks. its works!

But, how can i find the best solution in case when i try to find best value for parameter in sklearn method. In this case, i try to find best value of C and Epsilon, in parameter of SVM in Sklearn.

Heres the code:

regressor = SVR(kernel='linear', C=value, gamma=0.1, epsilon=value)
regressor.fit(X_train, y_train)

Hope u can help, thanks again!

@GregaVrbancic
Copy link
Contributor

No problem. Regarding the parameter optimization of SVM, in general, you should implement your custom benchmark class which would map and evaluate the solution obtained from the optimization algorithm. For more information, you can check out the following blog post, where NiaPy is utilized for finding the most suitable parameters for KNN. Please, be aware that in the mentioned blog post the NiaPy version 1 is used, which is not compatible with version 2 (which you are using), so you can not copy-paste the code from the blog post to your project, but the general idea is the same.

@fakhrulfa
Copy link
Author

Okay, i will try to follow the idea of the code on your blog. Thanks!

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

No branches or pull requests

2 participants