Skip to content

Commit 002f77f

Browse files
committed
Add wraps decorator to preserve the functions' signatures
Adjust docu
1 parent 625645d commit 002f77f

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ All notable changes to the "swarmlib" pypi package will be documented in this fi
33
This project follows [semantic versioning](https://semver.org/).
44

55
## Unreleased
6+
* **Added** [landscapes](https://github.com/nathanrooy/landscapes#readme) as a dependency to enable more benchmark functions ([#15](https://github.com/HaaLeo/swarmlib/issues/15)). Contributed by Alex F ([@alxfmpl](https://github.com/alxfmpl)). Thanks a lot 🚀.
67

78
## 2020-07-21 - v0.9.0
8-
* Added _grey wolf optimizer_ ([#12](https://github.com/HaaLeo/swarmlib/issues/12)). Perform the grey wolf optimization algorithm on one of the selected 2D-functions. Contributed by Nimish Verma ([@NimishVerma](https://github.com/NimishVerma)) and greatly appreciated 🚀.
9+
* **Added** _grey wolf optimizer_ ([#12](https://github.com/HaaLeo/swarmlib/issues/12)). Perform the grey wolf optimization algorithm on one of the selected 2D-functions. Contributed by Nimish Verma ([@NimishVerma](https://github.com/NimishVerma)) and greatly appreciated 🚀.
910

1011
## 2020-04-13 - v0.8.1
1112
* **Fixed** a bug that caused the ACO algorithm to fail. Due to other third party packages swarmlib now requires `matplotlib<3.2.0`.

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The following is a set of guidelines for contributing to the [`swarmlib`](https:
99
* [Reporting Bugs](#reporting-bugs)
1010
* [Suggesting Enhancements](#suggesting-enhancements)
1111
* [Code Contribution](#code-contribution)
12+
* [Functions](#functions)
1213
* [Pull Requests](#pull-requests)
1314

1415
## How Can I Contribute?
@@ -88,6 +89,12 @@ swarmlib
8889

8990
To get started, I recommend you to take a look at the implementation of the CS, PSO, ABC algorithms.
9091

92+
### Functions
93+
94+
As of release _v0.10.0_ swarmlib uses the functions supplied by [landscapes](https://github.com/nathanrooy/landscapes#readme).
95+
If you are missing a benchmark function please open an issue in the landscapes repository.
96+
Once the function is implemented there we are happy to update swarmlib's landscapes dependency.
97+
9198
### Pull Requests
9299

93100
Please follow these steps to have your contribution considered:

README.md

+15-24
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ The implementation was part of the course [Natural computing for learning and op
6464

6565
#### Features
6666

67-
Enables to apply the firefly algorithm to one of the provided 2D functions. The algorithm tries to find the global minimum of the selected function.
68-
69-
Currently two functions can be selected:
70-
* [ackley](https://www.sfu.ca/~ssurjano/ackley.html)
71-
* [michalewicz](https://www.sfu.ca/~ssurjano/michal.html)
67+
Enables to apply the firefly algorithm to a 2D function.
68+
The algorithm tries to find the global minimum of the selected function.
69+
Any of [landscapes'](https://github.com/nathanrooy/landscapes#readme) 2D or nD functions can be selected.
7270

7371
![firefly algorithm](https://raw.githubusercontent.com/HaaLeo/swarmlib/master/doc/fireflies.gif)
7472

@@ -96,11 +94,9 @@ This repository also implements the _cuckoo search_ that was introduced by Xin-S
9694

9795
#### Features
9896

99-
Enables to apply cuckoo search to one of the provided 2D functions. The algorithm tries to find the global minimum of the selected function.
100-
101-
Currently two functions can be selected:
102-
* [ackley](https://www.sfu.ca/~ssurjano/ackley.html)
103-
* [michalewicz](https://www.sfu.ca/~ssurjano/michal.html)
97+
Enables to apply cuckoo search to one of the provided 2D functions.
98+
The algorithm tries to find the global minimum of the selected function.
99+
Any of [landscapes'](https://github.com/nathanrooy/landscapes#readme) 2D or nD functions can be selected.
104100

105101
![cukoo search](https://raw.githubusercontent.com/HaaLeo/swarmlib/master/doc/cuckoos.gif)
106102

@@ -129,11 +125,9 @@ This repository also implements modified _particle swarm optimization_ that was
129125

130126
#### Features
131127

132-
Enables particle swarm optimization to one of the provided 2D functions. The algorithm tries to find the global minimum of the selected function.
133-
134-
Currently two functions can be selected:
135-
* [ackley](https://www.sfu.ca/~ssurjano/ackley.html)
136-
* [michalewicz](https://www.sfu.ca/~ssurjano/michal.html)
128+
Enables particle swarm optimization to one of the provided 2D functions.
129+
The algorithm tries to find the global minimum of the selected function.
130+
Any of [landscapes'](https://github.com/nathanrooy/landscapes#readme) 2D or nD functions can be selected.
137131

138132
![particle swarm optimization](https://raw.githubusercontent.com/HaaLeo/swarmlib/master/doc/particles.gif)
139133

@@ -198,11 +192,10 @@ Research has shown that the flight behavior of birds, fruit flies and other inse
198192

199193
#### Features
200194

201-
Enables the ABC algorithm to one of the provided 2D functions. The algorithm tries to find the global minimum of the selected function.
195+
Enables the ABC algorithm to one of the provided 2D functions.
196+
The algorithm tries to find the global minimum of the selected function.
197+
Any of [landscapes'](https://github.com/nathanrooy/landscapes#readme) 2D or nD functions can be selected.
202198

203-
Currently two functions can be selected:
204-
* [ackley](https://www.sfu.ca/~ssurjano/ackley.html)
205-
* [michalewicz](https://www.sfu.ca/~ssurjano/michal.html)
206199

207200
![ABC Sample](https://raw.githubusercontent.com/HaaLeo/swarmlib/master/doc/bees.gif)
208201

@@ -234,11 +227,9 @@ The paper proposed a novel algorithm based on the hunting and the hierarchy stru
234227

235228
#### Features
236229

237-
Enables the GWO algorithm to one of the provided 2D functions. The algorithm tries to find the global minimum of the selected function.
238-
239-
Currently two functions can be selected:
240-
* [ackley](https://www.sfu.ca/~ssurjano/ackley.html)
241-
* [michalewicz](https://www.sfu.ca/~ssurjano/michal.html)
230+
Enables the GWO algorithm to one of the provided 2D functions.
231+
The algorithm tries to find the global minimum of the selected function.
232+
Any of [landscapes'](https://github.com/nathanrooy/landscapes#readme) 2D or nD functions can be selected.
242233

243234
![GWO Sample](https://raw.githubusercontent.com/HaaLeo/swarmlib/master/doc/gwo.gif)
244235

swarmlib/util/functions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#pylint: disable=invalid-name
77

88
import inspect
9+
from functools import wraps
910

1011
import landscapes.single_objective
1112
import numpy as np
1213

1314

1415
# Wrapper for landscapes.single_objective functions for inputs > 1d
1516
def wrap_landscapes_func(landscapes_func):
17+
@wraps(landscapes_func)
1618
def wrapper(x):
1719
return np.apply_along_axis(func1d=landscapes_func, axis=0, arr=x)
1820
return wrapper
@@ -24,5 +26,5 @@ def wrapper(x):
2426
for (name, func) in inspect.getmembers(
2527
landscapes.single_objective, inspect.isfunction
2628
)
27-
if name not in ['colville', 'wolfe'] # Don't include 3D and 4D functions
29+
if name not in ['colville', 'wolfe'] # Don't include 3D and 4D functions
2830
}

0 commit comments

Comments
 (0)