Skip to content

Commit b8776d1

Browse files
committed
reformatted code
1 parent 80f686e commit b8776d1

File tree

243 files changed

+21171
-18672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+21171
-18672
lines changed

.flake8

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
2-
ignore = E203,E266,E501,W503,D302,D401,D413,D414,D202,RST210,RST299,RST304,RST305,RST399,FI
2+
ignore = E126, E501, D302,D401,D413,D414,D202,RST210,RST299,RST304,RST305,RST399,FI
33
exclude =
44
.git,
55
__pycache__,
@@ -8,10 +8,9 @@ exclude =
88
build,
99
dist,
1010
scent.py
11-
per-file-ignores =
11+
per-file-ignores =
1212
niapy/tests/*:B007,D100,D101,D102,D107,D208,D211,D413,E117,E302,E701,E704,F841,S110,W191,W293,D204,RST210,E101,D204,D205,D206,E741
13-
niapy/algorithms/*:B305,B007,D100,D101,D102,D107,D204,D206,D413,E101,E117,E126,E302,E305,E701,E704,E711,E741,F812,RST201,RST203,RST204,RST210,RST301,W191
14-
niapy/task/*:E701
15-
niapy/util/*:W191,E117,E305,E302,E704,E701,RST203,D204,E306,D100
16-
niapy/benchmarks/*:W191,E117,E305,E302,E704,E701,RST203,D204,E306,D206,D208
13+
niapy/algorithms/*:B007,D100,D101,D102,D107,D204,D206,D413,RST201,RST203,RST204,RST210,RST301
14+
niapy/util/*:RST203,D100
15+
niapy/benchmarks/*:W191,RST203,D204,D206,D208
1716

.pycodestyle.ini

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,5 @@
33
# E401 multiple imports on one line (checked by PyLint)
44
# E402 module level import not at top of file (checked by PyLint)
55
# E501: line too long (checked by PyLint)
6-
# E711: comparison to None (used to improve test style)
7-
# E712: comparison to True (used to improve test style)
8-
# W191: intentation contains tabs
9-
# E701: multiple statements on one line (dolon)
10-
# E704: multiple statements on one line (def)
11-
# E101: intentation contains mixed spaces nad tabs
12-
# E242: tab after ':'
13-
# E302: expected 2 blank lines
14-
# E305: expected 2 blank lines after class or function definition
15-
# E306: expected 1 blank line befor a nested definition
16-
# E274: tab vefore keyword
17-
# D204: 1 blank line required after class docstring
18-
# D413: Missing blank line after last section
19-
# E126: cntinuation line over-indented for hanging indent
20-
# E702: Multiple statemets on one line (semicolon)
21-
# E111 indentation is not a multiple of four
22-
# E741 ambiguous variable name 'I'
23-
ignore = E401,E402,E501,E711,E712,W504,W191,E701,E704,E101,E242,E302,E305,E306,E274,D204,D413,E126,E702,E111,E741,E117
6+
# E126: continuation line over-indented for hanging indent
7+
ignore = E401,E402,E501,E711,E712,E126

.pydocstyle.ini

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
[pydocstyle]
22

33
# D211: No blank lines allowed before class docstring
4-
add_select = D211
4+
# add_select = D211
55

66
# D100: Missing docstring in public module
77
# D101: Missing docstring in public class
88
# D102: Missing docstring in public method
99
# D103: Missing docstring in public function
1010
# D104: Missing docstring in public package
1111
# D105: Missing docstring in magic method
12-
# D107: Missing docstring in __init__
13-
# D202: No blank lines allowed after function docstring
14-
# D204: 1 blank line required after class docstring
15-
# D206: Docstring should be indented with spaces, not tabs
16-
# D413: Missing blank line after last section
17-
# D414: Section has no content ('Returns')
18-
add_ignore = D100,D101,D102,D103,D104,D105,D107,D202,D204,D206,D301,D302,D402,D413,D414
12+
add_ignore = D100,D101,D102,D103,D104,D105

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ from niapy.task import StoppingTask
114114
# we will run 10 repetitions of Grey Wolf Optimizer against Pinter benchmark function
115115
for i in range(10):
116116
task = StoppingTask(D=10, nFES=1000, benchmark='pinter')
117-
algorithm = GreyWolfOptimizer(NP=20)
117+
algorithm = GreyWolfOptimizer(population_size=20)
118118
best = algorithm.run(task)
119119
print(best[-1])
120120
```
@@ -165,7 +165,7 @@ for i in range(10):
165165
task = StoppingTask(D=20, nGEN=100, optType=OptimizationType.MINIMIZATION, benchmark=MyBenchmark())
166166

167167
# parameter is population size
168-
algo = GreyWolfOptimizer(NP=20)
168+
algo = GreyWolfOptimizer(population_size=20)
169169

170170
# running algorithm returns best found minimum
171171
best = algo.run(task)

docs/source/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ Changelog <https://github.com/NiaOrg/NiaPy/compare/1.0.0...1.0.1>`__
619619
(`GregaVrbancic <https://github.com/GregaVrbancic>`__)
620620
- Fix paper `#115 <https://github.com/NiaOrg/NiaPy/pull/115>`__
621621
(`GregaVrbancic <https://github.com/GregaVrbancic>`__)
622-
- arguments: Ts->integer; TournamentSelection: use shuffled indices in
622+
- arguments: Ts->integer; tournament_selection: use shuffled indices in
623623
… `#114 <https://github.com/NiaOrg/NiaPy/pull/114>`__
624624
(`mlaky88 <https://github.com/mlaky88>`__)
625625

docs/source/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ The complete example would look something like this.
213213
task = StoppingTask(D=20, nGEN=100, optType=OptimizationType.MINIMIZATION, benchmark=MyBenchmark())
214214
215215
# parameter is population size
216-
algo = GreyWolfOptimizer(NP=20, InitPopFunc=MyInit)
216+
algo = GreyWolfOptimizer(NP=20, initialization_function=MyInit)
217217
218218
# running algorithm returns best found minimum
219219
best = algo.run(task)

examples/about_algorithm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
# This is temporary fix to import module from parent folder
33
# It will be removed when package is published on PyPI
44
import sys
5+
56
sys.path.append('../')
67
# End of fix
78

89
from niapy.algorithms.basic import FireflyAlgorithm
910

1011
algo = FireflyAlgorithm()
11-
print(algo.algorithmInfo())
12+
print(algo.info())

examples/advanced_example.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@
22
# This is temporary fix to import module from parent folder
33
# It will be removed when package is published on PyPI
44
import sys
5+
56
sys.path.append('../')
67

78
from niapy.task import StoppingTask, OptimizationType
89
from niapy.benchmarks import Benchmark
910
from niapy.algorithms.basic import GreyWolfOptimizer
1011

12+
1113
# our custom benchmark class
1214
class MyBenchmark(Benchmark):
13-
def __init__(self):
14-
Benchmark.__init__(self, -10, 10)
15+
def __init__(self):
16+
Benchmark.__init__(self, -10, 10)
17+
18+
def function(self):
19+
def evaluate(D, sol):
20+
val = 0.0
21+
for i in range(D): val += sol[i] ** 2
22+
return val
1523

16-
def function(self):
17-
def evaluate(D, sol):
18-
val = 0.0
19-
for i in range(D): val += sol[i] ** 2
20-
return val
21-
return evaluate
24+
return evaluate
2225

2326

2427
# we will run 10 repetitions of Grey Wolf Optimizer against our custom MyBenchmark benchmark function
2528
for i in range(10):
26-
task = StoppingTask(D=20, nGEN=100, optType=OptimizationType.MINIMIZATION, benchmark=MyBenchmark())
29+
task = StoppingTask(max_iters=100, dimension=20, optimization_type=OptimizationType.MINIMIZATION,
30+
benchmark=MyBenchmark())
2731

2832
# parameter is population size
29-
algo = GreyWolfOptimizer(NP=20)
33+
algo = GreyWolfOptimizer(population_size=20)
3034

3135
# running algorithm returns best found minimum
3236
best = algo.run(task)

examples/advanced_example_custom_pop.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,44 @@
22
# This is temporary fix to import module from parent folder
33
# It will be removed when package is published on PyPI
44
import sys
5+
56
sys.path.append('../')
67

78
from niapy.task import StoppingTask, OptimizationType
89
from niapy.benchmarks import Benchmark
910
from niapy.algorithms.basic import GreyWolfOptimizer
1011
from numpy import random as rand, apply_along_axis
1112

13+
1214
# our custom benchmark class
1315
class MyBenchmark(Benchmark):
14-
def __init__(self):
15-
Benchmark.__init__(self, -10, 10)
16+
def __init__(self):
17+
18+
Benchmark.__init__(self, -10, 10)
1619

17-
def function(self):
18-
def evaluate(D, sol):
19-
val = 0.0
20-
for i in range(D): val += sol[i] ** 2
21-
return val
22-
return evaluate
20+
def function(self):
21+
def evaluate(D, sol):
22+
val = 0.0
23+
for i in range(D): val += sol[i] ** 2
24+
return val
25+
26+
return evaluate
2327

2428

2529
# custom initialization population function
2630
def MyInit(task, NP, rnd=rand, **kwargs):
27-
pop = 0.2 + rnd.rand(NP, task.D) * task.bRange
31+
pop = 0.2 + rnd.rand(NP, task.dimension) * task.range
2832
fpop = apply_along_axis(task.eval, 1, pop)
2933
return pop, fpop
3034

35+
3136
# we will run 10 repetitions of Grey Wolf Optimizer against our custom MyBenchmark benchmark function
3237
for i in range(10):
33-
task = StoppingTask(D=20, nGEN=100, optType=OptimizationType.MINIMIZATION, benchmark=MyBenchmark())
38+
task = StoppingTask(max_iters=100, dimension=20, optimization_type=OptimizationType.MINIMIZATION,
39+
benchmark=MyBenchmark())
3440

3541
# parameter is population size
36-
algo = GreyWolfOptimizer(NP=20, InitPopFunc=MyInit)
42+
algo = GreyWolfOptimizer(NP=20, initialization_function=MyInit)
3743

3844
# running algorithm returns best found minimum
3945
best = algo.run(task)

examples/basic_customized_example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This is temporary fix to import module from parent folder
22
# It will be removed when package is published on PyPI
33
import sys
4+
45
sys.path.append('../')
56
# End of fix
67

@@ -17,10 +18,11 @@
1718
# second parameter takes the number of function evaluations
1819
# third parameter is benchmark optimization type
1920
# forth parameter is benchmark function
20-
task = StoppingTask(D=20, nGEN=100, optType=OptimizationType.MINIMIZATION, benchmark=pinterCustom)
21+
task = StoppingTask(max_iters=100, dimension=20, optimization_type=OptimizationType.MINIMIZATION,
22+
benchmark=pinterCustom)
2123

2224
# parameter is population size
23-
algo = GreyWolfOptimizer(NP=20)
25+
algo = GreyWolfOptimizer(population_size=20)
2426

2527
# running algorithm returns best found minimum
2628
best = algo.run(task)

examples/basic_example.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This is temporary fix to import module from parent folder
22
# It will be removed when package is published on PyPI
33
import sys
4+
45
sys.path.append('../')
56
# End of fix
67

@@ -9,7 +10,7 @@
910

1011
# we will run 10 repetitions of Grey Wolf Optimizer against Pinter benchmark function
1112
for i in range(10):
12-
task = StoppingTask(D=10, nFES=1000, benchmark='pinter')
13-
algorithm = GreyWolfOptimizer(NP=20)
13+
task = StoppingTask(max_evals=1000, dimension=10, benchmark='pinter')
14+
algorithm = GreyWolfOptimizer(population_size=20)
1415
best = algorithm.run(task)
1516
print(best[-1])

examples/basic_stats.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# This is temporary fix to import module from parent folder
33
# It will be removed when package is published on PyPI
44
import sys
5+
56
sys.path.append('../')
67
# End of fix
78

@@ -15,9 +16,10 @@
1516
stats = np.zeros(NUM_RUNS)
1617

1718
for i in range(NUM_RUNS):
18-
task = StoppingTask(D=10, nFES=10000, optType=OptimizationType.MINIMIZATION, benchmark=Sphere())
19-
print ("Working on run: " + str(i+1))
20-
algo = DifferentialEvolution(NP=40, CR=0.9, F=0.5)
19+
task = StoppingTask(max_evals=10000, dimension=10, optimization_type=OptimizationType.MINIMIZATION,
20+
benchmark=Sphere())
21+
print("Working on run: " + str(i + 1))
22+
algo = DifferentialEvolution(population_size=40, CR=0.9, F=0.5)
2123
best = algo.run(task)
2224
stats[i] = best[1] # save best
2325

examples/custom_benchmark.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@
22
# This is temporary fix to import module from parent folder
33
# It will be removed when package is published on PyPI
44
import sys
5+
56
sys.path.append('../')
67

78
from niapy.task import StoppingTask, OptimizationType
89
from niapy.benchmarks import Benchmark
910
from niapy.algorithms.basic import ParticleSwarmAlgorithm
1011

12+
1113
class MyBenchmark(Benchmark):
12-
def __init__(self):
13-
Benchmark.__init__(self, -10, 10)
14+
def __init__(self):
15+
16+
Benchmark.__init__(self, -10, 10)
17+
18+
def function(self):
19+
def evaluate(D, sol):
20+
val = 0.0
21+
for i in range(D): val += sol[i] ** 2
22+
return val
1423

15-
def function(self):
16-
def evaluate(D, sol):
17-
val = 0.0
18-
for i in range(D): val += sol[i] ** 2
19-
return val
20-
return evaluate
24+
return evaluate
2125

2226

2327
# we will run Particle Swarm Algorithm with on custom benchmark
2428
for i in range(1):
25-
task = StoppingTask(D=10, nGEN=1000, optType=OptimizationType.MINIMIZATION, benchmark=MyBenchmark())
26-
algo = ParticleSwarmAlgorithm(NP=40, C1=2.0, C2=2.0, w=0.7, vMin=-4, vMax=4)
29+
task = StoppingTask(max_iters=1000, dimension=10, optimization_type=OptimizationType.MINIMIZATION,
30+
benchmark=MyBenchmark())
31+
algo = ParticleSwarmAlgorithm(population_size=40, C1=2.0, C2=2.0, w=0.7, vMin=-4, vMax=4)
2732
best = algo.run(task=task)
2833
print('%s -> %s ' % (best[0], best[1]))

examples/custom_init_population.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
# This is temporary fix to import module from parent folder
33
# It will be removed when package is published on PyPI
44
import sys
5+
56
sys.path.append('../')
67
# End of fix
78

89
from niapy.algorithms.basic import ParticleSwarmAlgorithm
9-
from niapy.task.task import StoppingTask, OptimizationType
10+
from niapy.task.task import StoppingTask
1011
from niapy.benchmarks import Sphere
1112
from numpy import random as rand, apply_along_axis
1213

14+
1315
def MyInit(task, NP, rnd=rand, **kwargs):
14-
pop = 0.2 + rnd.rand(NP, task.D) * task.bRange
16+
pop = 0.2 + rnd.rand(NP, task.dimension) * task.range
1517
fpop = apply_along_axis(task.eval, 1, pop)
1618
return pop, fpop
1719

1820

1921
# we will run Particle Swarm Algorithm with custom Init function for 5 independent runs
2022
for i in range(5):
21-
task = StoppingTask(D=10, nFES=1000, benchmark=Sphere())
22-
algo = ParticleSwarmAlgorithm(NP=10, C1=2.0, C2=2.0, w=0.7, vMin=-4, vMax=4, InitPopFunc=MyInit)
23-
best = algo.run(task=task)
24-
print(best)
23+
task = StoppingTask(max_evals=1000, dimension=10, benchmark=Sphere())
24+
algo = ParticleSwarmAlgorithm(population_size=10, C1=2.0, C2=2.0, w=0.7, vMin=-4, vMax=4, initialization_function=MyInit)
25+
best = algo.run(task=task)
26+
print(best)

examples/log_results.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
# This is temporary fix to import module from parent folder
33
# It will be removed when package is published on PyPI
44
import sys
5+
56
sys.path.append('../')
67
# End of fix
78

8-
from niapy.task import StoppingTask, OptimizationType
9+
from niapy.task import StoppingTask
910
from niapy.benchmarks import Sphere
1011
from niapy.algorithms.basic import DifferentialEvolution
1112

1213
# Storing improvements during the evolutionary cycle
1314
for i in range(1):
14-
task = StoppingTask(D=10, nFES=10000, benchmark=Sphere())
15-
algo = DifferentialEvolution(NP=40, CR=0.9, F=0.5)
16-
best = algo.run(task)
17-
evals, x_f = task.return_conv()
18-
print(evals) # print function evaluations
19-
print(x_f) # print values
15+
task = StoppingTask(max_evals=10000, dimension=10, benchmark=Sphere())
16+
algo = DifferentialEvolution(population_size=40, CR=0.9, F=0.5)
17+
best = algo.run(task)
18+
evals, x_f = task.return_conv()
19+
print(evals) # print function evaluations
20+
print(x_f) # print values

0 commit comments

Comments
 (0)