Skip to content

Commit 251a9e1

Browse files
jarcelaoljvmiranda921
authored andcommitted
Remove _func in single_obj function names (ljvmiranda921#222)
1 parent 918b46e commit 251a9e1

26 files changed

+152
-152
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ import pyswarms as ps
101101

102102
Suppose we want to find the minima of `f(x) = x^2` using global best
103103
PSO, simply import the built-in sphere function,
104-
`pyswarms.utils.functions.sphere_func()`, and the necessary optimizer:
104+
`pyswarms.utils.functions.sphere()`, and the necessary optimizer:
105105

106106
```python
107107
import pyswarms as ps
@@ -111,7 +111,7 @@ options = {'c1': 0.5, 'c2': 0.3, 'w':0.9}
111111
# Call instance of PSO
112112
optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options)
113113
# Perform optimization
114-
best_cost, best_pos = optimizer.optimize(fx.sphere_func, iters=100, verbose=3, print_step=25)
114+
best_cost, best_pos = optimizer.optimize(fx.sphere, iters=100, verbose=3, print_step=25)
115115
```
116116
```s
117117
>>> 2017-10-03 10:12:33,859 - pyswarms.single.global_best - INFO - Iteration 1/100, cost: 0.131244226714
@@ -170,7 +170,7 @@ options = {
170170
# n_selection_iters is the number of iterations to run the searcher
171171
# iters is the number of iterations to run the optimizer
172172
g = RandomSearch(ps.single.LocalBestPSO, n_particles=40,
173-
dimensions=20, options=options, objective_func=fx.sphere_func,
173+
dimensions=20, options=options, objective_func=fx.sphere,
174174
iters=10, n_selection_iters=100)
175175

176176
best_score, best_options = g.search()
@@ -202,7 +202,7 @@ from pyswarms.utils.plotters import plot_cost_history
202202
# Set-up optimizer
203203
options = {'c1':0.5, 'c2':0.3, 'w':0.9}
204204
optimizer = ps.single.GlobalBestPSO(n_particles=50, dimensions=2, options=options)
205-
optimizer.optimize(fx.sphere_func, iters=100)
205+
optimizer.optimize(fx.sphere, iters=100)
206206
# Plot the cost
207207
plot_cost_history(optimizer.cost_history)
208208
plt.show()
@@ -216,7 +216,7 @@ We can also plot the animation...
216216
from pyswarms.utils.plotters.formatters import Mesher
217217
from pyswarms.utils.plotters.formatters import Designer
218218
# Plot the sphere function's mesh for better plots
219-
m = Mesher(func=fx.sphere_func)
219+
m = Mesher(func=fx.sphere)
220220
# Adjust figure limits
221221
d = Designer(limits=[(-1,1), (-1,1), (-0.1,1)],
222222
label=['x-axis', 'y-axis', 'z-axis'])

docs/examples/basic_optimization.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ several variables at once.
7171
optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options)
7272
7373
# Perform optimization
74-
cost, pos = optimizer.optimize(fx.sphere_func, print_step=100, iters=1000, verbose=3)
74+
cost, pos = optimizer.optimize(fx.sphere, print_step=100, iters=1000, verbose=3)
7575
7676
7777
.. parsed-literal::
@@ -116,7 +116,7 @@ Now, let’s try this one using local-best PSO:
116116
optimizer = ps.single.LocalBestPSO(n_particles=10, dimensions=2, options=options)
117117
118118
# Perform optimization
119-
cost, pos = optimizer.optimize(fx.sphere_func, print_step=100, iters=1000, verbose=3)
119+
cost, pos = optimizer.optimize(fx.sphere, print_step=100, iters=1000, verbose=3)
120120
121121
122122
.. parsed-literal::
@@ -151,7 +151,7 @@ Another thing that we can do is to set some bounds into our solution, so
151151
as to contain our candidate solutions within a specific range. We can do
152152
this simply by passing a ``bounds`` parameter, of type ``tuple``, when
153153
creating an instance of our swarm. Let’s try this using the global-best
154-
PSO with the Rastrigin function (``rastrigin_func`` in
154+
PSO with the Rastrigin function (``rastrigin`` in
155155
``pyswarms.utils.functions.single_obj``).
156156

157157
Recall that the Rastrigin function is bounded within ``[-5.12, 5.12]``.
@@ -191,7 +191,7 @@ constant.
191191
optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)
192192
193193
# Perform optimization
194-
cost, pos = optimizer.optimize(fx.rastrigin_func, print_step=100, iters=1000, verbose=3)
194+
cost, pos = optimizer.optimize(fx.rastrigin, print_step=100, iters=1000, verbose=3)
195195
196196
197197
.. parsed-literal::

docs/examples/custom_optimization_loop.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ new attributes.
2929
import numpy as np
3030
3131
# Import sphere function as objective function
32-
from pyswarms.utils.functions.single_obj import sphere_func as f
32+
from pyswarms.utils.functions.single_obj import sphere as f
3333
3434
# Import backend modules
3535
import pyswarms.backend as P

docs/examples/visualization.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ the ``optimize()`` method for 100 iterations.
5050
5151
options = {'c1':0.5, 'c2':0.3, 'w':0.9}
5252
optimizer = ps.single.GlobalBestPSO(n_particles=50, dimensions=2, options=options)
53-
cost, pos = optimizer.optimize(fx.sphere_func, iters=100)
53+
cost, pos = optimizer.optimize(fx.sphere, iters=100)
5454
5555
5656
.. code-block::
@@ -112,7 +112,7 @@ with respect to our objective function. We can accomplish that using the
112112
from pyswarms.utils.plotters.formatters import Mesher
113113
114114
# Initialize mesher with sphere function
115-
m = Mesher(func=fx.sphere_func)
115+
m = Mesher(func=fx.sphere)
116116
117117
There are different formatters available in the
118118
``pyswarms.utils.plotters.formatters`` module to customize your plots

examples/basic_optimization.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options)\n",
122122
"\n",
123123
"# Perform optimization\n",
124-
"cost, pos = optimizer.optimize(fx.sphere_func, print_step=100, iters=1000, verbose=3)"
124+
"cost, pos = optimizer.optimize(fx.sphere, print_step=100, iters=1000, verbose=3)"
125125
]
126126
},
127127
{
@@ -184,15 +184,15 @@
184184
"optimizer = ps.single.LocalBestPSO(n_particles=10, dimensions=2, options=options)\n",
185185
"\n",
186186
"# Perform optimization\n",
187-
"cost, pos = optimizer.optimize(fx.sphere_func, print_step=100, iters=1000, verbose=3)"
187+
"cost, pos = optimizer.optimize(fx.sphere, print_step=100, iters=1000, verbose=3)"
188188
]
189189
},
190190
{
191191
"cell_type": "markdown",
192192
"metadata": {},
193193
"source": [
194194
"## Optimizing a function with bounds\n",
195-
"Another thing that we can do is to set some bounds into our solution, so as to contain our candidate solutions within a specific range. We can do this simply by passing a `bounds` parameter, of type `tuple`, when creating an instance of our swarm. Let's try this using the global-best PSO with the Rastrigin function (`rastrigin_func` in `pyswarms.utils.functions.single_obj`)."
195+
"Another thing that we can do is to set some bounds into our solution, so as to contain our candidate solutions within a specific range. We can do this simply by passing a `bounds` parameter, of type `tuple`, when creating an instance of our swarm. Let's try this using the global-best PSO with the Rastrigin function (`rastrigin` in `pyswarms.utils.functions.single_obj`)."
196196
]
197197
},
198198
{
@@ -269,7 +269,7 @@
269269
"optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)\n",
270270
"\n",
271271
"# Perform optimization\n",
272-
"cost, pos = optimizer.optimize(fx.rastrigin_func, print_step=100, iters=1000, verbose=3)"
272+
"cost, pos = optimizer.optimize(fx.rastrigin, print_step=100, iters=1000, verbose=3)"
273273
]
274274
},
275275
{

examples/custom_optimization_loop.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"import numpy as np\n",
6161
"\n",
6262
"# Import sphere function as objective function\n",
63-
"from pyswarms.utils.functions.single_obj import sphere_func as f\n",
63+
"from pyswarms.utils.functions.single_obj import sphere as f\n",
6464
"\n",
6565
"# Import backend modules\n",
6666
"import pyswarms.backend as P\n",

examples/visualization.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"source": [
106106
"options = {'c1':0.5, 'c2':0.3, 'w':0.9}\n",
107107
"optimizer = ps.single.GlobalBestPSO(n_particles=50, dimensions=2, options=options)\n",
108-
"cost, pos = optimizer.optimize(fx.sphere_func, iters=100)"
108+
"cost, pos = optimizer.optimize(fx.sphere, iters=100)"
109109
]
110110
},
111111
{
@@ -184,7 +184,7 @@
184184
"outputs": [],
185185
"source": [
186186
"# Initialize mesher with sphere function\n",
187-
"m = Mesher(func=fx.sphere_func)"
187+
"m = Mesher(func=fx.sphere)"
188188
]
189189
},
190190
{

pyswarms/single/general_optimizer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
options=options, topology=my_topology)
4747
4848
# Perform optimization
49-
stats = optimizer.optimize(fx.sphere_func, iters=100)
49+
stats = optimizer.optimize(fx.sphere, iters=100)
5050
5151
This algorithm was adapted from the earlier works of J. Kennedy and
5252
R.C. Eberhart in Particle Swarm Optimization [IJCNN1995]_.

pyswarms/single/global_best.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
options=options)
4646
4747
# Perform optimization
48-
stats = optimizer.optimize(fx.sphere_func, iters=100)
48+
stats = optimizer.optimize(fx.sphere, iters=100)
4949
5050
This algorithm was adapted from the earlier works of J. Kennedy and
5151
R.C. Eberhart in Particle Swarm Optimization [IJCNN1995]_.

pyswarms/single/local_best.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
options=options)
5050
5151
# Perform optimization
52-
stats = optimizer.optimize(fx.sphere_func, iters=100)
52+
stats = optimizer.optimize(fx.sphere, iters=100)
5353
5454
This algorithm was adapted from one of the earlier works of
5555
J. Kennedy and R.C. Eberhart in Particle Swarm Optimization

pyswarms/utils/functions/single_obj.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@
1717
the design pattern stated above.
1818
1919
Function list:
20-
- Ackley's, ackley_func
21-
- Beale, beale_func
22-
- Booth, booth_func
23-
- Bukin's No 6, bukin6_func
24-
- Cross-in-Tray, crossintray_func
25-
- Easom, easom_func
26-
- Eggholder, eggholder_func
27-
- Goldstein, goldstein_func
28-
- Himmelblau's, himmelblau_func
29-
- Holder Table, holdertable_func
30-
- Levi, levi_func
31-
- Matyas, matyas_func
32-
- Rastrigin, rastrigin_func
33-
- Rosenbrock, rosenbrock_func
34-
- Schaffer No 2, schaffer2_func
35-
- Sphere, sphere_func
36-
- Three Hump Camel, threehump_func
20+
- Ackley's, ackley
21+
- Beale, beale
22+
- Booth, booth
23+
- Bukin's No 6, bukin6
24+
- Cross-in-Tray, crossintray
25+
- Easom, easom
26+
- Eggholder, eggholder
27+
- Goldstein, goldstein
28+
- Himmelblau's, himmelblau
29+
- Holder Table, holdertable
30+
- Levi, levi
31+
- Matyas, matyas
32+
- Rastrigin, rastrigin
33+
- Rosenbrock, rosenbrock
34+
- Schaffer No 2, schaffer2
35+
- Sphere, sphere
36+
- Three Hump Camel, threehump
3737
"""
3838

3939
# Import from __future__
@@ -45,7 +45,7 @@
4545
import numpy as np
4646

4747

48-
def ackley_func(x):
48+
def ackley(x):
4949
"""Ackley's objective function.
5050
5151
Has a global minimum of `0` at :code:`f(0,0,...,0)` with a search
@@ -81,7 +81,7 @@ def ackley_func(x):
8181
return j
8282

8383

84-
def beale_func(x):
84+
def beale(x):
8585
"""Beale objective function.
8686
8787
Only takes two dimensions and has a global minimum of `0` at
@@ -124,7 +124,7 @@ def beale_func(x):
124124
return j
125125

126126

127-
def booth_func(x):
127+
def booth(x):
128128
"""Booth's objective function.
129129
130130
Only takes two dimensions and has a global minimum of `0` at
@@ -161,7 +161,7 @@ def booth_func(x):
161161
return j
162162

163163

164-
def bukin6_func(x):
164+
def bukin6(x):
165165
"""Bukin N. 6 Objective Function
166166
167167
Only takes two dimensions and has a global minimum of `0` at
@@ -210,7 +210,7 @@ def bukin6_func(x):
210210
return j
211211

212212

213-
def crossintray_func(x):
213+
def crossintray(x):
214214
"""Cross-in-tray objective function.
215215
216216
Only takes two dimensions and has a four equal global minimums
@@ -264,7 +264,7 @@ def crossintray_func(x):
264264
return j
265265

266266

267-
def easom_func(x):
267+
def easom(x):
268268
"""Easom objective function.
269269
270270
Only takes two dimensions and has a global minimum of
@@ -312,7 +312,7 @@ def easom_func(x):
312312
return j
313313

314314

315-
def eggholder_func(x):
315+
def eggholder(x):
316316
"""Eggholder objective function.
317317
318318
Only takes two dimensions and has a global minimum of
@@ -359,7 +359,7 @@ def eggholder_func(x):
359359
return j
360360

361361

362-
def goldstein_func(x):
362+
def goldstein(x):
363363
"""Goldstein-Price's objective function.
364364
365365
Only takes two dimensions and has a global minimum at
@@ -424,7 +424,7 @@ def goldstein_func(x):
424424
return j
425425

426426

427-
def himmelblau_func(x):
427+
def himmelblau(x):
428428
"""Himmelblau's objective function
429429
430430
Only takes two dimensions and has a four equal global minimums
@@ -470,7 +470,7 @@ def himmelblau_func(x):
470470
return j
471471

472472

473-
def holdertable_func(x):
473+
def holdertable(x):
474474
"""Holder Table objective function
475475
476476
Only takes two dimensions and has a four equal global minimums
@@ -520,7 +520,7 @@ def holdertable_func(x):
520520
return j
521521

522522

523-
def levi_func(x):
523+
def levi(x):
524524
"""Levi objective function
525525
526526
Only takes two dimensions and has a global minimum at
@@ -569,7 +569,7 @@ def levi_func(x):
569569
return j
570570

571571

572-
def matyas_func(x):
572+
def matyas(x):
573573
"""Matyas objective function
574574
575575
Only takes two dimensions and has a global minimum at
@@ -599,7 +599,7 @@ def matyas_func(x):
599599
return j
600600

601601

602-
def rastrigin_func(x):
602+
def rastrigin(x):
603603
"""Rastrigin objective function.
604604
605605
Has a global minimum at :code:`f(0,0,...,0)` with a search
@@ -632,7 +632,7 @@ def rastrigin_func(x):
632632
return j
633633

634634

635-
def rosenbrock_func(x):
635+
def rosenbrock(x):
636636
"""Rosenbrock objective function.
637637
638638
Also known as the Rosenbrock's valley or Rosenbrock's banana
@@ -658,7 +658,7 @@ def rosenbrock_func(x):
658658
return r
659659

660660

661-
def schaffer2_func(x):
661+
def schaffer2(x):
662662
"""Schaffer N.2 objective function
663663
664664
Only takes two dimensions and has a global minimum at
@@ -703,7 +703,7 @@ def schaffer2_func(x):
703703
return j
704704

705705

706-
def sphere_func(x):
706+
def sphere(x):
707707
"""Sphere objective function.
708708
709709
Has a global minimum at :code:`0` and with a search domain of
@@ -724,7 +724,7 @@ def sphere_func(x):
724724
return j
725725

726726

727-
def threehump_func(x):
727+
def threehump(x):
728728
"""Three-hump camel objective function
729729
730730
Only takes two dimensions and has a global minimum of `0` at

0 commit comments

Comments
 (0)