pyerualjetwork 4.3.8.dev4__py3-none-any.whl → 4.3.8.dev6__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.
@@ -1,4 +1,4 @@
1
- __version__ = "4.3.8dev4"
1
+ __version__ = "4.3.8dev6"
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.dev4
3
+ Version: 4.3.8.dev6
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=tTsCaO21gpTHXANBa1BxXVjtXNtwRBZbEgajdSreUyc,643
1
+ pyerualjetwork/__init__.py,sha256=olCEbcpfxR8QpQvxMzMKJtKcpSevTnsDX7lI96-QHyY,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=Pw-QCXxnDb7n0onhtNr3b3rW1p44D68garrl-OJdouQ,655
21
+ pyerualjetwork_afterburner/__init__.py,sha256=ziEOwTxIO9tl2N63bre_zkIPjmpQ-3iCuRNkFJO0YS4,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=VbeaoKlqquKDLcRaQHdoERvoxzO75Day0RgJtOSU9wk,38898
37
+ pyerualjetwork_afterburner/planeat_cuda.py,sha256=XS-latsokCvxvUbbGRALen35w3JJQJoIWIeFFtTl_7w,39942
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.dev4.dist-info/METADATA,sha256=4Gq7RqhoiGuEirXF6ZFFgs2fyZnZm46lQxj5IMsO9JU,8384
42
- pyerualjetwork-4.3.8.dev4.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
43
- pyerualjetwork-4.3.8.dev4.dist-info/top_level.txt,sha256=uK64ge08QQoPuXM3aiRVPgiQQtl8Fxm2-HieIut5Lwo,42
44
- pyerualjetwork-4.3.8.dev4.dist-info/RECORD,,
41
+ pyerualjetwork-4.3.8.dev6.dist-info/METADATA,sha256=Kg8zdJAToUWOeWr9cBYG_wDFzLykd6BTn_diSLmgaQc,8384
42
+ pyerualjetwork-4.3.8.dev6.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
43
+ pyerualjetwork-4.3.8.dev6.dist-info/top_level.txt,sha256=uK64ge08QQoPuXM3aiRVPgiQQtl8Fxm2-HieIut5Lwo,42
44
+ pyerualjetwork-4.3.8.dev6.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
- __version__ = "4.3.8dev4-afterburner"
1
+ __version__ = "4.3.8dev6-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
- from numba import cuda
20
- import concurrent.futures
19
+ import multiprocessing as mp
21
20
  from functools import partial
22
21
 
23
22
 
@@ -299,64 +298,30 @@ def evolver(weights,
299
298
  mutated_W = cp.copy(bad_weights)
300
299
  mutated_act = bad_activations.copy()
301
300
 
302
-
303
- for i in range(len(bad_weights)):
304
-
305
- if policy == 'aggressive':
306
- first_parent_W = best_weight
307
- first_parent_act = best_activations
308
-
309
- elif policy == 'explorer':
310
- first_parent_W = good_weights[i]
311
- first_parent_act = good_activations[i]
312
-
313
- else: raise ValueError("policy parameter must be: 'aggressive' or 'explorer'")
314
-
315
- second_parent_W, second_parent_act, s_i = second_parent_selection(good_weights, bad_weights, good_activations, bad_activations, bad_genomes_selection_prob)
316
-
317
- child_W[i], child_act[i] = cross_over(first_parent_W,
318
- second_parent_W,
319
- first_parent_act,
320
- second_parent_act,
321
- cross_over_mode=cross_over_mode,
322
- activation_selection_add_prob=activation_selection_add_prob,
323
- activation_selection_change_prob=activation_selection_change_prob,
324
- activation_selection_threshold=activation_selection_threshold,
325
- bad_genomes_selection_prob=bad_genomes_selection_prob,
326
- first_parent_fitness=best_fitness,
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
+ cross_over_mode=cross_over_mode,
309
+ activation_selection_add_prob=activation_selection_add_prob,
310
+ activation_selection_change_prob=activation_selection_change_prob,
311
+ activation_selection_threshold=activation_selection_threshold,
312
+ bad_genomes_selection_prob=bad_genomes_selection_prob,
313
+ fitness_bias=fitness_bias,
314
+ epsilon=epsilon,
315
+ bad_genomes_mutation_prob=bad_genomes_mutation_prob,
316
+ activation_mutate_prob=activation_mutate_prob,
317
+ activation_mutate_add_prob=activation_mutate_add_prob,
318
+ activation_mutate_delete_prob=activation_mutate_delete_prob,
319
+ activation_mutate_change_prob=activation_mutate_change_prob,
320
+ weight_mutate_prob=weight_mutate_prob,
321
+ weight_mutate_threshold=weight_mutate_threshold,
322
+ activation_mutate_threshold=activation_mutate_threshold)
323
+
324
+ pool.map(process_func, range(len(bad_weights)))
360
325
 
361
326
  child_W[0] = best_weight
362
327
  child_act[0] = best_activations
@@ -401,6 +366,63 @@ def evolver(weights,
401
366
  return weights, activation_potentiations
402
367
 
403
368
 
369
+ def process_single(i, policy, best_weight, best_activations, good_weights, good_activations,
370
+ bad_weights, bad_activations, best_fitness, normalized_fitness, child_W, child_act,
371
+ mutated_W, mutated_act, cross_over_mode,
372
+ activation_selection_add_prob, activation_selection_change_prob,
373
+ activation_selection_threshold, bad_genomes_selection_prob, fitness_bias,
374
+ epsilon, bad_genomes_mutation_prob, activation_mutate_prob,
375
+ activation_mutate_add_prob, activation_mutate_delete_prob,
376
+ activation_mutate_change_prob, weight_mutate_prob, weight_mutate_threshold,
377
+ activation_mutate_threshold):
378
+ if policy == 'aggressive':
379
+ first_parent_W = best_weight
380
+ first_parent_act = best_activations
381
+ elif policy == 'explorer':
382
+ first_parent_W = good_weights[i]
383
+ first_parent_act = good_activations[i]
384
+ else:
385
+ raise ValueError("policy parameter must be: 'aggressive' or 'explorer'")
386
+
387
+ second_parent_W, second_parent_act, s_i = second_parent_selection(good_weights, bad_weights, good_activations, bad_activations, bad_genomes_selection_prob)
388
+ child_W[i], child_act[i] = cross_over(first_parent_W,
389
+ second_parent_W,
390
+ first_parent_act,
391
+ second_parent_act,
392
+ cross_over_mode=cross_over_mode,
393
+ activation_selection_add_prob=activation_selection_add_prob,
394
+ activation_selection_change_prob=activation_selection_change_prob,
395
+ activation_selection_threshold=activation_selection_threshold,
396
+ bad_genomes_selection_prob=bad_genomes_selection_prob,
397
+ first_parent_fitness=best_fitness,
398
+ fitness_bias=fitness_bias,
399
+ second_parent_fitness=normalized_fitness[s_i],
400
+ epsilon=epsilon
401
+ )
402
+
403
+ mutation_prob = random.uniform(0, 1)
404
+ if mutation_prob > bad_genomes_mutation_prob:
405
+ genome_W = good_weights[i]
406
+ genome_act = good_activations[i]
407
+ fitness_index = int(len(bad_weights) / 2 + i)
408
+ else:
409
+ genome_W = bad_weights[i]
410
+ genome_act = bad_activations[i]
411
+ fitness_index = i
412
+
413
+ mutated_W[i], mutated_act[i] = mutation(genome_W,
414
+ genome_act,
415
+ activation_mutate_prob=activation_mutate_prob,
416
+ activation_add_prob=activation_mutate_add_prob,
417
+ activation_delete_prob=activation_mutate_delete_prob,
418
+ activation_change_prob=activation_mutate_change_prob,
419
+ weight_mutate_prob=weight_mutate_prob,
420
+ weight_mutate_threshold=weight_mutate_threshold,
421
+ genome_fitness=normalized_fitness[fitness_index],
422
+ activation_mutate_threshold=activation_mutate_threshold,
423
+ epsilon=epsilon
424
+ )
425
+
404
426
  def evaluate(x_population, weights, activation_potentiations):
405
427
  """
406
428
  Evaluates the performance of a population of genomes, applying different activation functions
@@ -441,20 +463,20 @@ def evaluate(x_population, weights, activation_potentiations):
441
463
  return result
442
464
 
443
465
 
444
- @cuda.jit
445
- def crossover_kernel(undominant_W, child_W, row_start, row_end, col_start, col_end):
446
- idx = cuda.grid(1)
447
- if idx < (row_end - row_start) * (col_end - col_start):
448
- row = row_start + (idx // (col_end - col_start))
449
- col = col_start + (idx % (col_end - col_start))
450
- if row < row_end and col < col_end:
451
- child_W[row, col] = undominant_W[row, col]
452
-
453
- def cross_over(first_parent_W, second_parent_W, first_parent_act, second_parent_act,
454
- first_parent_fitness, second_parent_fitness, bad_genomes_selection_prob,
455
- fitness_bias, cross_over_mode, activation_selection_add_prob,
456
- activation_selection_change_prob, activation_selection_threshold, epsilon=1e-10):
457
- """
466
+ def cross_over(first_parent_W,
467
+ second_parent_W,
468
+ first_parent_act,
469
+ second_parent_act,
470
+ cross_over_mode,
471
+ activation_selection_add_prob,
472
+ activation_selection_change_prob,
473
+ activation_selection_threshold,
474
+ bad_genomes_selection_prob,
475
+ first_parent_fitness,
476
+ second_parent_fitness,
477
+ fitness_bias,
478
+ epsilon):
479
+ """
458
480
  Performs a crossover operation on two sets of weights and activation functions.
459
481
  This function combines two individuals (represented by their weights and activation functions)
460
482
  to create a new individual by exchanging parts of their weight matrices and activation functions.
@@ -516,128 +538,131 @@ def cross_over(first_parent_W, second_parent_W, first_parent_act, second_parent_
516
538
  fitness_bias=0.6,
517
539
  epsilon=cp.finfo(float).eps
518
540
  )
519
- ```"""
520
-
521
- d_first_parent_W = cp.copy(first_parent_W)
522
- d_second_parent_W = cp.copy(second_parent_W)
523
-
524
- row_end = first_parent_W.shape[0]
525
- col_end = first_parent_W.shape[1]
526
- total_gene = row_end * col_end
527
- half_of_gene = int(total_gene / 2)
528
-
529
- decision = dominant_parent_selection(bad_genomes_selection_prob)
530
- if decision == 'first_parent':
531
- dominant_parent_W = cp.copy(d_first_parent_W)
532
- dominant_parent_act = first_parent_act
533
- undominant_parent_W = cp.copy(d_second_parent_W)
534
- undominant_parent_act = second_parent_act
535
- succes = second_parent_fitness + epsilon
536
- else:
537
- dominant_parent_W = cp.copy(d_second_parent_W)
538
- dominant_parent_act = second_parent_act
539
- undominant_parent_W = cp.copy(d_first_parent_W)
540
- undominant_parent_act = first_parent_act
541
- succes = first_parent_fitness + epsilon
542
-
543
- while True:
544
- row_cut_start = int(random.uniform(0, row_end))
545
- col_cut_start = int(random.uniform(0, col_end))
546
- row_cut_end = int(random.uniform(0, row_end))
547
- col_cut_end = int(random.uniform(0, col_end))
548
-
549
- if ((row_cut_end > row_cut_start) and
550
- (col_cut_end > col_cut_start) and
551
- (((row_cut_end + 1) - (row_cut_start + 1) * 2) +
552
- ((col_cut_end + 1) - (col_cut_start + 1) * 2) <= half_of_gene)):
541
+ ```
542
+ """
543
+
544
+ ### 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:
545
+
546
+ start = 0
547
+
548
+ row_end = first_parent_W.shape[0]
549
+ col_end = first_parent_W.shape[1]
550
+
551
+ total_gene = row_end * col_end
552
+ half_of_gene = int(total_gene / 2)
553
+
554
+ decision = dominant_parent_selection(bad_genomes_selection_prob)
555
+
556
+ if decision == 'first_parent':
557
+ dominant_parent_W = cp.copy(first_parent_W)
558
+ dominant_parent_act = first_parent_act
559
+
560
+ undominant_parent_W = cp.copy(second_parent_W)
561
+ undominant_parent_act = second_parent_act
562
+ succes = second_parent_fitness + epsilon
563
+
564
+ elif decision == 'second_parent':
565
+ dominant_parent_W = cp.copy(second_parent_W)
566
+ dominant_parent_act = second_parent_act
567
+
568
+ undominant_parent_W = cp.copy(first_parent_W)
569
+ undominant_parent_act = first_parent_act
570
+ succes = first_parent_fitness + epsilon
571
+
572
+ while True:
573
+
574
+ row_cut_start = int(random.uniform(start, row_end))
575
+ col_cut_start = int(random.uniform(start, col_end))
576
+
577
+ row_cut_end = int(random.uniform(start, row_end))
578
+ col_cut_end = int(random.uniform(start, col_end))
579
+
580
+ if ((row_cut_end > row_cut_start) and
581
+ (col_cut_end > col_cut_start) and
582
+ (((row_cut_end + 1) - (row_cut_start + 1) * 2) + ((col_cut_end + 1) - (col_cut_start + 1) * 2) <= half_of_gene)):
583
+ break
584
+
585
+ selection_bias = random.uniform(0, 1)
586
+
587
+ if fitness_bias > selection_bias:
588
+ row_cut_start = math.floor(row_cut_start * succes)
589
+ row_cut_end = math.ceil(row_cut_end * succes)
590
+
591
+ col_cut_start = math.floor(col_cut_start * succes)
592
+ col_cut_end = math.ceil(col_cut_end * succes)
593
+
594
+ child_W = dominant_parent_W
595
+
596
+ if cross_over_mode == 'tpm':
597
+ 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]
598
+
599
+
600
+ if isinstance(dominant_parent_act, str): dominant_parent_act = [dominant_parent_act]
601
+ if isinstance(undominant_parent_act, str): undominant_parent_act = [undominant_parent_act]
602
+
603
+ child_act = list(np.copy(dominant_parent_act))
604
+
605
+ 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
606
+ potential_activation_selection_add = random.uniform(0, 1)
607
+
608
+ if potential_activation_selection_add > activation_selection_add_prob:
609
+
610
+ threshold = abs(activation_selection_threshold / succes)
611
+ new_threshold = threshold
612
+
613
+ while True:
614
+
615
+ random_index = int(random.uniform(0, len(undominant_parent_act)-1))
616
+ random_undominant_activation = undominant_parent_act[random_index]
617
+
618
+ child_act.append(random_undominant_activation)
619
+ new_threshold += threshold
620
+
621
+ if len(dominant_parent_act) > new_threshold:
622
+ pass
623
+
624
+ else:
553
625
  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
626
 
568
- crossover_kernel[blockspergrid, threadsperblock](undominant_parent_W, child_W,
569
- row_cut_start, row_cut_end, col_cut_start, col_cut_end
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))
627
+ activation_selection_change_prob = 1 - activation_selection_change_prob
628
+ potential_activation_selection_change_prob = random.uniform(0, 1)
579
629
 
580
- if random.uniform(0, 1) > (1 - activation_selection_add_prob):
581
- threshold = abs(activation_selection_threshold / succes)
582
- new_threshold = threshold
583
-
584
- futures = []
585
- while len(dominant_parent_act) > new_threshold:
586
- random_index = int(random.uniform(0, len(undominant_parent_act)-1))
587
- futures.append(
588
- executor.submit(
589
- lambda idx: undominant_parent_act[idx],
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
630
+ if potential_activation_selection_change_prob > activation_selection_change_prob:
631
+
632
+ threshold = abs(activation_selection_threshold / succes)
633
+ new_threshold = threshold
634
+
635
+ while True:
636
+
637
+ random_index_undominant = int(random.uniform(0, len(undominant_parent_act)-1))
638
+ random_index_dominant = int(random.uniform(0, len(dominant_parent_act)-1))
639
+ random_undominant_activation = undominant_parent_act[random_index_undominant]
618
640
 
619
- return child_W, child_act
641
+ child_act[random_index_dominant] = random_undominant_activation
642
+ new_threshold += threshold
620
643
 
644
+ if len(dominant_parent_act) > new_threshold:
645
+ pass
646
+
647
+ else:
648
+ break
621
649
 
622
- @cuda.jit
623
- def weight_mutation_kernel(weight, rows, cols, num_mutations, rng_states):
624
- idx = cuda.grid(1)
625
- if idx < num_mutations:
650
+ return child_W, child_act
626
651
 
627
- row = int(cuda.random.xoroshiro128p_uniform_float32(rng_states, idx) * rows)
628
- col = int(cuda.random.xoroshiro128p_uniform_float32(rng_states, idx) * cols)
629
- mutation_value = -1.0 + 2.0 * cuda.random.xoroshiro128p_uniform_float32(rng_states, idx)
630
-
631
- if row < rows and col < cols:
632
- weight[row, col] = mutation_value
633
-
634
- def mutation(weight, activations, genome_fitness, weight_mutate_prob,
635
- weight_mutate_threshold, activation_mutate_prob,
636
- activation_mutate_threshold, activation_add_prob,
637
- activation_delete_prob, activation_change_prob,
638
- epsilon=1e-10):
639
- """
640
- Performs mutation on the given weight matrix and activation functions.
652
+
653
+ def mutation(weight,
654
+ activations,
655
+ activation_mutate_prob,
656
+ activation_add_prob,
657
+ activation_delete_prob,
658
+ activation_change_prob,
659
+ weight_mutate_prob,
660
+ weight_mutate_threshold,
661
+ genome_fitness,
662
+ activation_mutate_threshold,
663
+ epsilon):
664
+ """
665
+ Performs mutation on the given weight matrix and activation functions.
641
666
  - The weight matrix is mutated by randomly changing its values based on the mutation probability.
642
667
  - The activation functions are mutated by adding, removing, or replacing them with predefined probabilities.
643
668
 
@@ -679,81 +704,97 @@ def mutation(weight, activations, genome_fitness, weight_mutate_prob,
679
704
  `activation_change_prob`).
680
705
  - The mutation probabilities should be chosen carefully to balance exploration and exploitation during
681
706
  the optimization process.
682
- """
683
-
684
- if isinstance(activations, str):
685
- activations = [activations]
707
+ """
686
708
 
687
- weight_mutate_prob = 1 - weight_mutate_prob
688
- if random.uniform(0, 1) > weight_mutate_prob:
689
- # GPU'ya veri transferi
690
- d_weight = cp.copy(weight)
691
-
692
- row_end = weight.shape[0]
693
- col_end = weight.shape[1]
694
- max_threshold = row_end * col_end
695
- threshold = weight_mutate_threshold * genome_fitness
696
- num_mutations = int(min(max_threshold, threshold))
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))
709
+ if isinstance(activations, str): activations = [activations]
710
+
711
+ 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
712
+ potential_weight_mutation = random.uniform(0, 1)
713
+
714
+ if potential_weight_mutation > weight_mutate_prob:
715
+
716
+ start = 0
717
+ row_end = weight.shape[0]
718
+ col_end = weight.shape[1]
702
719
 
703
- weight_mutation_kernel[blockspergrid, threadsperblock](
704
- d_weight, row_end, col_end, num_mutations, rng_states
705
- )
706
-
707
- activation_mutate_prob = 1 - activation_mutate_prob
708
- if random.uniform(0, 1) > activation_mutate_prob:
709
- genome_fitness += epsilon
710
- threshold = abs(activation_mutate_threshold / genome_fitness)
711
- max_threshold = len(activations)
712
-
713
- except_this = ['spiral', 'circular']
714
- all_acts = [item for item in all_activations() if item not in except_this]
715
-
716
- activation_add_prob = 1 - activation_add_prob
717
- activation_delete_prob = 1 - activation_delete_prob
718
- activation_change_prob = 1 - activation_change_prob
719
-
720
- def process_mutation(_, activations, all_acts, probs):
721
- """Tek bir mutasyon işlemi için yardımcı fonksiyon"""
722
- add_prob, delete_prob, change_prob = probs
723
- local_activations = activations.copy()
724
-
725
- if random.uniform(0, 1) > delete_prob and len(local_activations) > 1:
726
- random_index = random.randint(0, len(local_activations) - 1)
727
- local_activations.pop(random_index)
728
-
729
- if random.uniform(0, 1) > add_prob:
730
- try:
731
- random_index_all_act = int(random.uniform(0, len(all_acts)-1))
732
- local_activations.append(all_acts[random_index_all_act])
733
- except:
734
- activation = local_activations[0]
735
- local_activations = [activation]
736
- local_activations.append(all_acts[int(random.uniform(0, len(all_acts)-1))])
737
-
738
- if random.uniform(0, 1) > change_prob:
739
- random_index_all_act = int(random.uniform(0, len(all_acts)-1))
740
- random_index_genom_act = int(random.uniform(0, len(local_activations)-1))
741
- local_activations[random_index_genom_act] = all_acts[random_index_all_act]
742
-
743
- return local_activations
744
-
745
- num_iterations = int(min(max_threshold, threshold))
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)
720
+ max_threshold = row_end * col_end
721
+
722
+ threshold = weight_mutate_threshold * genome_fitness
723
+ new_threshold = threshold
724
+
725
+ for _ in range(max_threshold):
726
+
727
+ selected_row = int(random.uniform(start, row_end))
728
+ selected_col = int(random.uniform(start, col_end))
729
+
730
+ weight[selected_row, selected_col] = random.uniform(-1, 1)
731
+ new_threshold += threshold
732
+
733
+ if max_threshold > new_threshold:
734
+ pass
735
+
736
+ else:
737
+ break
738
+
739
+ activation_mutate_prob = 1 - activation_mutate_prob
740
+ potential_activation_mutation = random.uniform(0, 1)
741
+
742
+ if potential_activation_mutation > activation_mutate_prob:
743
+
744
+ genome_fitness += epsilon
745
+ threshold = abs(activation_mutate_threshold / genome_fitness)
746
+ max_threshold = len(activations)
747
+
748
+ new_threshold = threshold
749
+
750
+ except_this = ['spiral', 'circular']
751
+ all_acts = [item for item in all_activations() if item not in except_this] # SPIRAL AND CIRCULAR ACTIVATION DISCARDED
752
+
753
+ activation_add_prob = 1 - activation_add_prob
754
+ activation_delete_prob = 1 - activation_delete_prob
755
+ activation_change_prob = 1 - activation_change_prob
756
+
757
+ for _ in range(max_threshold):
758
+
759
+ potential_activation_add_prob = random.uniform(0, 1)
760
+ potential_activation_delete_prob = random.uniform(0, 1)
761
+ potential_activation_change_prob = random.uniform(0, 1)
762
+
750
763
 
751
- future_results = list(executor.map(process_func, range(num_iterations)))
764
+ if potential_activation_delete_prob > activation_delete_prob and len(activations) > 1:
765
+
766
+ random_index = random.randint(0, len(activations) - 1)
767
+ activations.pop(random_index)
768
+
752
769
 
753
- if future_results:
754
- activations = future_results[-1]
755
-
756
- return weight, activations
770
+ if potential_activation_add_prob > activation_add_prob:
771
+
772
+ try:
773
+
774
+ random_index_all_act = int(random.uniform(0, len(all_acts)-1))
775
+ activations.append(all_acts[random_index_all_act])
776
+
777
+ except:
778
+
779
+ activation = activations
780
+ activations = []
781
+
782
+ activations.append(activation)
783
+ activations.append(all_acts[int(random.uniform(0, len(all_acts)-1))])
784
+
785
+ if potential_activation_change_prob > activation_change_prob:
786
+
787
+ random_index_all_act = int(random.uniform(0, len(all_acts)-1))
788
+ random_index_genom_act = int(random.uniform(0, len(activations)-1))
789
+
790
+ activations[random_index_genom_act] = all_acts[random_index_all_act]
791
+
792
+ new_threshold += threshold
793
+
794
+ if max_threshold > new_threshold: pass
795
+ else: break
796
+
797
+ return weight, activations
757
798
 
758
799
 
759
800
  def second_parent_selection(good_weights, bad_weights, good_activations, bad_activations, bad_genomes_selection_prob):