pyerualjetwork 4.2.6b8__py3-none-any.whl → 4.2.7__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/planeat.py +102 -84
- pyerualjetwork/planeat_cuda.py +99 -78
- {pyerualjetwork-4.2.6b8.dist-info → pyerualjetwork-4.2.7.dist-info}/METADATA +1 -1
- {pyerualjetwork-4.2.6b8.dist-info → pyerualjetwork-4.2.7.dist-info}/RECORD +7 -7
- {pyerualjetwork-4.2.6b8.dist-info → pyerualjetwork-4.2.7.dist-info}/WHEEL +0 -0
- {pyerualjetwork-4.2.6b8.dist-info → pyerualjetwork-4.2.7.dist-info}/top_level.txt +0 -0
pyerualjetwork/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "4.2.
|
1
|
+
__version__ = "4.2.7"
|
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__):
|
pyerualjetwork/planeat.py
CHANGED
@@ -81,18 +81,19 @@ def evolver(weights,
|
|
81
81
|
bad_genomes_selection_prob=None,
|
82
82
|
bar_status=True,
|
83
83
|
strategy='normal_selective',
|
84
|
-
bad_genomes_mutation_prob=None,
|
85
|
-
|
86
|
-
|
87
|
-
cross_over_mode='tpm',
|
84
|
+
bad_genomes_mutation_prob=None,
|
85
|
+
fitness_bias=1,
|
86
|
+
cross_over_mode='tpm',
|
88
87
|
activation_mutate_add_prob=0.5,
|
89
88
|
activation_mutate_delete_prob=0.5,
|
90
|
-
activation_mutate_change_prob=0.5,
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
activation_mutate_change_prob=0.5,
|
90
|
+
activation_selection_add_prob=0.7,
|
91
|
+
activation_selection_change_prob=0.5,
|
92
|
+
activation_selection_threshold=2,
|
93
|
+
activation_mutate_prob=1,
|
94
|
+
activation_mutate_threshold=2,
|
95
|
+
weight_mutate_threshold=16,
|
96
|
+
weight_mutate_prob=1,
|
96
97
|
dtype=np.float32):
|
97
98
|
"""
|
98
99
|
Applies the evolving process of a population of genomes using selection, crossover, mutation, and activation function potentiation.
|
@@ -138,21 +139,21 @@ def evolver(weights,
|
|
138
139
|
|
139
140
|
Default: 'aggressive'.
|
140
141
|
|
141
|
-
fitness_bias (float, optional): Fitness bias must be a probability value between 0 and 1 that determines the effect of fitness on the crossover process. Default:
|
142
|
+
fitness_bias (float, optional): Fitness bias must be a probability value between 0 and 1 that determines the effect of fitness on the crossover process. Default: 1.
|
142
143
|
|
143
144
|
bad_genomes_mutation_prob (float, optional): The probability of applying mutation to the bad genomes.
|
144
145
|
Must be in the range [0, 1]. Also affects the mutation probability of the best genomes inversely.
|
145
146
|
For example, a value of 0.7 for bad genomes implies 0.3 for best genomes. Default: Determined by `policy`.
|
146
147
|
|
147
148
|
activation_mutate_prob (float, optional): The probability of applying mutation to the activation functions.
|
148
|
-
Must be in the range [0, 1]. Default is
|
149
|
+
Must be in the range [0, 1]. Default is 1 (%100).
|
149
150
|
|
150
151
|
cross_over_mode (str, optional): Specifies the crossover method to use. Options:
|
151
152
|
- 'tpm': Two-Point Matrix Crossover.
|
152
153
|
Default is 'tpm'.
|
153
154
|
|
154
155
|
activation_mutate_add_prob (float, optional): The probability of adding a new activation function to the genome for mutation.
|
155
|
-
Must be in the range [0, 1]. Default is 0.
|
156
|
+
Must be in the range [0, 1]. Default is 0.7.
|
156
157
|
|
157
158
|
activation_mutate_delete_prob (float, optional): The probability of deleting an existing activation function
|
158
159
|
from the genome for mutation. Must be in the range [0, 1]. Default is 0.5.
|
@@ -161,21 +162,21 @@ def evolver(weights,
|
|
161
162
|
Must be in the range [0, 1]. Default is 0.5.
|
162
163
|
|
163
164
|
weight_mutate_prob (float, optional): The probability of mutating a weight in the genome.
|
164
|
-
Must be in the range [0, 1]. Default is 1.
|
165
|
+
Must be in the range [0, 1]. Default is 1 (%100).
|
165
166
|
|
166
|
-
|
167
|
-
only a single weight will be mutated during each mutation process. If the value is half of the result,
|
168
|
-
two weights will be mutated. WARNING: If you don't understand, do NOT change this value. Default is 32.
|
167
|
+
weight_mutate_threshold (int): Determines max how much weight mutaiton operation applying. (Function automaticly determines to min) Default: 16
|
169
168
|
|
170
169
|
activation_selection_add_prob (float, optional): The probability of adding an existing activation function for crossover.
|
171
|
-
Must be in the range [0, 1]. Default is 0.
|
170
|
+
Must be in the range [0, 1]. Default is 0.5. (WARNING! Higher values increase complexity. For faster training, increase this value.)
|
172
171
|
|
173
172
|
activation_selection_change_prob (float, optional): The probability of changing an activation function in the genome for crossover.
|
174
|
-
Must be in the range [0, 1]. Default is 0.
|
173
|
+
Must be in the range [0, 1]. Default is 0.5.
|
175
174
|
|
176
|
-
|
175
|
+
activation_mutate_threshold (int, optional): Determines max how much activation mutaiton operation applying. (Function automaticly determines to min) Default: 2
|
176
|
+
|
177
|
+
activation_selection_threshold (int, optional): Determines max how much activaton transferable to child from undominant parent. (Function automaticly determines to min) Default: 2
|
177
178
|
|
178
|
-
dtype (numpy.dtype): Data type for the arrays. Default: np.float32.
|
179
|
+
dtype (numpy.dtype, optional): Data type for the arrays. Default: np.float32.
|
179
180
|
Example: np.float64 or np.float16 [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not recommended!].
|
180
181
|
|
181
182
|
Raises:
|
@@ -223,17 +224,14 @@ def evolver(weights,
|
|
223
224
|
if strategy == 'normal_selective':
|
224
225
|
if bad_genomes_mutation_prob is None: bad_genomes_mutation_prob = 0.7 # EFFECTS MUTATION
|
225
226
|
if bad_genomes_selection_prob is None: bad_genomes_selection_prob = 0.25 # EFFECTS CROSS-OVER
|
226
|
-
|
227
|
-
|
227
|
+
|
228
228
|
elif strategy == 'more_selective':
|
229
229
|
if bad_genomes_mutation_prob is None: bad_genomes_mutation_prob = 0.85 # EFFECTS MUTATION
|
230
230
|
if bad_genomes_selection_prob is None: bad_genomes_selection_prob = 0.1 # EFFECTS CROSS-OVER
|
231
|
-
if fitness_bias is None: fitness_bias = 0.7 # The pressure applied by FITNESS to the CROSS-OVER
|
232
231
|
|
233
232
|
elif strategy == 'less_selective':
|
234
233
|
if bad_genomes_mutation_prob is None: bad_genomes_mutation_prob = 0.6 # EFFECTS MUTATION
|
235
234
|
if bad_genomes_selection_prob is None: bad_genomes_selection_prob = 0.5 # EFFECTS CROSS-OVER
|
236
|
-
if fitness_bias is None: fitness_bias = 0.3 # The pressure applied by FITNESS to the CROSS-OVER
|
237
235
|
|
238
236
|
else:
|
239
237
|
raise ValueError("strategy parameter must be: 'normal_selective' or 'more_selective' or 'less_selective'")
|
@@ -250,11 +248,11 @@ def evolver(weights,
|
|
250
248
|
if fitness_bias < 0 or fitness_bias > 1: raise ValueError("fitness_bias value must be a number between 0 and 1.")
|
251
249
|
|
252
250
|
if bad_genomes_mutation_prob is not None:
|
253
|
-
if
|
251
|
+
if bad_genomes_mutation_prob < 0 or bad_genomes_mutation_prob > 1:
|
254
252
|
raise ValueError("bad_genomes_mutation_prob parameter must be float and 0-1 range")
|
255
253
|
|
256
254
|
if activation_mutate_prob is not None:
|
257
|
-
if
|
255
|
+
if activation_mutate_prob < 0 or activation_mutate_prob > 1:
|
258
256
|
raise ValueError("activation_mutate_prob parameter must be float and 0-1 range")
|
259
257
|
|
260
258
|
if len(fitness) % 2 == 0:
|
@@ -321,7 +319,7 @@ def evolver(weights,
|
|
321
319
|
cross_over_mode=cross_over_mode,
|
322
320
|
activation_selection_add_prob=activation_selection_add_prob,
|
323
321
|
activation_selection_change_prob=activation_selection_change_prob,
|
324
|
-
|
322
|
+
activation_selection_threshold=activation_selection_threshold,
|
325
323
|
bad_genomes_selection_prob=bad_genomes_selection_prob,
|
326
324
|
first_parent_fitness=best_fitness,
|
327
325
|
fitness_bias=fitness_bias,
|
@@ -350,8 +348,10 @@ def evolver(weights,
|
|
350
348
|
activation_delete_prob=activation_mutate_delete_prob,
|
351
349
|
activation_change_prob=activation_mutate_change_prob,
|
352
350
|
weight_mutate_prob=weight_mutate_prob,
|
353
|
-
|
354
|
-
genome_fitness=normalized_fitness[fitness_index]
|
351
|
+
weight_mutate_threshold=weight_mutate_threshold,
|
352
|
+
genome_fitness=normalized_fitness[fitness_index],
|
353
|
+
activation_mutate_threshold=activation_mutate_threshold,
|
354
|
+
epsilon=epsilon
|
355
355
|
)
|
356
356
|
|
357
357
|
if bar_status: progress.update(1)
|
@@ -375,15 +375,16 @@ def evolver(weights,
|
|
375
375
|
print(" GOOD GENOMES MUTATION PROB: ", str(round(1 - bad_genomes_mutation_prob, 2)))
|
376
376
|
print(" BAD GENOMES SELECTION PROB: ", str(bad_genomes_selection_prob))
|
377
377
|
print(" WEIGHT MUTATE PROB: ", str(weight_mutate_prob))
|
378
|
-
print(" WEIGHT MUTATE
|
378
|
+
print(" WEIGHT MUTATE THRESHOLD: ", str(weight_mutate_threshold))
|
379
379
|
print(" ACTIVATION MUTATE PROB: ", str(activation_mutate_prob))
|
380
|
+
print(" ACTIVATION MUTATE THRESHOLD: ", str(activation_mutate_threshold))
|
380
381
|
print(" ACTIVATION MUTATE ADD PROB: ", str(activation_mutate_add_prob))
|
381
382
|
print(" ACTIVATION MUTATE DELETE PROB: ", str(activation_mutate_delete_prob))
|
382
383
|
print(" ACTIVATION MUTATE CHANGE PROB: ", str(activation_mutate_change_prob))
|
384
|
+
print(" ACTIVATION SELECTION THRESHOLD:", str(activation_selection_threshold))
|
383
385
|
print(" ACTIVATION SELECTION ADD PROB: ", str(activation_selection_add_prob))
|
384
386
|
print(" ACTIVATION SELECTION CHANGE PROB: ", str(activation_selection_change_prob))
|
385
|
-
print(" FITNESS BIAS: ", str(fitness_bias))
|
386
|
-
print(" ACTIVATION SELECTION RATE (THRESHOLD VALUE FOR SINGLE CROSS OVER):", str(activation_selection_rate) + '\n')
|
387
|
+
print(" FITNESS BIAS: ", str(fitness_bias) + '\n')
|
387
388
|
|
388
389
|
|
389
390
|
print("*** Performance ***")
|
@@ -477,7 +478,7 @@ def cross_over(first_parent_W,
|
|
477
478
|
cross_over_mode,
|
478
479
|
activation_selection_add_prob,
|
479
480
|
activation_selection_change_prob,
|
480
|
-
|
481
|
+
activation_selection_threshold,
|
481
482
|
bad_genomes_selection_prob,
|
482
483
|
first_parent_fitness,
|
483
484
|
second_parent_fitness,
|
@@ -506,8 +507,7 @@ def cross_over(first_parent_W,
|
|
506
507
|
activation_selection_change_prob (float): Probability of replacing an activation function in the child genome
|
507
508
|
with one from the second parent.
|
508
509
|
|
509
|
-
|
510
|
-
during the crossover process.
|
510
|
+
activation_selection_threshold (float): (float): Determines max how much activaton transferable to child from undominant parent. (Function automaticly determines to min)
|
511
511
|
|
512
512
|
bad_genomes_selection_prob (float): Probability of selecting a "bad" genome for replacement with the offspring.
|
513
513
|
|
@@ -539,7 +539,7 @@ def cross_over(first_parent_W,
|
|
539
539
|
cross_over_mode='tpm',
|
540
540
|
activation_selection_add_prob=0.8,
|
541
541
|
activation_selection_change_prob=0.5,
|
542
|
-
|
542
|
+
activation_selection_threshold=2,
|
543
543
|
bad_genomes_selection_prob=0.7,
|
544
544
|
first_parent_fitness=0.9,
|
545
545
|
second_parent_fitness=0.85,
|
@@ -614,7 +614,7 @@ def cross_over(first_parent_W,
|
|
614
614
|
|
615
615
|
if potential_activation_selection_add > activation_selection_add_prob:
|
616
616
|
|
617
|
-
threshold = abs(
|
617
|
+
threshold = abs(activation_selection_threshold / succes)
|
618
618
|
new_threshold = threshold
|
619
619
|
|
620
620
|
while True:
|
@@ -626,7 +626,6 @@ def cross_over(first_parent_W,
|
|
626
626
|
|
627
627
|
if len(dominant_parent_act) > new_threshold:
|
628
628
|
new_threshold += threshold
|
629
|
-
pass
|
630
629
|
|
631
630
|
else:
|
632
631
|
break
|
@@ -636,7 +635,7 @@ def cross_over(first_parent_W,
|
|
636
635
|
|
637
636
|
if potential_activation_selection_change_prob > activation_selection_change_prob:
|
638
637
|
|
639
|
-
threshold = abs(
|
638
|
+
threshold = abs(activation_selection_threshold / succes)
|
640
639
|
new_threshold = threshold
|
641
640
|
|
642
641
|
while True:
|
@@ -649,7 +648,6 @@ def cross_over(first_parent_W,
|
|
649
648
|
|
650
649
|
if len(dominant_parent_act) > new_threshold:
|
651
650
|
new_threshold += threshold
|
652
|
-
pass
|
653
651
|
|
654
652
|
else:
|
655
653
|
break
|
@@ -663,9 +661,10 @@ def mutation(weight,
|
|
663
661
|
activation_delete_prob,
|
664
662
|
activation_change_prob,
|
665
663
|
weight_mutate_prob,
|
666
|
-
|
667
|
-
genome_fitness
|
668
|
-
|
664
|
+
weight_mutate_threshold,
|
665
|
+
genome_fitness,
|
666
|
+
activation_mutate_threshold,
|
667
|
+
epsilon):
|
669
668
|
"""
|
670
669
|
Performs mutation on the given weight matrix and activation functions.
|
671
670
|
- The weight matrix is mutated by randomly changing its values based on the mutation probability.
|
@@ -686,9 +685,13 @@ def mutation(weight,
|
|
686
685
|
|
687
686
|
weight_mutate_prob (float): The probability of mutating weight matrix.
|
688
687
|
|
689
|
-
|
688
|
+
weight_mutate_threshold (float): Determines max how much weight mutaiton operation applying. (Function automaticly determines to min)
|
690
689
|
|
691
|
-
genome_fitness (float): Fitness value of genome
|
690
|
+
genome_fitness (float): Fitness (0-1) value of genome
|
691
|
+
|
692
|
+
activation_mutate_threshold (float): Determines max how much activation mutaiton operation applying. (Function automaticly determines to min)
|
693
|
+
|
694
|
+
epsilon (float): Small epsilon constant
|
692
695
|
|
693
696
|
Returns:
|
694
697
|
tuple: A tuple containing:
|
@@ -720,7 +723,7 @@ def mutation(weight,
|
|
720
723
|
|
721
724
|
max_threshold = row_end * col_end
|
722
725
|
|
723
|
-
threshold =
|
726
|
+
threshold = weight_mutate_threshold * genome_fitness
|
724
727
|
new_threshold = threshold
|
725
728
|
|
726
729
|
for _ in range(max_threshold):
|
@@ -729,57 +732,72 @@ def mutation(weight,
|
|
729
732
|
selected_col = int(random.uniform(start, col_end))
|
730
733
|
|
731
734
|
weight[selected_row, selected_col] = random.uniform(-1, 1)
|
735
|
+
new_threshold += threshold
|
732
736
|
|
733
737
|
if max_threshold > new_threshold:
|
734
|
-
|
738
|
+
pass
|
735
739
|
|
736
740
|
else:
|
737
741
|
break
|
738
742
|
|
739
|
-
|
740
|
-
|
741
|
-
potential_activation_mutation = random.uniform(0, 1)
|
743
|
+
activation_mutate_prob = 1 - activation_mutate_prob
|
744
|
+
potential_activation_mutation = random.uniform(0, 1)
|
742
745
|
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
activation_add_prob = 1 - activation_add_prob
|
749
|
-
activation_delete_prob = 1 - activation_delete_prob
|
750
|
-
activation_change_prob = 1 - activation_change_prob
|
746
|
+
if potential_activation_mutation > activation_mutate_prob:
|
747
|
+
|
748
|
+
genome_fitness += epsilon
|
749
|
+
threshold = abs(activation_mutate_threshold / genome_fitness)
|
750
|
+
max_threshold = len(activations)
|
751
751
|
|
752
|
-
|
753
|
-
potential_activation_delete_prob = random.uniform(0, 1)
|
754
|
-
potential_activation_change_prob = random.uniform(0, 1)
|
752
|
+
new_threshold = threshold
|
755
753
|
|
756
|
-
|
754
|
+
except_this = ['spiral', 'circular']
|
755
|
+
all_acts = [item for item in all_activations() if item not in except_this] # SPIRAL AND CIRCULAR ACTIVATION DISCARDED
|
756
|
+
|
757
|
+
activation_add_prob = 1 - activation_add_prob
|
758
|
+
activation_delete_prob = 1 - activation_delete_prob
|
759
|
+
activation_change_prob = 1 - activation_change_prob
|
757
760
|
|
758
|
-
|
759
|
-
|
760
|
-
random_index_all_act = int(random.uniform(0, len(all_acts)-1))
|
761
|
-
activations.append(all_acts[random_index_all_act])
|
761
|
+
for _ in range(max_threshold):
|
762
762
|
|
763
|
-
|
763
|
+
potential_activation_add_prob = random.uniform(0, 1)
|
764
|
+
potential_activation_delete_prob = random.uniform(0, 1)
|
765
|
+
potential_activation_change_prob = random.uniform(0, 1)
|
764
766
|
|
765
|
-
activation = activations
|
766
|
-
activations = []
|
767
767
|
|
768
|
-
activations
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
768
|
+
if potential_activation_delete_prob > activation_delete_prob and len(activations) > 1:
|
769
|
+
|
770
|
+
random_index = random.randint(0, len(activations) - 1)
|
771
|
+
activations.pop(random_index)
|
772
|
+
|
773
|
+
|
774
|
+
if potential_activation_add_prob > activation_add_prob:
|
775
|
+
|
776
|
+
try:
|
777
|
+
|
778
|
+
random_index_all_act = int(random.uniform(0, len(all_acts)-1))
|
779
|
+
activations.append(all_acts[random_index_all_act])
|
780
|
+
|
781
|
+
except:
|
782
|
+
|
783
|
+
activation = activations
|
784
|
+
activations = []
|
785
|
+
|
786
|
+
activations.append(activation)
|
787
|
+
activations.append(all_acts[int(random.uniform(0, len(all_acts)-1))])
|
788
|
+
|
789
|
+
|
790
|
+
if potential_activation_change_prob > activation_change_prob:
|
791
|
+
|
792
|
+
random_index_all_act = int(random.uniform(0, len(all_acts)-1))
|
793
|
+
random_index_genom_act = int(random.uniform(0, len(activations)-1))
|
794
|
+
|
795
|
+
activations[random_index_genom_act] = all_acts[random_index_all_act]
|
796
|
+
|
797
|
+
new_threshold += threshold
|
781
798
|
|
782
|
-
|
799
|
+
if max_threshold > new_threshold: pass
|
800
|
+
else: break
|
783
801
|
|
784
802
|
return weight, activations
|
785
803
|
|
pyerualjetwork/planeat_cuda.py
CHANGED
@@ -83,18 +83,19 @@ def evolver(weights,
|
|
83
83
|
bad_genomes_selection_prob=None,
|
84
84
|
bar_status=True,
|
85
85
|
strategy='normal_selective',
|
86
|
-
bad_genomes_mutation_prob=None,
|
87
|
-
|
88
|
-
fitness_bias=None,
|
86
|
+
bad_genomes_mutation_prob=None,
|
87
|
+
fitness_bias=1,
|
89
88
|
cross_over_mode='tpm',
|
90
89
|
activation_mutate_add_prob=0.5,
|
91
90
|
activation_mutate_delete_prob=0.5,
|
92
|
-
activation_mutate_change_prob=0.5,
|
91
|
+
activation_mutate_change_prob=0.5,
|
92
|
+
activation_selection_add_prob=0.7,
|
93
|
+
activation_selection_change_prob=0.5,
|
94
|
+
activation_selection_threshold=2,
|
95
|
+
activation_mutate_prob=1,
|
96
|
+
activation_mutate_threshold=2,
|
97
|
+
weight_mutate_threshold=16,
|
93
98
|
weight_mutate_prob=1,
|
94
|
-
weight_mutate_rate=32,
|
95
|
-
activation_selection_add_prob=0.6,
|
96
|
-
activation_selection_change_prob=0.4,
|
97
|
-
activation_selection_rate=2,
|
98
99
|
dtype=cp.float32):
|
99
100
|
"""
|
100
101
|
Applies the evolving process of a population of genomes using selection, crossover, mutation, and activation function potentiation.
|
@@ -140,7 +141,7 @@ def evolver(weights,
|
|
140
141
|
|
141
142
|
Default: 'aggressive'.
|
142
143
|
|
143
|
-
fitness_bias (float, optional): Fitness bias must be a probability value between 0 and 1 that determines the effect of fitness on the crossover process. Default:
|
144
|
+
fitness_bias (float, optional): Fitness bias must be a probability value between 0 and 1 that determines the effect of fitness on the crossover process. Default: 1`.
|
144
145
|
|
145
146
|
bad_genomes_mutation_prob (float, optional): The probability of applying mutation to the bad genomes.
|
146
147
|
Must be in the range [0, 1]. Also affects the mutation probability of the best genomes inversely.
|
@@ -154,7 +155,7 @@ def evolver(weights,
|
|
154
155
|
Default is 'tpm'.
|
155
156
|
|
156
157
|
activation_mutate_add_prob (float, optional): The probability of adding a new activation function to the genome for mutation.
|
157
|
-
Must be in the range [0, 1]. Default is 0.
|
158
|
+
Must be in the range [0, 1]. Default is 0.7.
|
158
159
|
|
159
160
|
activation_mutate_delete_prob (float, optional): The probability of deleting an existing activation function
|
160
161
|
from the genome for mutation. Must be in the range [0, 1]. Default is 0.5.
|
@@ -163,19 +164,19 @@ def evolver(weights,
|
|
163
164
|
Must be in the range [0, 1]. Default is 0.5.
|
164
165
|
|
165
166
|
weight_mutate_prob (float, optional): The probability of mutating a weight in the genome.
|
166
|
-
Must be in the range [0, 1]. Default is 1.
|
167
|
+
Must be in the range [0, 1]. Default is 1 (%100).
|
167
168
|
|
168
|
-
|
169
|
-
only a single weight will be mutated during each mutation process. If the value is half of the result,
|
170
|
-
two weights will be mutated. WARNING: If you don't understand, do NOT change this value. Default is 32.
|
169
|
+
weight_mutate_threshold (int): Determines max how much weight mutaiton operation applying. (Function automaticly determines to min) Default: 16
|
171
170
|
|
172
171
|
activation_selection_add_prob (float, optional): The probability of adding an existing activation function for crossover.
|
173
|
-
Must be in the range [0, 1]. Default is 0.
|
172
|
+
Must be in the range [0, 1]. Default is 0.5. (WARNING! Higher values increase complexity. For faster training, increase this value.)
|
174
173
|
|
175
174
|
activation_selection_change_prob (float, optional): The probability of changing an activation function in the genome for crossover.
|
176
|
-
Must be in the range [0, 1]. Default is 0.
|
175
|
+
Must be in the range [0, 1]. Default is 0.5.
|
176
|
+
|
177
|
+
activation_mutate_threshold (int): Determines max how much activation mutaiton operation applying. (Function automaticly determines to min) Default: 2
|
177
178
|
|
178
|
-
|
179
|
+
activation_selection_threshold (int, optional): Determines max how much activaton transferable to child from undominant parent. (Function automaticly determines to min) Default: 2
|
179
180
|
|
180
181
|
dtype (cupy.dtype): Data type for the arrays. Default: cp.float32.
|
181
182
|
Example: cp.float64 or cp.float16 [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not recommended!].
|
@@ -224,17 +225,14 @@ def evolver(weights,
|
|
224
225
|
if strategy == 'normal_selective':
|
225
226
|
if bad_genomes_mutation_prob is None: bad_genomes_mutation_prob = 0.7 # EFFECTS MUTATION
|
226
227
|
if bad_genomes_selection_prob is None: bad_genomes_selection_prob = 0.25 # EFFECTS CROSS-OVER
|
227
|
-
|
228
|
-
|
228
|
+
|
229
229
|
elif strategy == 'more_selective':
|
230
230
|
if bad_genomes_mutation_prob is None: bad_genomes_mutation_prob = 0.85 # EFFECTS MUTATION
|
231
231
|
if bad_genomes_selection_prob is None: bad_genomes_selection_prob = 0.1 # EFFECTS CROSS-OVER
|
232
|
-
if fitness_bias is None: fitness_bias = 0.7 # The pressure applied by FITNESS to the CROSS-OVER
|
233
232
|
|
234
233
|
elif strategy == 'less_selective':
|
235
234
|
if bad_genomes_mutation_prob is None: bad_genomes_mutation_prob = 0.6 # EFFECTS MUTATION
|
236
235
|
if bad_genomes_selection_prob is None: bad_genomes_selection_prob = 0.5 # EFFECTS CROSS-OVER
|
237
|
-
if fitness_bias is None: fitness_bias = 0.3 # The pressure applied by FITNESS to the CROSS-OVER
|
238
236
|
|
239
237
|
else:
|
240
238
|
raise ValueError("strategy parameter must be: 'normal_selective' or 'more_selective' or 'less_selective'")
|
@@ -251,11 +249,11 @@ def evolver(weights,
|
|
251
249
|
if fitness_bias < 0 or fitness_bias > 1: raise ValueError("fitness_bias value must be a number between 0 and 1.")
|
252
250
|
|
253
251
|
if bad_genomes_mutation_prob is not None:
|
254
|
-
if
|
252
|
+
if bad_genomes_mutation_prob < 0 or bad_genomes_mutation_prob > 1:
|
255
253
|
raise ValueError("bad_genomes_mutation_prob parameter must be float and 0-1 range")
|
256
254
|
|
257
255
|
if activation_mutate_prob is not None:
|
258
|
-
if
|
256
|
+
if activation_mutate_prob < 0 or activation_mutate_prob > 1:
|
259
257
|
raise ValueError("activation_mutate_prob parameter must be float and 0-1 range")
|
260
258
|
|
261
259
|
if len(fitness) % 2 == 0:
|
@@ -322,7 +320,7 @@ def evolver(weights,
|
|
322
320
|
cross_over_mode=cross_over_mode,
|
323
321
|
activation_selection_add_prob=activation_selection_add_prob,
|
324
322
|
activation_selection_change_prob=activation_selection_change_prob,
|
325
|
-
|
323
|
+
activation_selection_threshold=activation_selection_threshold,
|
326
324
|
bad_genomes_selection_prob=bad_genomes_selection_prob,
|
327
325
|
first_parent_fitness=best_fitness,
|
328
326
|
fitness_bias=fitness_bias,
|
@@ -351,8 +349,10 @@ def evolver(weights,
|
|
351
349
|
activation_delete_prob=activation_mutate_delete_prob,
|
352
350
|
activation_change_prob=activation_mutate_change_prob,
|
353
351
|
weight_mutate_prob=weight_mutate_prob,
|
354
|
-
|
355
|
-
genome_fitness=normalized_fitness[fitness_index]
|
352
|
+
weight_mutate_threshold=weight_mutate_threshold,
|
353
|
+
genome_fitness=normalized_fitness[fitness_index],
|
354
|
+
activation_mutate_threshold=activation_mutate_threshold,
|
355
|
+
epsilon=epsilon
|
356
356
|
)
|
357
357
|
|
358
358
|
if bar_status: progress.update(1)
|
@@ -374,17 +374,19 @@ def evolver(weights,
|
|
374
374
|
print(" POLICY: ", policy)
|
375
375
|
print(" BAD GENOMES MUTATION PROB: ", str(bad_genomes_mutation_prob))
|
376
376
|
print(" GOOD GENOMES MUTATION PROB: ", str(round(1 - bad_genomes_mutation_prob, 2)))
|
377
|
+
print(" BAD GENOMES SELECTION PROB: ", str(bad_genomes_selection_prob))
|
377
378
|
print(" WEIGHT MUTATE PROB: ", str(weight_mutate_prob))
|
378
|
-
print(" WEIGHT MUTATE
|
379
|
+
print(" WEIGHT MUTATE THRESHOLD: ", str(weight_mutate_threshold))
|
379
380
|
print(" ACTIVATION MUTATE PROB: ", str(activation_mutate_prob))
|
381
|
+
print(" ACTIVATION MUTATE THRESHOLD: ", str(activation_mutate_threshold))
|
380
382
|
print(" ACTIVATION MUTATE ADD PROB: ", str(activation_mutate_add_prob))
|
381
383
|
print(" ACTIVATION MUTATE DELETE PROB: ", str(activation_mutate_delete_prob))
|
382
384
|
print(" ACTIVATION MUTATE CHANGE PROB: ", str(activation_mutate_change_prob))
|
385
|
+
print(" ACTIVATION SELECTION THRESHOLD:", str(activation_selection_threshold))
|
383
386
|
print(" ACTIVATION SELECTION ADD PROB: ", str(activation_selection_add_prob))
|
384
387
|
print(" ACTIVATION SELECTION CHANGE PROB: ", str(activation_selection_change_prob))
|
385
|
-
print(" FITNESS BIAS: ", str(fitness_bias))
|
386
|
-
|
387
|
-
|
388
|
+
print(" FITNESS BIAS: ", str(fitness_bias) + '\n')
|
389
|
+
|
388
390
|
print("*** Performance ***")
|
389
391
|
print(" MAX FITNESS: ", str(cp.round(max(fitness), 2)))
|
390
392
|
print(" MEAN FITNESS: ", str(cp.round(cp.mean(fitness), 2)))
|
@@ -480,7 +482,7 @@ def cross_over(first_parent_W,
|
|
480
482
|
cross_over_mode,
|
481
483
|
activation_selection_add_prob,
|
482
484
|
activation_selection_change_prob,
|
483
|
-
|
485
|
+
activation_selection_threshold,
|
484
486
|
bad_genomes_selection_prob,
|
485
487
|
first_parent_fitness,
|
486
488
|
second_parent_fitness,
|
@@ -509,8 +511,7 @@ def cross_over(first_parent_W,
|
|
509
511
|
activation_selection_change_prob (float): Probability of replacing an activation function in the child genome
|
510
512
|
with one from the second parent.
|
511
513
|
|
512
|
-
|
513
|
-
during the crossover process.
|
514
|
+
activation_selection_threshold (int): Determines max how much activaton transferable to child from undominant parent. (Function automaticly determines to min)
|
514
515
|
|
515
516
|
bad_genomes_selection_prob (float): Probability of selecting a "bad" genome for replacement with the offspring.
|
516
517
|
|
@@ -542,7 +543,7 @@ def cross_over(first_parent_W,
|
|
542
543
|
cross_over_mode='tpm',
|
543
544
|
activation_selection_add_prob=0.8,
|
544
545
|
activation_selection_change_prob=0.5,
|
545
|
-
|
546
|
+
activation_selection_threshold=2,
|
546
547
|
bad_genomes_selection_prob=0.7,
|
547
548
|
first_parent_fitness=0.9,
|
548
549
|
second_parent_fitness=0.85,
|
@@ -618,7 +619,7 @@ def cross_over(first_parent_W,
|
|
618
619
|
|
619
620
|
if potential_activation_selection_add > activation_selection_add_prob:
|
620
621
|
|
621
|
-
threshold =
|
622
|
+
threshold = abs(activation_selection_threshold / succes)
|
622
623
|
new_threshold = threshold
|
623
624
|
|
624
625
|
while True:
|
@@ -627,9 +628,9 @@ def cross_over(first_parent_W,
|
|
627
628
|
random_undominant_activation = undominant_parent_act[random_index]
|
628
629
|
|
629
630
|
child_act.append(random_undominant_activation)
|
631
|
+
new_threshold += threshold
|
630
632
|
|
631
633
|
if len(dominant_parent_act) > new_threshold:
|
632
|
-
new_threshold += threshold
|
633
634
|
pass
|
634
635
|
|
635
636
|
else:
|
@@ -640,7 +641,7 @@ def cross_over(first_parent_W,
|
|
640
641
|
|
641
642
|
if potential_activation_selection_change_prob > activation_selection_change_prob:
|
642
643
|
|
643
|
-
threshold =
|
644
|
+
threshold = abs(activation_selection_threshold / succes)
|
644
645
|
new_threshold = threshold
|
645
646
|
|
646
647
|
while True:
|
@@ -650,9 +651,9 @@ def cross_over(first_parent_W,
|
|
650
651
|
random_undominant_activation = undominant_parent_act[random_index_undominant]
|
651
652
|
|
652
653
|
child_act[random_index_dominant] = random_undominant_activation
|
654
|
+
new_threshold += threshold
|
653
655
|
|
654
656
|
if len(dominant_parent_act) > new_threshold:
|
655
|
-
new_threshold += threshold
|
656
657
|
pass
|
657
658
|
|
658
659
|
else:
|
@@ -668,8 +669,10 @@ def mutation(weight,
|
|
668
669
|
activation_delete_prob,
|
669
670
|
activation_change_prob,
|
670
671
|
weight_mutate_prob,
|
671
|
-
|
672
|
-
genome_fitness
|
672
|
+
weight_mutate_threshold,
|
673
|
+
genome_fitness,
|
674
|
+
activation_mutate_threshold,
|
675
|
+
epsilon):
|
673
676
|
"""
|
674
677
|
Performs mutation on the given weight matrix and activation functions.
|
675
678
|
- The weight matrix is mutated by randomly changing its values based on the mutation probability.
|
@@ -690,10 +693,13 @@ def mutation(weight,
|
|
690
693
|
|
691
694
|
weight_mutate_prob (float): The probability of mutating weight matrix.
|
692
695
|
|
693
|
-
|
696
|
+
weight_mutate_threshold (float): Determines max how much weight mutaiton operation applying. (Function automaticly determines to min)
|
694
697
|
|
695
698
|
genome_fitness (float): Fitness value of genome
|
696
699
|
|
700
|
+
activation_mutate_threshold (float): Determines max how much activation mutaiton operation applying. (Function automaticly determines to min)
|
701
|
+
|
702
|
+
epsilon (float): Small epsilon constant
|
697
703
|
|
698
704
|
Returns:
|
699
705
|
tuple: A tuple containing:
|
@@ -725,7 +731,7 @@ def mutation(weight,
|
|
725
731
|
|
726
732
|
max_threshold = row_end * col_end
|
727
733
|
|
728
|
-
threshold =
|
734
|
+
threshold = weight_mutate_threshold * genome_fitness
|
729
735
|
new_threshold = threshold
|
730
736
|
|
731
737
|
for _ in range(max_threshold):
|
@@ -734,56 +740,71 @@ def mutation(weight,
|
|
734
740
|
selected_col = int(random.uniform(start, col_end))
|
735
741
|
|
736
742
|
weight[selected_row, selected_col] = random.uniform(-1, 1)
|
743
|
+
new_threshold += threshold
|
737
744
|
|
738
745
|
if max_threshold > new_threshold:
|
739
|
-
|
746
|
+
pass
|
740
747
|
|
741
748
|
else:
|
742
749
|
break
|
743
|
-
|
744
|
-
activation_mutate_prob = 1 - activation_mutate_prob
|
745
|
-
potential_activation_mutation = random.uniform(0, 1)
|
746
750
|
|
747
|
-
|
748
|
-
|
749
|
-
except_this = ['spiral', 'circular']
|
750
|
-
all_acts = [item for item in all_activations() if item not in except_this] # SPIRAL AND CIRCULAR ACTIVATION DISCARDED
|
751
|
-
|
752
|
-
activation_add_prob = 1 - activation_add_prob
|
753
|
-
activation_delete_prob = 1 - activation_delete_prob
|
754
|
-
activation_change_prob = 1 - activation_change_prob
|
751
|
+
activation_mutate_prob = 1 - activation_mutate_prob
|
752
|
+
potential_activation_mutation = random.uniform(0, 1)
|
755
753
|
|
756
|
-
|
757
|
-
|
758
|
-
|
754
|
+
if potential_activation_mutation > activation_mutate_prob:
|
755
|
+
|
756
|
+
genome_fitness += epsilon
|
757
|
+
threshold = abs(activation_mutate_threshold / genome_fitness)
|
758
|
+
max_threshold = len(activations)
|
759
759
|
|
760
|
-
|
760
|
+
new_threshold = threshold
|
761
761
|
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
762
|
+
except_this = ['spiral', 'circular']
|
763
|
+
all_acts = [item for item in all_activations() if item not in except_this] # SPIRAL AND CIRCULAR ACTIVATION DISCARDED
|
764
|
+
|
765
|
+
activation_add_prob = 1 - activation_add_prob
|
766
|
+
activation_delete_prob = 1 - activation_delete_prob
|
767
|
+
activation_change_prob = 1 - activation_change_prob
|
766
768
|
|
767
|
-
|
769
|
+
for _ in range(max_threshold):
|
768
770
|
|
769
|
-
|
770
|
-
|
771
|
+
potential_activation_add_prob = random.uniform(0, 1)
|
772
|
+
potential_activation_delete_prob = random.uniform(0, 1)
|
773
|
+
potential_activation_change_prob = random.uniform(0, 1)
|
771
774
|
|
772
|
-
activations.append(activation)
|
773
|
-
activations.append(all_acts[int(random.uniform(0, len(all_acts)-1))])
|
774
775
|
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
776
|
+
if potential_activation_delete_prob > activation_delete_prob and len(activations) > 1:
|
777
|
+
|
778
|
+
random_index = random.randint(0, len(activations) - 1)
|
779
|
+
activations.pop(random_index)
|
780
|
+
|
781
|
+
|
782
|
+
if potential_activation_add_prob > activation_add_prob:
|
783
|
+
|
784
|
+
try:
|
785
|
+
|
786
|
+
random_index_all_act = int(random.uniform(0, len(all_acts)-1))
|
787
|
+
activations.append(all_acts[random_index_all_act])
|
788
|
+
|
789
|
+
except:
|
790
|
+
|
791
|
+
activation = activations
|
792
|
+
activations = []
|
793
|
+
|
794
|
+
activations.append(activation)
|
795
|
+
activations.append(all_acts[int(random.uniform(0, len(all_acts)-1))])
|
796
|
+
|
797
|
+
if potential_activation_change_prob > activation_change_prob:
|
798
|
+
|
799
|
+
random_index_all_act = int(random.uniform(0, len(all_acts)-1))
|
800
|
+
random_index_genom_act = int(random.uniform(0, len(activations)-1))
|
801
|
+
|
802
|
+
activations[random_index_genom_act] = all_acts[random_index_all_act]
|
803
|
+
|
804
|
+
new_threshold += threshold
|
785
805
|
|
786
|
-
|
806
|
+
if max_threshold > new_threshold: pass
|
807
|
+
else: break
|
787
808
|
|
788
809
|
return weight, activations
|
789
810
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pyerualjetwork
|
3
|
-
Version: 4.2.
|
3
|
+
Version: 4.2.7
|
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=QoWVlKx1oD7DDQipA1e4Sgk-kgmbFt5TqDTB3vFXiRs,639
|
2
2
|
pyerualjetwork/activation_functions.py,sha256=WWOdMd5pI6ZKe-ieKCIsKAYPQODHuXYxx7tzhA5xjes,11767
|
3
3
|
pyerualjetwork/activation_functions_cuda.py,sha256=KmXJ5Cdig46XAMYakXFPEOlxSxtFJjD21-i3nGtxPjE,11807
|
4
4
|
pyerualjetwork/data_operations.py,sha256=pb5CqJ0Th6fCjTNMCtqQMiwH3KezTxAijacglsKUxmY,14730
|
@@ -13,12 +13,12 @@ pyerualjetwork/model_operations.py,sha256=RKqnh7-MByFosxqme4q4jC1lOndX26O-OVXYV6
|
|
13
13
|
pyerualjetwork/model_operations_cuda.py,sha256=XnKKq54ZLaqCm-NaJ6d8IToACKcKg2Ttq6moowVRRWo,13365
|
14
14
|
pyerualjetwork/plan.py,sha256=UzCTFCA9cTv9ITCtsqfJ1g02rCMyescoIV6j1amvYGw,32134
|
15
15
|
pyerualjetwork/plan_cuda.py,sha256=hpXZl3h7B1qAVYW-gZebwKMZd4-ftAZ-u05teOJjsno,33525
|
16
|
-
pyerualjetwork/planeat.py,sha256=
|
17
|
-
pyerualjetwork/planeat_cuda.py,sha256=
|
16
|
+
pyerualjetwork/planeat.py,sha256=9W1QTEw7TbDuGWvFbFCPeCZ2SmooeL8wjtn2cCjVr6Y,39440
|
17
|
+
pyerualjetwork/planeat_cuda.py,sha256=lnCvyyDVhs4pybeVzmQBOf1H1_fqmwXZwZNDrLQEAcA,39499
|
18
18
|
pyerualjetwork/ui.py,sha256=wu2BhU1k-w3Kcho5Jtq4SEKe68ftaUeRGneUOSCVDjU,575
|
19
19
|
pyerualjetwork/visualizations.py,sha256=1SKMZaJ80OD2qHUyMxW1IOv8zwmxzMPxclfbeq1Xr4g,28772
|
20
20
|
pyerualjetwork/visualizations_cuda.py,sha256=KbMhfsLlxujy_i3QrwCf734Q-k6d7Zn_7CEbm3gzK9w,29186
|
21
|
-
pyerualjetwork-4.2.
|
22
|
-
pyerualjetwork-4.2.
|
23
|
-
pyerualjetwork-4.2.
|
24
|
-
pyerualjetwork-4.2.
|
21
|
+
pyerualjetwork-4.2.7.dist-info/METADATA,sha256=uhb0FLFa5h8P5nM10tZNC3cAFKxtjVqxC_WLygaBiMw,7452
|
22
|
+
pyerualjetwork-4.2.7.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
23
|
+
pyerualjetwork-4.2.7.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
|
24
|
+
pyerualjetwork-4.2.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|