Skip to content

Commit 981b0ba

Browse files
committed
Rerun all examples with new code.
1 parent 25bee39 commit 981b0ba

12 files changed

Lines changed: 204 additions & 406 deletions

examples/binh_and_korn_multiobjective.ipynb

Lines changed: 12 additions & 32 deletions
Large diffs are not rendered by default.

examples/easom_in_parallel.ipynb

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"id": "c0d16d4b",
65
"metadata": {},
76
"source": [
87
"# Easom function\n",
@@ -24,16 +23,14 @@
2423
},
2524
{
2625
"cell_type": "markdown",
27-
"id": "2e5eb17a",
2826
"metadata": {},
2927
"source": [
3028
"### First we import python libraries and set up the directory of our code."
3129
]
3230
},
3331
{
3432
"cell_type": "code",
35-
"execution_count": 7,
36-
"id": "26b4eb8a",
33+
"execution_count": 1,
3734
"metadata": {},
3835
"outputs": [],
3936
"source": [
@@ -47,16 +44,14 @@
4744
},
4845
{
4946
"cell_type": "markdown",
50-
"id": "bedebcd1",
5147
"metadata": {},
5248
"source": [
5349
"### Here we import all our custom GA code."
5450
]
5551
},
5652
{
5753
"cell_type": "code",
58-
"execution_count": 8,
59-
"id": "05edf811",
54+
"execution_count": 2,
6055
"metadata": {},
6156
"outputs": [],
6257
"source": [
@@ -80,7 +75,6 @@
8075
},
8176
{
8277
"cell_type": "markdown",
83-
"id": "c3e282d5",
8478
"metadata": {},
8579
"source": [
8680
"### Define the Easom function, which plays also the role of the 'fitness' function.\n",
@@ -91,8 +85,7 @@
9185
},
9286
{
9387
"cell_type": "code",
94-
"execution_count": 9,
95-
"id": "8719472f",
88+
"execution_count": 3,
9689
"metadata": {},
9790
"outputs": [],
9891
"source": [
@@ -128,7 +121,7 @@
128121
" is_valid = check_validity(chromosome)\n",
129122
" \n",
130123
" # Extract the data values as 'x' and 'y', for parsimony.\n",
131-
" x, y = [gene.value for gene in chromosome.genome]\n",
124+
" x, y = chromosome.values()\n",
132125
" \n",
133126
" # Calculate the function value.\n",
134127
" f_val = -np.cos(x) * np.cos(y) * np.exp(-((x - np.pi)**2 + (y - np.pi)**2))\n",
@@ -147,16 +140,14 @@
147140
},
148141
{
149142
"cell_type": "markdown",
150-
"id": "43bd7841",
151143
"metadata": {},
152144
"source": [
153145
"Here we set the GA parameters, such as number of genes, number of chromosomes, etc."
154146
]
155147
},
156148
{
157149
"cell_type": "code",
158-
"execution_count": 10,
159-
"id": "037270cd",
150+
"execution_count": 4,
160151
"metadata": {},
161152
"outputs": [],
162153
"source": [
@@ -188,7 +179,6 @@
188179
},
189180
{
190181
"cell_type": "markdown",
191-
"id": "fe274ad3",
192182
"metadata": {},
193183
"source": [
194184
"### Optimization process.\n",
@@ -198,8 +188,7 @@
198188
},
199189
{
200190
"cell_type": "code",
201-
"execution_count": 11,
202-
"id": "0a1c5d14",
191+
"execution_count": 5,
203192
"metadata": {
204193
"scrolled": true
205194
},
@@ -209,8 +198,8 @@
209198
"output_type": "stream",
210199
"text": [
211200
"Parallel evolution in progress with 4 islands ...\n",
212-
"Final Avg. Fitness = 0.2246.\n",
213-
"Elapsed time: 1.955 seconds.\n"
201+
"Final Avg. Fitness = 0.2212.\n",
202+
"Elapsed time: 1.221 seconds.\n"
214203
]
215204
}
216205
],
@@ -220,8 +209,7 @@
220209
},
221210
{
222211
"cell_type": "code",
223-
"execution_count": 12,
224-
"id": "3b3a2ad8",
212+
"execution_count": 6,
225213
"metadata": {},
226214
"outputs": [
227215
{
@@ -230,8 +218,8 @@
230218
"text": [
231219
"Minimum Found: -1.00000\n",
232220
"\n",
233-
"x0 = 3.14277\n",
234-
"x1 = 3.14188\n"
221+
"x0 = 3.14072\n",
222+
"x1 = 3.14087\n"
235223
]
236224
}
237225
],
@@ -246,16 +234,15 @@
246234
"print(f\"Minimum Found: {optimal_fit:.5f}\\n\")\n",
247235
"\n",
248236
"# Display each gene value separately.\n",
249-
"for i, xi in enumerate(optimal_solution.genome):\n",
250-
" print(f\"x{i} = {xi.value:.5f}\")\n",
237+
"for i, xi in enumerate(optimal_solution.values()):\n",
238+
" print(f\"x{i} = {xi:.5f}\")\n",
251239
"# _end_for_\n",
252240
"\n",
253241
"# True minimum: f(\\pi, \\pi) = -1.0"
254242
]
255243
},
256244
{
257245
"cell_type": "markdown",
258-
"id": "9f4a70ee",
259246
"metadata": {},
260247
"source": [
261248
"### End of file"
@@ -264,17 +251,16 @@
264251
{
265252
"cell_type": "code",
266253
"execution_count": null,
267-
"id": "b329d023-912e-4d42-b4d6-cbdec42a2c1d",
268254
"metadata": {},
269255
"outputs": [],
270256
"source": []
271257
}
272258
],
273259
"metadata": {
274260
"kernelspec": {
275-
"display_name": "venv_tf",
261+
"display_name": "SOMap",
276262
"language": "python",
277-
"name": "venv_tf"
263+
"name": "somap"
278264
},
279265
"language_info": {
280266
"codemirror_mode": {

examples/one_max.ipynb

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"id": "2a871b92",
65
"metadata": {},
76
"source": [
87
"# OneMax function\n",
@@ -25,7 +24,6 @@
2524
},
2625
{
2726
"cell_type": "markdown",
28-
"id": "5314f4cb",
2927
"metadata": {},
3028
"source": [
3129
"### First we import python libraries and set up the directory of our code."
@@ -34,7 +32,6 @@
3432
{
3533
"cell_type": "code",
3634
"execution_count": 1,
37-
"id": "e3e288b8",
3835
"metadata": {},
3936
"outputs": [],
4037
"source": [
@@ -48,7 +45,6 @@
4845
},
4946
{
5047
"cell_type": "markdown",
51-
"id": "a0ca56c0",
5248
"metadata": {},
5349
"source": [
5450
"### Here we import all our custom GA code."
@@ -57,7 +53,6 @@
5753
{
5854
"cell_type": "code",
5955
"execution_count": 2,
60-
"id": "73015625",
6156
"metadata": {},
6257
"outputs": [],
6358
"source": [
@@ -78,7 +73,6 @@
7873
},
7974
{
8075
"cell_type": "markdown",
81-
"id": "fd95b659",
8276
"metadata": {},
8377
"source": [
8478
"### Define the OneMax fitness function."
@@ -87,15 +81,14 @@
8781
{
8882
"cell_type": "code",
8983
"execution_count": 3,
90-
"id": "5a2d2bc4",
9184
"metadata": {},
9285
"outputs": [],
9386
"source": [
9487
"# OneMax function.\n",
9588
"def fun_OneMax(individual: Chromosome, f_min: bool = False):\n",
9689
" \n",
9790
" # Compute the function value.\n",
98-
" f_val = fsum([xi.value for xi in individual])\n",
91+
" f_val = fsum(individual.values())\n",
9992
"\n",
10093
" # Condition for termination.\n",
10194
" solution_found = f_val == len(individual)\n",
@@ -110,7 +103,6 @@
110103
},
111104
{
112105
"cell_type": "markdown",
113-
"id": "bdadd046",
114106
"metadata": {},
115107
"source": [
116108
"Here we set the GA parameters, such as number of genes, number of chromosomes, etc."
@@ -119,7 +111,6 @@
119111
{
120112
"cell_type": "code",
121113
"execution_count": 4,
122-
"id": "091152b6",
123114
"metadata": {},
124115
"outputs": [],
125116
"source": [
@@ -153,7 +144,6 @@
153144
},
154145
{
155146
"cell_type": "markdown",
156-
"id": "d0712daf",
157147
"metadata": {},
158148
"source": [
159149
"### Optimization process.\n",
@@ -164,17 +154,16 @@
164154
{
165155
"cell_type": "code",
166156
"execution_count": 5,
167-
"id": "b3502a18",
168157
"metadata": {},
169158
"outputs": [
170159
{
171160
"name": "stdout",
172161
"output_type": "stream",
173162
"text": [
174-
"Initial Avg. Fitness = 24.9700.\n",
175-
"StandardGA finished in 33 iterations.\n",
176-
"Final Avg. Fitness = 46.3100.\n",
177-
"Elapsed time: 2.655 seconds.\n"
163+
"Initial Avg. Fitness = 25.5900\n",
164+
"StandardGA finished in 16 iterations.\n",
165+
"Final Avg. Fitness = 45.0500\n",
166+
"Elapsed time: 2.212 seconds.\n"
178167
]
179168
}
180169
],
@@ -185,14 +174,13 @@
185174
{
186175
"cell_type": "code",
187176
"execution_count": 6,
188-
"id": "2523fc1f",
189177
"metadata": {},
190178
"outputs": [
191179
{
192180
"name": "stdout",
193181
"output_type": "stream",
194182
"text": [
195-
"Optimum Found: 50.00000\n",
183+
"Optimum Found: 50.000000\n",
196184
"\n",
197185
"x1 = 1.000000\n",
198186
"x2 = 1.000000\n",
@@ -255,19 +243,18 @@
255243
"optimal_fit, _ = fun_OneMax(optimal_solution)\n",
256244
"\n",
257245
"# Display the (final) optimal value.\n",
258-
"print(f\"Optimum Found: {optimal_fit:.5f}\\n\")\n",
246+
"print(f\"Optimum Found: {optimal_fit:.6f}\\n\")\n",
259247
"\n",
260248
"# Display each gene value separately.\n",
261-
"for i, xi in enumerate(optimal_solution.genome, start=1):\n",
262-
" print(f\"x{i} = {xi.value:>10.6f}\")\n",
249+
"for i, xi in enumerate(optimal_solution.values(), start=1):\n",
250+
" print(f\"x{i} = {xi:>10.6f}\")\n",
263251
"# _end_for_\n",
264252
"\n",
265253
"# True maximum: f(1.0, 1.0, ..., 1.0) = M"
266254
]
267255
},
268256
{
269257
"cell_type": "markdown",
270-
"id": "e3193c7f",
271258
"metadata": {},
272259
"source": [
273260
"### End of file"
@@ -276,17 +263,16 @@
276263
{
277264
"cell_type": "code",
278265
"execution_count": null,
279-
"id": "d7b1f97e",
280266
"metadata": {},
281267
"outputs": [],
282268
"source": []
283269
}
284270
],
285271
"metadata": {
286272
"kernelspec": {
287-
"display_name": "venv_tf",
273+
"display_name": "SOMap",
288274
"language": "python",
289-
"name": "venv_tf"
275+
"name": "somap"
290276
},
291277
"language_info": {
292278
"codemirror_mode": {

0 commit comments

Comments
 (0)