pyerualjetwork 4.3.8.dev4__py3-none-any.whl → 4.3.8.dev5__py3-none-any.whl
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.
- pyerualjetwork/__init__.py +1 -1
- {pyerualjetwork-4.3.8.dev4.dist-info → pyerualjetwork-4.3.8.dev5.dist-info}/METADATA +1 -1
- {pyerualjetwork-4.3.8.dev4.dist-info → pyerualjetwork-4.3.8.dev5.dist-info}/RECORD +7 -7
- pyerualjetwork_afterburner/__init__.py +1 -1
- pyerualjetwork_afterburner/planeat_cuda.py +279 -260
- {pyerualjetwork-4.3.8.dev4.dist-info → pyerualjetwork-4.3.8.dev5.dist-info}/WHEEL +0 -0
- {pyerualjetwork-4.3.8.dev4.dist-info → pyerualjetwork-4.3.8.dev5.dist-info}/top_level.txt +0 -0
pyerualjetwork/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "4.3.
|
1
|
+
__version__ = "4.3.8dev5"
|
2
2
|
__update__ = "* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES\n* PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main\n* PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf\n* YouTube tutorials: https://www.youtube.com/@HasanCanBeydili"
|
3
3
|
|
4
4
|
def print_version(__version__):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pyerualjetwork
|
3
|
-
Version: 4.3.8.
|
3
|
+
Version: 4.3.8.dev5
|
4
4
|
Summary: PyerualJetwork is a machine learning library supported with GPU(CUDA) acceleration written in Python for professionals and researchers including with PLAN algorithm, PLANEAT algorithm (genetic optimization). Also includes data pre-process and memory manegament
|
5
5
|
Author: Hasan Can Beydili
|
6
6
|
Author-email: tchasancan@gmail.com
|
@@ -1,4 +1,4 @@
|
|
1
|
-
pyerualjetwork/__init__.py,sha256=
|
1
|
+
pyerualjetwork/__init__.py,sha256=aQiVtvIoAkk7-Wrr-xNhNQPwVZB-2cSoKH8xytXVVqM,643
|
2
2
|
pyerualjetwork/activation_functions.py,sha256=AR91fQV2W2rc-Qb4Yp7b8ucYpGjwyQUewO-M-lyEMs8,7729
|
3
3
|
pyerualjetwork/activation_functions_cuda.py,sha256=ztIw6rMR4t1289_TPIGYwE6qarl_YbSOGj5Ep3rUMqs,11803
|
4
4
|
pyerualjetwork/data_operations.py,sha256=Flteouu6rfSo2uHMqBHuzO02dXmbNa-I5qWmUpGTZ5Y,14760
|
@@ -18,7 +18,7 @@ pyerualjetwork/planeat_cuda.py,sha256=QNHCQLkR0MNFqyN2iHAtC7cbf8qZiD3p_54YH3lnMF
|
|
18
18
|
pyerualjetwork/ui.py,sha256=wu2BhU1k-w3Kcho5Jtq4SEKe68ftaUeRGneUOSCVDjU,575
|
19
19
|
pyerualjetwork/visualizations.py,sha256=VL00sX2DZz83F__PyEJH9s1LizuXpOBzWjnoSjMJIJ0,28770
|
20
20
|
pyerualjetwork/visualizations_cuda.py,sha256=KbMhfsLlxujy_i3QrwCf734Q-k6d7Zn_7CEbm3gzK9w,29186
|
21
|
-
pyerualjetwork_afterburner/__init__.py,sha256=
|
21
|
+
pyerualjetwork_afterburner/__init__.py,sha256=kmFJeX5myisl9iSpmRGJPH4v51_2kcI0ZaauXjLkRCw,655
|
22
22
|
pyerualjetwork_afterburner/activation_functions.py,sha256=bKf00lsuuLJNO-4vVp4OqBi4zJ-qZ8L3v-vl52notkY,7721
|
23
23
|
pyerualjetwork_afterburner/activation_functions_cuda.py,sha256=5y1Ti3GDfDteQDCUmODwe7tAyDAUlDTKmIikChQ8d6g,7772
|
24
24
|
pyerualjetwork_afterburner/data_operations.py,sha256=Flteouu6rfSo2uHMqBHuzO02dXmbNa-I5qWmUpGTZ5Y,14760
|
@@ -34,11 +34,11 @@ pyerualjetwork_afterburner/model_operations_cuda.py,sha256=NT01BK5nrDYE7H1x3KnSI
|
|
34
34
|
pyerualjetwork_afterburner/plan.py,sha256=EOXngujG7DQRf3cooFigKB7heQsEoK96JtrcKivT_pE,22449
|
35
35
|
pyerualjetwork_afterburner/plan_cuda.py,sha256=fg5YunEuBE7sK6q9paP_yAGONr9x0e19oF0J0DucejM,23380
|
36
36
|
pyerualjetwork_afterburner/planeat.py,sha256=Lq5R0aMS4UIdZdbUKsKDv5g0WLwYryomR3IQYb8vAa4,37573
|
37
|
-
pyerualjetwork_afterburner/planeat_cuda.py,sha256=
|
37
|
+
pyerualjetwork_afterburner/planeat_cuda.py,sha256=Hh-prPlPToiJIyR3Xsp_b22cFIwEP09T77UJyZKnLLo,38722
|
38
38
|
pyerualjetwork_afterburner/ui.py,sha256=wu2BhU1k-w3Kcho5Jtq4SEKe68ftaUeRGneUOSCVDjU,575
|
39
39
|
pyerualjetwork_afterburner/visualizations.py,sha256=1SKMZaJ80OD2qHUyMxW1IOv8zwmxzMPxclfbeq1Xr4g,28772
|
40
40
|
pyerualjetwork_afterburner/visualizations_cuda.py,sha256=KbMhfsLlxujy_i3QrwCf734Q-k6d7Zn_7CEbm3gzK9w,29186
|
41
|
-
pyerualjetwork-4.3.8.
|
42
|
-
pyerualjetwork-4.3.8.
|
43
|
-
pyerualjetwork-4.3.8.
|
44
|
-
pyerualjetwork-4.3.8.
|
41
|
+
pyerualjetwork-4.3.8.dev5.dist-info/METADATA,sha256=4tAsoW5zkw92w30B6KZimXpYC1GIun2NWTbTenshDbs,8384
|
42
|
+
pyerualjetwork-4.3.8.dev5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
43
|
+
pyerualjetwork-4.3.8.dev5.dist-info/top_level.txt,sha256=uK64ge08QQoPuXM3aiRVPgiQQtl8Fxm2-HieIut5Lwo,42
|
44
|
+
pyerualjetwork-4.3.8.dev5.dist-info/RECORD,,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "4.3.
|
1
|
+
__version__ = "4.3.8dev5-afterburner"
|
2
2
|
__update__ = "* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES\n* PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main\n* PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf\n* YouTube tutorials: https://www.youtube.com/@HasanCanBeydili"
|
3
3
|
|
4
4
|
def print_version(__version__):
|
@@ -16,8 +16,7 @@ import cupy as cp
|
|
16
16
|
import numpy as np
|
17
17
|
import random
|
18
18
|
import math
|
19
|
-
|
20
|
-
import concurrent.futures
|
19
|
+
import multiprocessing as mp
|
21
20
|
from functools import partial
|
22
21
|
|
23
22
|
|
@@ -299,64 +298,31 @@ def evolver(weights,
|
|
299
298
|
mutated_W = cp.copy(bad_weights)
|
300
299
|
mutated_act = bad_activations.copy()
|
301
300
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
fitness_bias=fitness_bias,
|
328
|
-
second_parent_fitness=normalized_fitness[s_i],
|
329
|
-
epsilon=epsilon
|
330
|
-
)
|
331
|
-
|
332
|
-
mutation_prob = random.uniform(0, 1)
|
333
|
-
|
334
|
-
if mutation_prob > bad_genomes_mutation_prob:
|
335
|
-
genome_W = good_weights[i]
|
336
|
-
genome_act = good_activations[i]
|
337
|
-
|
338
|
-
fitness_index = int(len(bad_weights) / 2 + i)
|
339
|
-
|
340
|
-
else:
|
341
|
-
genome_W = bad_weights[i]
|
342
|
-
genome_act = bad_activations[i]
|
343
|
-
|
344
|
-
fitness_index = i
|
345
|
-
|
346
|
-
mutated_W[i], mutated_act[i] = mutation(genome_W,
|
347
|
-
genome_act,
|
348
|
-
activation_mutate_prob=activation_mutate_prob,
|
349
|
-
activation_add_prob=activation_mutate_add_prob,
|
350
|
-
activation_delete_prob=activation_mutate_delete_prob,
|
351
|
-
activation_change_prob=activation_mutate_change_prob,
|
352
|
-
weight_mutate_prob=weight_mutate_prob,
|
353
|
-
weight_mutate_threshold=weight_mutate_threshold,
|
354
|
-
genome_fitness=normalized_fitness[fitness_index],
|
355
|
-
activation_mutate_threshold=activation_mutate_threshold,
|
356
|
-
epsilon=epsilon
|
357
|
-
)
|
358
|
-
|
359
|
-
if bar_status: progress.update(1)
|
301
|
+
with mp.Pool() as pool:
|
302
|
+
process_func = partial(process_single, policy=policy, best_weight=best_weight,
|
303
|
+
best_activations=best_activations, good_weights=good_weights,
|
304
|
+
good_activations=good_activations, bad_weights=bad_weights,
|
305
|
+
bad_activations=bad_activations, best_fitness=best_fitness,
|
306
|
+
normalized_fitness=normalized_fitness, child_W=child_W,
|
307
|
+
child_act=child_act, mutated_W=mutated_W, mutated_act=mutated_act,
|
308
|
+
progress=progress, bar_status=bar_status,
|
309
|
+
cross_over_mode=cross_over_mode,
|
310
|
+
activation_selection_add_prob=activation_selection_add_prob,
|
311
|
+
activation_selection_change_prob=activation_selection_change_prob,
|
312
|
+
activation_selection_threshold=activation_selection_threshold,
|
313
|
+
bad_genomes_selection_prob=bad_genomes_selection_prob,
|
314
|
+
fitness_bias=fitness_bias,
|
315
|
+
epsilon=epsilon,
|
316
|
+
bad_genomes_mutation_prob=bad_genomes_mutation_prob,
|
317
|
+
activation_mutate_prob=activation_mutate_prob,
|
318
|
+
activation_mutate_add_prob=activation_mutate_add_prob,
|
319
|
+
activation_mutate_delete_prob=activation_mutate_delete_prob,
|
320
|
+
activation_mutate_change_prob=activation_mutate_change_prob,
|
321
|
+
weight_mutate_prob=weight_mutate_prob,
|
322
|
+
weight_mutate_threshold=weight_mutate_threshold,
|
323
|
+
activation_mutate_threshold=activation_mutate_threshold)
|
324
|
+
|
325
|
+
pool.map(process_func, range(len(bad_weights)))
|
360
326
|
|
361
327
|
child_W[0] = best_weight
|
362
328
|
child_act[0] = best_activations
|
@@ -401,6 +367,40 @@ def evolver(weights,
|
|
401
367
|
return weights, activation_potentiations
|
402
368
|
|
403
369
|
|
370
|
+
def process_single(i, policy, best_weight, best_activations, good_weights, good_activations,
|
371
|
+
bad_weights, bad_activations, best_fitness, normalized_fitness, child_W, child_act,
|
372
|
+
mutated_W, mutated_act, progress, bar_status, cross_over_mode,
|
373
|
+
activation_selection_add_prob, activation_selection_change_prob,
|
374
|
+
activation_selection_threshold, bad_genomes_selection_prob, fitness_bias,
|
375
|
+
epsilon, bad_genomes_mutation_prob, activation_mutate_prob,
|
376
|
+
activation_mutate_add_prob, activation_mutate_delete_prob,
|
377
|
+
activation_mutate_change_prob, weight_mutate_prob, weight_mutate_threshold,
|
378
|
+
activation_mutate_threshold):
|
379
|
+
if policy == 'aggressive':
|
380
|
+
first_parent_W = best_weight
|
381
|
+
first_parent_act = best_activations
|
382
|
+
elif policy == 'explorer':
|
383
|
+
first_parent_W = good_weights[i]
|
384
|
+
first_parent_act = good_activations[i]
|
385
|
+
else:
|
386
|
+
raise ValueError("policy parameter must be: 'aggressive' or 'explorer'")
|
387
|
+
|
388
|
+
second_parent_W, second_parent_act, s_i = second_parent_selection(good_weights, bad_weights, good_activations, bad_activations, bad_genomes_selection_prob)
|
389
|
+
child_W[i], child_act[i] = cross_over(first_parent_W,
|
390
|
+
second_parent_W,
|
391
|
+
first_parent_act,
|
392
|
+
second_parent_act,
|
393
|
+
cross_over_mode=cross_over_mode,
|
394
|
+
activation_selection_add_prob=activation_selection_add_prob,
|
395
|
+
activation_selection_change_prob=activation_selection_change_prob,
|
396
|
+
activation_selection_threshold=activation_selection_threshold,
|
397
|
+
bad_genomes_selection_prob=bad_genomes_selection_prob,
|
398
|
+
first_parent_fitness=best_fitness,
|
399
|
+
fitness_bias=fitness_bias,
|
400
|
+
second_parent_fitness=normalized_fitness[s_i],
|
401
|
+
epsilon=epsilon
|
402
|
+
)
|
403
|
+
|
404
404
|
def evaluate(x_population, weights, activation_potentiations):
|
405
405
|
"""
|
406
406
|
Evaluates the performance of a population of genomes, applying different activation functions
|
@@ -441,20 +441,20 @@ def evaluate(x_population, weights, activation_potentiations):
|
|
441
441
|
return result
|
442
442
|
|
443
443
|
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
444
|
+
def cross_over(first_parent_W,
|
445
|
+
second_parent_W,
|
446
|
+
first_parent_act,
|
447
|
+
second_parent_act,
|
448
|
+
cross_over_mode,
|
449
|
+
activation_selection_add_prob,
|
450
|
+
activation_selection_change_prob,
|
451
|
+
activation_selection_threshold,
|
452
|
+
bad_genomes_selection_prob,
|
453
|
+
first_parent_fitness,
|
454
|
+
second_parent_fitness,
|
455
|
+
fitness_bias,
|
456
|
+
epsilon):
|
457
|
+
"""
|
458
458
|
Performs a crossover operation on two sets of weights and activation functions.
|
459
459
|
This function combines two individuals (represented by their weights and activation functions)
|
460
460
|
to create a new individual by exchanging parts of their weight matrices and activation functions.
|
@@ -516,128 +516,131 @@ def cross_over(first_parent_W, second_parent_W, first_parent_act, second_parent_
|
|
516
516
|
fitness_bias=0.6,
|
517
517
|
epsilon=cp.finfo(float).eps
|
518
518
|
)
|
519
|
-
```
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
519
|
+
```
|
520
|
+
"""
|
521
|
+
|
522
|
+
### THE GIVEN GENOMES' WEIGHTS ARE RANDOMLY SELECTED AND COMBINED OVER A RANDOM RANGE. SIMILARLY, THEIR ACTIVATIONS ARE COMBINED. A NEW GENOME IS RETURNED WITH THE COMBINED WEIGHTS FIRST, FOLLOWED BY THE ACTIVATIONS:
|
523
|
+
|
524
|
+
start = 0
|
525
|
+
|
526
|
+
row_end = first_parent_W.shape[0]
|
527
|
+
col_end = first_parent_W.shape[1]
|
528
|
+
|
529
|
+
total_gene = row_end * col_end
|
530
|
+
half_of_gene = int(total_gene / 2)
|
531
|
+
|
532
|
+
decision = dominant_parent_selection(bad_genomes_selection_prob)
|
533
|
+
|
534
|
+
if decision == 'first_parent':
|
535
|
+
dominant_parent_W = cp.copy(first_parent_W)
|
536
|
+
dominant_parent_act = first_parent_act
|
537
|
+
|
538
|
+
undominant_parent_W = cp.copy(second_parent_W)
|
539
|
+
undominant_parent_act = second_parent_act
|
540
|
+
succes = second_parent_fitness + epsilon
|
541
|
+
|
542
|
+
elif decision == 'second_parent':
|
543
|
+
dominant_parent_W = cp.copy(second_parent_W)
|
544
|
+
dominant_parent_act = second_parent_act
|
545
|
+
|
546
|
+
undominant_parent_W = cp.copy(first_parent_W)
|
547
|
+
undominant_parent_act = first_parent_act
|
548
|
+
succes = first_parent_fitness + epsilon
|
549
|
+
|
550
|
+
while True:
|
551
|
+
|
552
|
+
row_cut_start = int(random.uniform(start, row_end))
|
553
|
+
col_cut_start = int(random.uniform(start, col_end))
|
554
|
+
|
555
|
+
row_cut_end = int(random.uniform(start, row_end))
|
556
|
+
col_cut_end = int(random.uniform(start, col_end))
|
557
|
+
|
558
|
+
if ((row_cut_end > row_cut_start) and
|
559
|
+
(col_cut_end > col_cut_start) and
|
560
|
+
(((row_cut_end + 1) - (row_cut_start + 1) * 2) + ((col_cut_end + 1) - (col_cut_start + 1) * 2) <= half_of_gene)):
|
561
|
+
break
|
562
|
+
|
563
|
+
selection_bias = random.uniform(0, 1)
|
564
|
+
|
565
|
+
if fitness_bias > selection_bias:
|
566
|
+
row_cut_start = math.floor(row_cut_start * succes)
|
567
|
+
row_cut_end = math.ceil(row_cut_end * succes)
|
568
|
+
|
569
|
+
col_cut_start = math.floor(col_cut_start * succes)
|
570
|
+
col_cut_end = math.ceil(col_cut_end * succes)
|
571
|
+
|
572
|
+
child_W = dominant_parent_W
|
573
|
+
|
574
|
+
if cross_over_mode == 'tpm':
|
575
|
+
child_W[row_cut_start:row_cut_end, col_cut_start:col_cut_end] = undominant_parent_W[row_cut_start:row_cut_end, col_cut_start:col_cut_end]
|
576
|
+
|
577
|
+
|
578
|
+
if isinstance(dominant_parent_act, str): dominant_parent_act = [dominant_parent_act]
|
579
|
+
if isinstance(undominant_parent_act, str): undominant_parent_act = [undominant_parent_act]
|
580
|
+
|
581
|
+
child_act = list(np.copy(dominant_parent_act))
|
582
|
+
|
583
|
+
activation_selection_add_prob = 1 - activation_selection_add_prob # if prob 0.8 (%80) then 1 - 0.8. Because 0-1 random number probably greater than 0.2
|
584
|
+
potential_activation_selection_add = random.uniform(0, 1)
|
585
|
+
|
586
|
+
if potential_activation_selection_add > activation_selection_add_prob:
|
587
|
+
|
588
|
+
threshold = abs(activation_selection_threshold / succes)
|
589
|
+
new_threshold = threshold
|
590
|
+
|
591
|
+
while True:
|
592
|
+
|
593
|
+
random_index = int(random.uniform(0, len(undominant_parent_act)-1))
|
594
|
+
random_undominant_activation = undominant_parent_act[random_index]
|
595
|
+
|
596
|
+
child_act.append(random_undominant_activation)
|
597
|
+
new_threshold += threshold
|
598
|
+
|
599
|
+
if len(dominant_parent_act) > new_threshold:
|
600
|
+
pass
|
601
|
+
|
602
|
+
else:
|
553
603
|
break
|
554
|
-
|
555
|
-
selection_bias = random.uniform(0, 1)
|
556
|
-
if fitness_bias > selection_bias:
|
557
|
-
row_cut_start = math.floor(row_cut_start * succes)
|
558
|
-
row_cut_end = math.ceil(row_cut_end * succes)
|
559
|
-
col_cut_start = math.floor(col_cut_start * succes)
|
560
|
-
col_cut_end = math.ceil(col_cut_end * succes)
|
561
|
-
|
562
|
-
child_W = cp.copy(dominant_parent_W)
|
563
|
-
|
564
|
-
if cross_over_mode == 'tpm':
|
565
|
-
threadsperblock = 256
|
566
|
-
blockspergrid = (total_gene + (threadsperblock - 1)) // threadsperblock
|
567
604
|
|
568
|
-
|
569
|
-
|
570
|
-
)
|
571
|
-
|
572
|
-
with concurrent.futures.ThreadPoolExecutor() as executor:
|
573
|
-
if isinstance(dominant_parent_act, str):
|
574
|
-
dominant_parent_act = [dominant_parent_act]
|
575
|
-
if isinstance(undominant_parent_act, str):
|
576
|
-
undominant_parent_act = [undominant_parent_act]
|
577
|
-
|
578
|
-
child_act = list(np.copy(dominant_parent_act))
|
605
|
+
activation_selection_change_prob = 1 - activation_selection_change_prob
|
606
|
+
potential_activation_selection_change_prob = random.uniform(0, 1)
|
579
607
|
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
random_index
|
591
|
-
)
|
592
|
-
)
|
593
|
-
new_threshold += threshold
|
594
|
-
|
595
|
-
for future in concurrent.futures.as_completed(futures):
|
596
|
-
child_act.append(future.result())
|
597
|
-
|
598
|
-
if random.uniform(0, 1) > (1 - activation_selection_change_prob):
|
599
|
-
threshold = abs(activation_selection_threshold / succes)
|
600
|
-
new_threshold = threshold
|
601
|
-
|
602
|
-
futures = []
|
603
|
-
while len(dominant_parent_act) > new_threshold:
|
604
|
-
random_index_undominant = int(random.uniform(0, len(undominant_parent_act)-1))
|
605
|
-
random_index_dominant = int(random.uniform(0, len(dominant_parent_act)-1))
|
606
|
-
futures.append(
|
607
|
-
executor.submit(
|
608
|
-
lambda u_idx, d_idx: (d_idx, undominant_parent_act[u_idx]),
|
609
|
-
random_index_undominant,
|
610
|
-
random_index_dominant
|
611
|
-
)
|
612
|
-
)
|
613
|
-
new_threshold += threshold
|
614
|
-
|
615
|
-
for future in concurrent.futures.as_completed(futures):
|
616
|
-
idx, val = future.result()
|
617
|
-
child_act[idx] = val
|
608
|
+
if potential_activation_selection_change_prob > activation_selection_change_prob:
|
609
|
+
|
610
|
+
threshold = abs(activation_selection_threshold / succes)
|
611
|
+
new_threshold = threshold
|
612
|
+
|
613
|
+
while True:
|
614
|
+
|
615
|
+
random_index_undominant = int(random.uniform(0, len(undominant_parent_act)-1))
|
616
|
+
random_index_dominant = int(random.uniform(0, len(dominant_parent_act)-1))
|
617
|
+
random_undominant_activation = undominant_parent_act[random_index_undominant]
|
618
618
|
|
619
|
-
|
619
|
+
child_act[random_index_dominant] = random_undominant_activation
|
620
|
+
new_threshold += threshold
|
620
621
|
|
622
|
+
if len(dominant_parent_act) > new_threshold:
|
623
|
+
pass
|
624
|
+
|
625
|
+
else:
|
626
|
+
break
|
621
627
|
|
622
|
-
|
623
|
-
def weight_mutation_kernel(weight, rows, cols, num_mutations, rng_states):
|
624
|
-
idx = cuda.grid(1)
|
625
|
-
if idx < num_mutations:
|
628
|
+
return child_W, child_act
|
626
629
|
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
630
|
+
|
631
|
+
def mutation(weight,
|
632
|
+
activations,
|
633
|
+
activation_mutate_prob,
|
634
|
+
activation_add_prob,
|
635
|
+
activation_delete_prob,
|
636
|
+
activation_change_prob,
|
637
|
+
weight_mutate_prob,
|
638
|
+
weight_mutate_threshold,
|
639
|
+
genome_fitness,
|
640
|
+
activation_mutate_threshold,
|
641
|
+
epsilon):
|
642
|
+
"""
|
643
|
+
Performs mutation on the given weight matrix and activation functions.
|
641
644
|
- The weight matrix is mutated by randomly changing its values based on the mutation probability.
|
642
645
|
- The activation functions are mutated by adding, removing, or replacing them with predefined probabilities.
|
643
646
|
|
@@ -679,81 +682,97 @@ def mutation(weight, activations, genome_fitness, weight_mutate_prob,
|
|
679
682
|
`activation_change_prob`).
|
680
683
|
- The mutation probabilities should be chosen carefully to balance exploration and exploitation during
|
681
684
|
the optimization process.
|
682
|
-
|
683
|
-
|
684
|
-
if isinstance(activations, str):
|
685
|
-
activations = [activations]
|
685
|
+
"""
|
686
686
|
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
threadsperblock = 256
|
699
|
-
blockspergrid = (num_mutations + (threadsperblock - 1)) // threadsperblock
|
700
|
-
|
701
|
-
rng_states = cuda.random.create_xoroshiro128p_states(threadsperblock * blockspergrid, seed=random.randint(0, 1000))
|
687
|
+
if isinstance(activations, str): activations = [activations]
|
688
|
+
|
689
|
+
weight_mutate_prob = 1 - weight_mutate_prob # if prob 0.8 (%80) then 1 - 0.8. Because 0-1 random number probably greater than 0.2
|
690
|
+
potential_weight_mutation = random.uniform(0, 1)
|
691
|
+
|
692
|
+
if potential_weight_mutation > weight_mutate_prob:
|
693
|
+
|
694
|
+
start = 0
|
695
|
+
row_end = weight.shape[0]
|
696
|
+
col_end = weight.shape[1]
|
702
697
|
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
with concurrent.futures.ThreadPoolExecutor() as executor:
|
747
|
-
probs = (activation_add_prob, activation_delete_prob, activation_change_prob)
|
748
|
-
process_func = partial(process_mutation, activations=activations,
|
749
|
-
all_acts=all_acts, probs=probs)
|
698
|
+
max_threshold = row_end * col_end
|
699
|
+
|
700
|
+
threshold = weight_mutate_threshold * genome_fitness
|
701
|
+
new_threshold = threshold
|
702
|
+
|
703
|
+
for _ in range(max_threshold):
|
704
|
+
|
705
|
+
selected_row = int(random.uniform(start, row_end))
|
706
|
+
selected_col = int(random.uniform(start, col_end))
|
707
|
+
|
708
|
+
weight[selected_row, selected_col] = random.uniform(-1, 1)
|
709
|
+
new_threshold += threshold
|
710
|
+
|
711
|
+
if max_threshold > new_threshold:
|
712
|
+
pass
|
713
|
+
|
714
|
+
else:
|
715
|
+
break
|
716
|
+
|
717
|
+
activation_mutate_prob = 1 - activation_mutate_prob
|
718
|
+
potential_activation_mutation = random.uniform(0, 1)
|
719
|
+
|
720
|
+
if potential_activation_mutation > activation_mutate_prob:
|
721
|
+
|
722
|
+
genome_fitness += epsilon
|
723
|
+
threshold = abs(activation_mutate_threshold / genome_fitness)
|
724
|
+
max_threshold = len(activations)
|
725
|
+
|
726
|
+
new_threshold = threshold
|
727
|
+
|
728
|
+
except_this = ['spiral', 'circular']
|
729
|
+
all_acts = [item for item in all_activations() if item not in except_this] # SPIRAL AND CIRCULAR ACTIVATION DISCARDED
|
730
|
+
|
731
|
+
activation_add_prob = 1 - activation_add_prob
|
732
|
+
activation_delete_prob = 1 - activation_delete_prob
|
733
|
+
activation_change_prob = 1 - activation_change_prob
|
734
|
+
|
735
|
+
for _ in range(max_threshold):
|
736
|
+
|
737
|
+
potential_activation_add_prob = random.uniform(0, 1)
|
738
|
+
potential_activation_delete_prob = random.uniform(0, 1)
|
739
|
+
potential_activation_change_prob = random.uniform(0, 1)
|
740
|
+
|
750
741
|
|
751
|
-
|
742
|
+
if potential_activation_delete_prob > activation_delete_prob and len(activations) > 1:
|
743
|
+
|
744
|
+
random_index = random.randint(0, len(activations) - 1)
|
745
|
+
activations.pop(random_index)
|
746
|
+
|
752
747
|
|
753
|
-
if
|
754
|
-
|
755
|
-
|
756
|
-
|
748
|
+
if potential_activation_add_prob > activation_add_prob:
|
749
|
+
|
750
|
+
try:
|
751
|
+
|
752
|
+
random_index_all_act = int(random.uniform(0, len(all_acts)-1))
|
753
|
+
activations.append(all_acts[random_index_all_act])
|
754
|
+
|
755
|
+
except:
|
756
|
+
|
757
|
+
activation = activations
|
758
|
+
activations = []
|
759
|
+
|
760
|
+
activations.append(activation)
|
761
|
+
activations.append(all_acts[int(random.uniform(0, len(all_acts)-1))])
|
762
|
+
|
763
|
+
if potential_activation_change_prob > activation_change_prob:
|
764
|
+
|
765
|
+
random_index_all_act = int(random.uniform(0, len(all_acts)-1))
|
766
|
+
random_index_genom_act = int(random.uniform(0, len(activations)-1))
|
767
|
+
|
768
|
+
activations[random_index_genom_act] = all_acts[random_index_all_act]
|
769
|
+
|
770
|
+
new_threshold += threshold
|
771
|
+
|
772
|
+
if max_threshold > new_threshold: pass
|
773
|
+
else: break
|
774
|
+
|
775
|
+
return weight, activations
|
757
776
|
|
758
777
|
|
759
778
|
def second_parent_selection(good_weights, bad_weights, good_activations, bad_activations, bad_genomes_selection_prob):
|
File without changes
|
File without changes
|