Skip to content

Commit 582aede

Browse files
committed
minor fixes
1 parent 89f0290 commit 582aede

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

fireflyalgorithm/problems.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def griewank(x):
5555
def katsuura(x):
5656
dim = len(x)
5757
k = np.atleast_2d(np.arange(1, 33)).T
58-
i = np.arange(0, dim * 1)
58+
i = np.arange(1, dim + 1)
5959
inner = np.round(2**k * x) * (2.0 ** (-k))
60-
return np.prod(np.sum(inner, axis=0) * (i + 1) + 1)
60+
return np.prod(np.sum(inner, axis=0) * i + 1)
6161

6262

6363
def levy(x):
@@ -158,7 +158,7 @@ def schaffer2(x):
158158
def schaffer4(x):
159159
return (
160160
0.5
161-
+ (np.cos(np.sin(x[0] ** 2 - x[1] ** 2)) ** 2 - 0.5)
161+
+ (np.cos(np.sin(abs(x[0] ** 2 - x[1] ** 2))) ** 2 - 0.5)
162162
/ (1 + 0.001 * (x[0] ** 2 + x[1] ** 2)) ** 2
163163
)
164164

@@ -170,11 +170,11 @@ def schwefel(x):
170170
)
171171

172172

173-
def schwefel21(x):
173+
def schwefel221(x):
174174
return np.amax(np.abs(x))
175175

176176

177-
def schwefel22(x):
177+
def schwefel222(x):
178178
return np.sum(np.abs(x)) + np.prod(np.abs(x))
179179

180180

@@ -253,8 +253,8 @@ def zakharov(x):
253253
"schaffer2": schaffer2,
254254
"schaffer4": schaffer4,
255255
"schwefel": schwefel,
256-
"schwefel21": schwefel21,
257-
"schwefel22": schwefel22,
256+
"schwefel221": schwefel221,
257+
"schwefel222": schwefel222,
258258
"sphere": sphere,
259259
"step": step,
260260
"step2": step2,

tests/test_problems.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
schaffer2,
2626
schaffer4,
2727
schwefel,
28-
schwefel21,
29-
schwefel22,
28+
schwefel221,
29+
schwefel222,
3030
sphere,
3131
step,
3232
step2,
@@ -64,8 +64,8 @@ def test_problem_factory(self):
6464
self.assertEqual(get_problem("schaffer2"), schaffer2)
6565
self.assertEqual(get_problem("schaffer4"), schaffer4)
6666
self.assertEqual(get_problem("schwefel"), schwefel)
67-
self.assertEqual(get_problem("schwefel21"), schwefel21)
68-
self.assertEqual(get_problem("schwefel22"), schwefel22)
67+
self.assertEqual(get_problem("schwefel221"), schwefel221)
68+
self.assertEqual(get_problem("schwefel222"), schwefel222)
6969
self.assertEqual(get_problem("sphere"), sphere)
7070
self.assertEqual(get_problem("step"), step)
7171
self.assertEqual(get_problem("step2"), step2)
@@ -175,11 +175,11 @@ def test_schwefel(self):
175175

176176
def test_schwefel21(self):
177177
x = np.zeros(5)
178-
self.assertAlmostEqual(schwefel21(x), 0.0)
178+
self.assertAlmostEqual(schwefel221(x), 0.0)
179179

180180
def test_schwefel22(self):
181181
x = np.zeros(5)
182-
self.assertAlmostEqual(schwefel22(x), 0.0)
182+
self.assertAlmostEqual(schwefel222(x), 0.0)
183183

184184
def test_sphere(self):
185185
x = np.zeros(5)
@@ -190,8 +190,8 @@ def test_step(self):
190190
self.assertAlmostEqual(step(x), 0.0)
191191

192192
def test_step2(self):
193-
x = np.full(5, 0.5)
194-
self.assertAlmostEqual(step(x), 0.0)
193+
x = np.full(5, -0.5)
194+
self.assertAlmostEqual(step2(x), 0.0)
195195

196196
def test_styblinski_tang(self):
197197
x = np.full(5, -2.903534018185960)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy