ecabc 3.0.0__tar.gz → 3.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ecabc-3.0.2/LICENSE +21 -0
- ecabc-3.0.2/PKG-INFO +272 -0
- {ecabc-3.0.0 → ecabc-3.0.2}/README.md +241 -244
- ecabc-3.0.2/pyproject.toml +71 -0
- {ecabc-3.0.0 → ecabc-3.0.2}/setup.cfg +4 -4
- ecabc-3.0.2/src/ecabc/__init__.py +19 -0
- ecabc-3.0.2/src/ecabc/abc.py +305 -0
- {ecabc-3.0.0 → ecabc-3.0.2/src}/ecabc/bee.py +97 -95
- {ecabc-3.0.0 → ecabc-3.0.2/src}/ecabc/parameter.py +100 -98
- {ecabc-3.0.0 → ecabc-3.0.2/src}/ecabc/utils.py +107 -98
- ecabc-3.0.2/src/ecabc.egg-info/PKG-INFO +272 -0
- ecabc-3.0.2/src/ecabc.egg-info/SOURCES.txt +15 -0
- ecabc-3.0.2/src/ecabc.egg-info/requires.txt +14 -0
- ecabc-3.0.2/tests/test_all.py +231 -0
- ecabc-3.0.2/tests/test_api_contract.py +305 -0
- ecabc-3.0.0/PKG-INFO +0 -10
- ecabc-3.0.0/ecabc/__init__.py +0 -5
- ecabc-3.0.0/ecabc/abc.py +0 -315
- ecabc-3.0.0/ecabc.egg-info/PKG-INFO +0 -10
- ecabc-3.0.0/ecabc.egg-info/SOURCES.txt +0 -12
- ecabc-3.0.0/ecabc.egg-info/not-zip-safe +0 -1
- ecabc-3.0.0/setup.py +0 -16
- {ecabc-3.0.0 → ecabc-3.0.2/src}/ecabc.egg-info/dependency_links.txt +0 -0
- {ecabc-3.0.0 → ecabc-3.0.2/src}/ecabc.egg-info/top_level.txt +0 -0
ecabc-3.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2026 Sanskriti Sharma, Hernan Gelaf-Romer, Travis Kessler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ecabc-3.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ecabc
|
|
3
|
+
Version: 3.0.2
|
|
4
|
+
Summary: Artificial bee colony for function parameter optimization
|
|
5
|
+
Author-email: Sanskriti Sharma <Sanskriti_Sharma@student.uml.edu>, Hernan Gelaf-Romer <Hernan_Gelafromer@student.uml.edu>, Travis Kessler <travis.j.kessler@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ecrl/ecabc
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/ecrl/ecabc/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
21
|
+
Requires-Dist: ruff>=0.8; extra == "dev"
|
|
22
|
+
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
23
|
+
Requires-Dist: pre-commit>=4; extra == "dev"
|
|
24
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
25
|
+
Provides-Extra: docs
|
|
26
|
+
Requires-Dist: sphinx>=7; extra == "docs"
|
|
27
|
+
Requires-Dist: furo>=2024.1; extra == "docs"
|
|
28
|
+
Requires-Dist: sphinx-autodoc-typehints>=2; extra == "docs"
|
|
29
|
+
Requires-Dist: sphinx-copybutton>=0.5; extra == "docs"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
[](http://faculty.uml.edu/Hunter_Mack/)
|
|
33
|
+
|
|
34
|
+
# ECabc: optimization algorithm for tuning user-defined parametric functions
|
|
35
|
+
[](https://badge.fury.io/gh/ECRL%2FECabc)
|
|
36
|
+
[](https://badge.fury.io/py/ecabc)
|
|
37
|
+
[](https://github.com/ECRL/ecabc/blob/master/LICENSE)
|
|
38
|
+
[](https://github.com/ecrl/ecabc/actions/workflows/run_tests.yml)
|
|
39
|
+
[](https://doi.org/10.21105/joss.01420)
|
|
40
|
+
|
|
41
|
+
**ECabc** is an open source Python package used to tune parameters for user-supplied functions based on the [Artificial Bee Colony by D. Karaboğa](http://scholarpedia.org/article/Artificial_bee_colony_algorithm). ECabc optimizes user supplied functions, or **fitness function**s, using a set of variables that exist within a search space. The bee colony consists of three types of bees: employers, onlookers and scouts. An **employer bee** exploits a solution comprised of a permutation of the variables in the search space, and evaluates the viability of the solution. An **onlooker bee** chooses an employer bee with an optimal solution and searches for new solutions near them. The **scout bee**, a variant of the employer bee, will search for a new solution if it has stayed too long at its current solution.
|
|
42
|
+
|
|
43
|
+
<p align="center">
|
|
44
|
+
<img align="center" src="docs/img/abc_visual_convergence.gif" width="75%" height="75%">
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
### Research applications
|
|
48
|
+
While it has several applications, ECabc has been successfully used by the Energy and Combustion Research Laboratory (ECRL) at the University of Massachusetts Lowell to tune the hyperparameters of ECNet, an open source Python package tailored to predicting fuel properties. ECNet provides scientists an open source tool for predicting key fuel properties of potential next-generation biofuels, reducing the need for costly fuel synthesis and experimentation. By increasing the accuracy of ECNet and similar models efficiently, ECabc helps to provide a higher degree of confidence in discovering new, optimal fuels. A single run of ECabc on ECNet yielded a lower average root mean square error (RMSE) for cetane number (CN) and yield sooting index (YSI) when compared to the RMSE generated by a year of manual tuning. While the manual tuning generated an RMSE of 10.13, the ECabc was able to yield an RMSE of 8.06 in one run of 500 iterations.
|
|
49
|
+
|
|
50
|
+
# Installation
|
|
51
|
+
|
|
52
|
+
**Requires Python 3.10 or newer.** ECabc has no runtime third-party dependencies
|
|
53
|
+
(stdlib only). A virtual environment is recommended.
|
|
54
|
+
|
|
55
|
+
### Method 1: pip
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
pip install ecabc
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
To upgrade to the latest release:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
pip install --upgrade ecabc
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Method 2: From source
|
|
68
|
+
|
|
69
|
+
Clone or download this repository, then from the repository root:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
pip install .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
# Usage
|
|
76
|
+
|
|
77
|
+
API stability for the public surface is documented in
|
|
78
|
+
[API_STABILITY.md](API_STABILITY.md) (also the Sphinx *API stability policy*
|
|
79
|
+
page under `docs/source/stability.rst`).
|
|
80
|
+
|
|
81
|
+
To start using ECabc, you need a couple items:
|
|
82
|
+
- a fitness function (cost function) to optimize
|
|
83
|
+
- parameters used by the fitness function
|
|
84
|
+
|
|
85
|
+
For example, let's define a fitness function to minimize the sum of three integers:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
def minimize_integers(integers):
|
|
89
|
+
|
|
90
|
+
return sum(integers)
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Your fitness function must accept a **list** from ECabc. The list values represent the current "food source", i.e. parameter values, being exploited by a given bee.
|
|
95
|
+
|
|
96
|
+
Now that we have our fitness function, let's import the ABC object from ECabc, initialize the artificial bee colony, and add our parameters:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from ecabc import ABC
|
|
100
|
+
|
|
101
|
+
def minimize_integers(integers):
|
|
102
|
+
|
|
103
|
+
return sum(integers)
|
|
104
|
+
|
|
105
|
+
abc = ABC(10, minimize_integers)
|
|
106
|
+
abc.add_param(0, 10, name='Int_1')
|
|
107
|
+
abc.add_param(0, 10, name='Int_2')
|
|
108
|
+
abc.add_param(0, 10, name='Int_3')
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Here we initialize the colony with 10 employer bees, supply our fitness function, and add our parameters. Parameters are added with minimum/maximum values for its search space and optionally a name. By default, parameter mutations (searching a neighboring food source) will not exceed the specified parameter bounds [min_val, max_val]; if this limitation is not desired, supply the "restrict=False" argument:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
abc.add_param(0, 10, restrict=False, name='Int_1')
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Once we have created our colony and added our parameters, we then need to "initialize" the colony's bees:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from ecabc import ABC
|
|
121
|
+
|
|
122
|
+
def minimize_integers(integers):
|
|
123
|
+
|
|
124
|
+
return sum(integers)
|
|
125
|
+
|
|
126
|
+
abc = ABC(10, minimize_integers)
|
|
127
|
+
abc.add_param(0, 10, name='Int_1')
|
|
128
|
+
abc.add_param(0, 10, name='Int_2')
|
|
129
|
+
abc.add_param(0, 10, name='Int_3')
|
|
130
|
+
abc.initialize()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Initializing the colony's bees deploys employer bees (in this example, 10 bees) to random food sources (random parameter values are generated), their fitness is evaluated (in this example, lowest sum is better), and onlooker bees (equal to the number of employers) are deployed proportionally to neighboring food sources of well-performing bees.
|
|
134
|
+
|
|
135
|
+
We then send the colony through a predetermined of "search cycles":
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from ecabc import ABC
|
|
139
|
+
|
|
140
|
+
def minimize_integers(integers):
|
|
141
|
+
|
|
142
|
+
return sum(integers)
|
|
143
|
+
|
|
144
|
+
abc = ABC(10, minimize_integers)
|
|
145
|
+
abc.add_param(0, 10, name='Int_1')
|
|
146
|
+
abc.add_param(0, 10, name='Int_2')
|
|
147
|
+
abc.add_param(0, 10, name='Int_3')
|
|
148
|
+
abc.initialize()
|
|
149
|
+
for _ in range(10):
|
|
150
|
+
abc.search()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
A search cycle consists of:
|
|
154
|
+
- each bee searches a neighboring food source (performs a mutation on one parameter)
|
|
155
|
+
- if the food source produces a better fitness than the bee's current food source, move there
|
|
156
|
+
- otherwise, the bee stays at its current food source
|
|
157
|
+
- if the bee has stayed for (NE * D) cycles (NE = number of employers, D = dimension of the function, 3 in our example), abandon the food source
|
|
158
|
+
- if the bee is an employer, go to a new random food source
|
|
159
|
+
- if the bee is an onlooker, go to a food source neighboring a well-performing bee
|
|
160
|
+
|
|
161
|
+
We can access the colony's average fitness score, average fitness function return value, best fitness score, best fitness function return value and best parameters at any time:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
print(abc.average_fitness)
|
|
165
|
+
print(abc.average_ret_val)
|
|
166
|
+
print(abc.best_fitness)
|
|
167
|
+
print(abc.best_ret_val)
|
|
168
|
+
print(abc.best_params)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
ECabc can utilize multiple CPU cores for concurrent processing:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
abc = ABC(10, minimize_integers, num_processes=8)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Tying everything together, we have:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from ecabc import ABC
|
|
181
|
+
|
|
182
|
+
def minimize_integers(integers):
|
|
183
|
+
|
|
184
|
+
return sum(integers)
|
|
185
|
+
|
|
186
|
+
abc = ABC(10, minimize_integers)
|
|
187
|
+
abc.add_param(0, 10, name='Int_1')
|
|
188
|
+
abc.add_param(0, 10, name='Int_2')
|
|
189
|
+
abc.add_param(0, 10, name='Int_3')
|
|
190
|
+
abc.initialize()
|
|
191
|
+
for _ in range(10):
|
|
192
|
+
abc.search()
|
|
193
|
+
print('Average fitness: {}'.format(abc.average_fitness))
|
|
194
|
+
print('Average obj. fn. return value: {}'.format(abc.average_ret_val))
|
|
195
|
+
print('Best fitness score: {}'.format(abc.best_fitness))
|
|
196
|
+
print('Best obj. fn. return value: {}'.format(abc.best_ret_val))
|
|
197
|
+
print('Best parameters: {}\n'.format(abc.best_params))
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Running this script produces:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
Average fitness: 0.08244866244866243
|
|
204
|
+
Average obj. fn. return value: 11.65
|
|
205
|
+
Best fitness score: 0.125
|
|
206
|
+
Best obj. fn. return value: 7
|
|
207
|
+
Best parameters: {'Int_1': 4, 'Int_2': 3, 'Int_3': 0}
|
|
208
|
+
|
|
209
|
+
Average fitness: 0.0885855117105117
|
|
210
|
+
Average obj. fn. return value: 10.8
|
|
211
|
+
Best fitness score: 0.125
|
|
212
|
+
Best obj. fn. return value: 7
|
|
213
|
+
Best parameters: {'Int_1': 4, 'Int_2': 3, 'Int_3': 0}
|
|
214
|
+
|
|
215
|
+
Average fitness: 0.10361832611832611
|
|
216
|
+
Average obj. fn. return value: 9.4
|
|
217
|
+
Best fitness score: 0.16666666666666666
|
|
218
|
+
Best obj. fn. return value: 5
|
|
219
|
+
Best parameters: {'Int_1': 2, 'Int_2': 3, 'Int_3': 0}
|
|
220
|
+
|
|
221
|
+
Average fitness: 0.11173502151443326
|
|
222
|
+
Average obj. fn. return value: 8.8
|
|
223
|
+
Best fitness score: 0.2
|
|
224
|
+
Best obj. fn. return value: 4
|
|
225
|
+
Best parameters: {'Int_1': 0, 'Int_2': 0, 'Int_3': 4}
|
|
226
|
+
|
|
227
|
+
Average fitness: 0.12448879551820731
|
|
228
|
+
Average obj. fn. return value: 7.95
|
|
229
|
+
Best fitness score: 0.2
|
|
230
|
+
Best obj. fn. return value: 4
|
|
231
|
+
Best parameters: {'Int_1': 1, 'Int_2': 3, 'Int_3': 0}
|
|
232
|
+
|
|
233
|
+
Average fitness: 0.1767694805194805
|
|
234
|
+
Average obj. fn. return value: 6.7
|
|
235
|
+
Best fitness score: 1.0
|
|
236
|
+
Best obj. fn. return value: 0
|
|
237
|
+
Best parameters: {'Int_1': 0, 'Int_2': 0, 'Int_3': 0}
|
|
238
|
+
|
|
239
|
+
Average fitness: 0.183255772005772
|
|
240
|
+
Average obj. fn. return value: 6.3
|
|
241
|
+
Best fitness score: 1.0
|
|
242
|
+
Best obj. fn. return value: 0
|
|
243
|
+
Best parameters: {'Int_1': 0, 'Int_2': 0, 'Int_3': 0}
|
|
244
|
+
|
|
245
|
+
Average fitness: 0.20172799422799423
|
|
246
|
+
Average obj. fn. return value: 5.65
|
|
247
|
+
Best fitness score: 1.0
|
|
248
|
+
Best obj. fn. return value: 0
|
|
249
|
+
Best parameters: {'Int_1': 0, 'Int_2': 0, 'Int_3': 0}
|
|
250
|
+
|
|
251
|
+
Average fitness: 0.23827561327561328
|
|
252
|
+
Average obj. fn. return value: 4.95
|
|
253
|
+
Best fitness score: 1.0
|
|
254
|
+
Best obj. fn. return value: 0
|
|
255
|
+
Best parameters: {'Int_1': 0, 'Int_2': 0, 'Int_3': 0}
|
|
256
|
+
|
|
257
|
+
Average fitness: 0.28456349206349213
|
|
258
|
+
Average obj. fn. return value: 4.35
|
|
259
|
+
Best fitness score: 1.0
|
|
260
|
+
Best obj. fn. return value: 0
|
|
261
|
+
Best parameters: {'Int_1': 0, 'Int_2': 0, 'Int_3': 0}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
To run this script yourself, head over to our [examples](https://github.com/ecrl/ecabc/tree/master/examples) directory.
|
|
265
|
+
|
|
266
|
+
# Contributing, Reporting Issues and Other Support:
|
|
267
|
+
|
|
268
|
+
To contribute to ECabc, make a pull request. Contributions should include tests for new features added, as well as extensive documentation.
|
|
269
|
+
|
|
270
|
+
To report problems with the software or feature requests, file an issue. When reporting problems, include information such as error messages, your OS/environment and Python version.
|
|
271
|
+
|
|
272
|
+
For additional support/questions, contact Sanskriti Sharma (Sanskriti_Sharma@student.uml.edu), Hernan Gelaf-Romer (Hernan_Gelafromer@student.uml.edu), or Travis Kessler (Travis_Kessler@student.uml.edu).
|