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

Benchmark refactor #321

Merged
merged 14 commits into from
May 30, 2021
Merged

Benchmark refactor #321

merged 14 commits into from
May 30, 2021

Conversation

zStupan
Copy link
Contributor

@zStupan zStupan commented May 29, 2021

Summary

  • Renamed class Benchmark to Problem and niapy/benchmarks to niapy/problems. I feel like that makes more sense and is more general. Benchmark sounds like it's only for testing and might confuse a new user trying to implement their own optimization problem.
  • Made Problem an abstract class.
  • All problems now have a dimension attribute, and the lower and upper bounds are numpy arrays of size dimension, as opposed to floats. Because of this I also had to rewrite the local and global seeding methods of the Forrest Optimization Algorithm and change a dtype parameter to float in Firefly Algorithm which should've been done anyway.
  • The Task class constructor has been rewritten so that if the problem argument is a string, a new problem will be constructed from the dimension, lower and upper arguments, if they're provided (not None), otherwise the Problem's defaults will be used. If problem is an instance of the problem class, then that problem will be used and the dimension and bounds arguments will be ignored. The dimension, lower and upper attributes of the task are then set to those of self.problem.
  • Task.eval now calls Problem.evaluate(x).
  • Problem.evaluate checks if the dimension of the input solution x matches the problem dimension and raises a ValueError if it doesn't. If the dimensions match it returns the function value of x, which is calculated by the _evaluate method. I was thinking for the future, that this method could also take a whole population and evaluate it either sequentially or in parallel, in batches, but for now it only does the dimension check.
  • Problem._evaluate is an abstract method which should contain the actual objective function implementation.
  • All Problem implementations were rewritten to make use of numpy instead of for loops, which should make them faster. It's only a little less than a minute improvement on test performance on my machine. The only ones I didn't know how to write in numpy form were Katsuura and Weierstrass.
  • I've removed all the static Name variables from problems. Instead I've implemented a name method in the problem base class which just returns the instances class name. I'm planning to do this for the Algorithm class as well in a future pull request.
  • Updated the docs and examples to include these changes.
  • Fixed some docstrings.
  • Made the full_array method and its tests faster and easier to read.
  • Removed the plot methods from the Problem class. I'm intending to add a plot.py module to util in the future.
  • Fixed Tasks are missing from the documentation. #315. The API documentation now includes tasks. Also fixed duplicate target name warnings while building docs, by using anonymous urls (2 underscores) in docs/source/installation.rst

@GregaVrbancic
Copy link
Contributor

@firefly-cpp if you agree, I would recommend merging this PR.

@GregaVrbancic
Copy link
Contributor

@zStupan it seems like this scrutinizer configuration works https://github.com/NiaOrg/NiaPy/blob/Attempt-to-fix-scrutinizer/.scrutinizer.yml

Could you update the scrutinizer configuration to the working one, so we do not need to merge separate PR to master and again update this PR?

@firefly-cpp
Copy link
Contributor

@GregaVrbancic, please merge this PR. Sorry for late response - holidays for one day.

@GregaVrbancic GregaVrbancic merged commit 7884aef into NiaOrg:master May 30, 2021
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

Successfully merging this pull request may close these issues.

Tasks are missing from the documentation.
3 participants