Skip to content

Commit db8f13b

Browse files
committed
Fixed ackley function
1 parent 505a8b9 commit db8f13b

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ 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

6+
## 2020-01-09 - v0.3.2
7+
* **Fixed** a bug in the firefly algorithm that caused the application to crash when the ackley function was selected.
8+
69
## 2019-10-30 - v0.3.1
710
* **Fixed** a bug in the ACO algorithm that chose the next node by its maximal attractiveness. Now the next node is chosen randomly weighted by its attractiveness
811

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The implementation was part of the course [Natural computing for learning and op
3434

3535
### Features
3636

37-
Enables to apply the ant colony optimization algorithm to a TSP using a [TSPLIB95](https://www.iwr.uni-heidelberg.de/groups/comopt/software/TSPLIB95/index.html) file and plots the result.
37+
Enables to apply the ant colony optimization algorithm to a TSP using a [TSPLIB95](http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/) file and plots the result.
3838

3939
![ACO Sample](https://raw.githubusercontent.com/HaaLeo/swarmlib/master/doc/ACO_Sample.png)
4040

swarmlib/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# Licensed under the BSD 3-Clause License. See LICENSE.txt in the project root for license information.
44
# ------------------------------------------------------------------------------------------------------
55

6-
__version__ = '0.3.1'
6+
__version__ = '0.3.2'

swarmlib/fireflyalgorithm/functions.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ def func(x):
1919
return -result
2020

2121

22-
def ackley(x):
23-
a = 20
24-
b = 0.2
25-
c = 2 * np.pi
22+
def ackley(x, a=20, b=0.2, c=2*np.pi):
2623

27-
first_sum = reduce(lambda acc, x: acc + np.power(x, 2), x, 0.)
28-
second_sum = reduce(lambda acc, x: np.cos(c * x), x, 0.)
29-
30-
return -a * np.exp(-b * np.sqrt(1/x.size * first_sum)-np.exp(1/x.size * second_sum)) + a + np.exp(1)
24+
x = np.asarray_chkfinite(x) # ValueError if any NaN or Inf
25+
n = len(x)
26+
s1 = np.sum(x**2, axis=0)
27+
s2 = np.sum(np.cos(c * x), axis=0)
28+
return -a*np.exp(-b*np.sqrt(s1 / n)) - np.exp(s2 / n) + a + np.exp(1)
3129

3230

3331
FUNCTIONS = {

0 commit comments

Comments
 (0)