pyerualjetwork 4.1.6__py3-none-any.whl → 4.1.8__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.
@@ -13,12 +13,12 @@ ANAPLAN document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_Anaplan/
13
13
  import cupy as cp
14
14
  import numpy as np
15
15
  import random
16
- from tqdm import tqdm
16
+
17
17
 
18
18
  ### LIBRARY IMPORTS ###
19
19
  from .plan_cuda import feed_forward
20
20
  from .data_operations_cuda import normalization
21
- from .ui import loading_bars
21
+ from .ui import loading_bars, initialize_loading_bar
22
22
  from .activation_functions_cuda import apply_activation, all_activations
23
23
 
24
24
  def define_genomes(input_shape, output_shape, population_size, dtype=cp.float32):
@@ -67,16 +67,16 @@ def define_genomes(input_shape, output_shape, population_size, dtype=cp.float32)
67
67
  population_weights[i][j,:] = apply_activation(population_weights[i][j,:], population_activations[i])
68
68
  population_weights[i][j,:] = normalization(population_weights[i][j,:], dtype=dtype)
69
69
 
70
- return cp.array(population_weights), population_activations
70
+ return cp.array(population_weights, dtype=dtype), population_activations
71
71
 
72
72
 
73
- def evolve(weights, activation_potentiations, what_gen, y_reward, show_info=False, strategy='cross_over', policy='normal_selective', mutations=True, bad_genoms_mutation_prob=None, activation_mutate_prob=0.5, save_best_genom=True, cross_over_mode='tpm', activation_add_prob=0.5, activation_delete_prob=0.5, activation_change_prob=0.5, weight_mutate_prob=1, weight_mutate_rate=32, activation_selection_add_prob=0.5, activation_selection_change_prob=0.5, activation_selection_rate=2, dtype=cp.float32):
73
+ def evolve(weights, activation_potentiations, what_gen, fitness, show_info=False, strategy='cross_over', bar_status=True, policy='normal_selective', target_fitness='max', mutations=True, bad_genoms_mutation_prob=None, activation_mutate_prob=0.5, save_best_genom=True, cross_over_mode='tpm', activation_add_prob=0.5, activation_delete_prob=0.5, activation_change_prob=0.5, weight_mutate_prob=1, weight_mutate_rate=32, activation_selection_add_prob=0.7, activation_selection_change_prob=0.5, activation_selection_rate=2, dtype=cp.float32):
74
74
  """
75
75
  Applies the evolving process of a population of genomes using selection, crossover, mutation, and activation function potentiation.
76
76
  The function modifies the population's weights and activation functions based on a specified policy, mutation probabilities, and strategy.
77
77
 
78
78
  Args:
79
- weights (numpy.ndarray): Array of weights for each genome.
79
+ weights (cupy.ndarray): Array of weights for each genome.
80
80
  (first returned value of define_genomes function)
81
81
 
82
82
  activation_potentiations (list): A list of activation functions for each genome.
@@ -84,7 +84,7 @@ Args:
84
84
 
85
85
  what_gen (int): The current generation number, used for informational purposes or logging.
86
86
 
87
- y_reward (numpy.ndarray): A 1D array containing the fitness or reward values of each genome.
87
+ fitness (cupy.ndarray): A 1D array containing the fitness or reward values of each genome.
88
88
  The array is used to rank the genomes based on their performance. PLANEAT maximizes the reward.
89
89
 
90
90
  show_info (bool, optional): If True, prints information about the current generation and the
@@ -97,12 +97,16 @@ Args:
97
97
  (PLAN feature, similar to arithmetic crossover but different.)
98
98
  Default is 'cross_over'.
99
99
 
100
+ bar_status (bool, optional): Loading bar status during evolving process of genomes. True or False. Default: True
101
+
100
102
  policy (str, optional): The selection policy that governs how genomes are selected for reproduction. Options:
101
103
  - 'normal_selective': Normal selection based on reward, where a portion of the bad genes are discarded.
102
104
  - 'more_selective': A more selective policy, where fewer bad genes survive.
103
105
  - 'less_selective': A less selective policy, where more bad genes survive.
104
106
  Default is 'normal_selective'.
105
107
 
108
+ target_fitness (str, optional): Target fitness strategy for PLANEAT optimization. ('max' for machine learning, 'min' for machine unlearning.) Default: 'max'
109
+
106
110
  mutations (bool, optional): If True, mutations are applied to the bad genomes and potentially
107
111
  to the best genomes as well. Default is True.
108
112
 
@@ -140,7 +144,7 @@ Args:
140
144
  WARNING: if you don't understand do NOT change this value. Default is 32.
141
145
 
142
146
  activation_selection_add_prob (float, optional): The probability of adding an existing activation function for cross over.
143
- from the genome. Must be in the range [0, 1]. Default is 0.5.
147
+ from the genome. Must be in the range [0, 1]. Default is 0.7. (WARNING! More higher values make models more complex. For fast training rise this value.)
144
148
 
145
149
  activation_selection_change_prob (float, optional): The probability of changing an activation function in the genome for cross over.
146
150
  Must be in the range [0, 1]. Default is 0.5.
@@ -164,7 +168,7 @@ Returns:
164
168
 
165
169
  Notes:
166
170
  - **Selection Process**:
167
- - The genomes are sorted by their fitness (based on `y_reward`), and then split into "best" and "bad" halves.
171
+ - The genomes are sorted by their fitness (based on `fitness`), and then split into "best" and "bad" halves.
168
172
  - The best genomes are retained, and the bad genomes are modified based on the selected strategy.
169
173
 
170
174
  - **Crossover and Potentiation Strategies**:
@@ -176,13 +180,13 @@ Notes:
176
180
  - `bad_genoms_mutation_prob` determines the probability of applying mutations to the bad genomes.
177
181
  - If `activation_mutate_prob` is provided, activation function mutations are applied to the genomes based on this probability.
178
182
 
179
- - **Population Size**: The population size must be an even number to properly split the best and bad genomes. If `y_reward` has an odd length, an error is raised.
183
+ - **Population Size**: The population size must be an even number to properly split the best and bad genomes. If `fitness` has an odd length, an error is raised.
180
184
 
181
185
  - **Logging**: If `show_info=True`, the current generation and the maximum reward from the population are printed for tracking the learning progress.
182
186
 
183
187
  Example:
184
188
  ```python
185
- weights, activation_potentiations = learner(weights, activation_potentiations, 1, y_reward, info=True, strategy='cross_over', policy='normal_selective')
189
+ weights, activation_potentiations = planeat.evolve(weights, activation_potentiations, 1, fitness, show_info=True, strategy='cross_over', policy='normal_selective')
186
190
  ```
187
191
 
188
192
  - The function returns the updated weights and activations after processing based on the chosen strategy, policy, and mutation parameters.
@@ -220,20 +224,21 @@ Example:
220
224
  if not isinstance(activation_mutate_prob, float) or activation_mutate_prob < 0 or activation_mutate_prob > 1:
221
225
  raise ValueError("activation_mutate_prob parameter must be float and 0-1 range")
222
226
 
223
- if len(y_reward) % 2 == 0:
224
- slice_center = int(len(y_reward) / 2)
227
+ if len(fitness) % 2 == 0:
228
+ slice_center = int(len(fitness) / 2)
225
229
 
226
230
  else:
227
231
  raise ValueError("genome population size must be even number. for example: not 99, make 100 or 98.")
228
232
 
229
- sort_indices = cp.argsort(y_reward)
233
+ ### FITNESS LIST IS SORTED IN ASCENDING (OR DESCENDING) ORDER, AND THE WEIGHT AND ACTIVATIONS OF EACH GENOME ARE SORTED ACCORDING TO THIS ORDER:
230
234
 
231
- ### REWARD LIST IS SORTED IN ASCENDING ORDER, AND THE WEIGHT AND ACTIVATIONS OF EACH GENOME ARE SORTED ACCORDING TO THIS ORDER:
235
+ if target_fitness == 'max': sort_indices = cp.argsort(fitness)
236
+ elif target_fitness == 'min': sort_indices = cp.argsort(-fitness)
232
237
 
233
- y_reward = y_reward[sort_indices]
238
+ fitness = fitness[sort_indices]
234
239
  weights = weights[sort_indices]
235
240
 
236
- activation_potentiations = [activation_potentiations[i] for i in sort_indices]
241
+ activation_potentiations = [activation_potentiations[int(i)] for i in sort_indices]
237
242
 
238
243
  ### GENOMES ARE DIVIDED INTO TWO GROUPS: GOOD GENOMES AND BAD GENOMES:
239
244
 
@@ -250,7 +255,9 @@ Example:
250
255
 
251
256
  bar_format = loading_bars()[0]
252
257
 
253
- for i in tqdm(range(len(bad_weights)), desc="GENERATION: " + str(what_gen), bar_format=bar_format, ncols=50, ascii="▱▰"):
258
+ if bar_status: progress = initialize_loading_bar(len(bad_weights), desc="GENERATION: " + str(what_gen), bar_format=bar_format, ncols=50, ascii="▱▰")
259
+
260
+ for i in range(len(bad_weights)):
254
261
 
255
262
  if policy == 'normal_selective':
256
263
 
@@ -315,6 +322,7 @@ Example:
315
322
  elif mutation_prob < bad_genoms_mutation_prob:
316
323
  bad_weights[i], bad_activations[i] = mutation(bad_weights[i], bad_activations[i], activation_mutate_prob=activation_mutate_prob, activation_add_prob=activation_add_prob, activation_delete_prob=activation_delete_prob, activation_change_prob=activation_change_prob, weight_mutate_prob=weight_mutate_prob, threshold=weight_mutate_rate, dtype=dtype)
317
324
 
325
+ if bar_status: progress.update(1)
318
326
 
319
327
  weights = cp.vstack((bad_weights, best_weights))
320
328
  activation_potentiations = bad_activations + best_activations
@@ -345,9 +353,9 @@ Example:
345
353
  print(" ACTIVATION SELECTION RATE (THRESHOLD VALUE FOR SINGLE CROSS OVER):", str(activation_selection_rate) + '\n')
346
354
 
347
355
  print("*** Performance ***")
348
- print(" MAX REWARD: ", str(round(max(y_reward), 2)))
349
- print(" MEAN REWARD: ", str(round(cp.mean(y_reward), 2)))
350
- print(" MIN REWARD: ", str(round(min(y_reward), 2)) + '\n')
356
+ print(" MAX REWARD: ", str(cp.round(max(fitness), 2)))
357
+ print(" MEAN REWARD: ", str(cp.round(cp.mean(fitness), 2)))
358
+ print(" MIN REWARD: ", str(cp.round(min(fitness), 2)) + '\n')
351
359
 
352
360
  print(" BEST GENOME INDEX: ", str(len(weights)-1))
353
361
  print(" NOTE: Genomes are always sorted from the least successful to the most successful according to their performance ranking. Therefore, the genome at the last index is the king of the previous generation. " + '\n')
@@ -318,10 +318,12 @@ def draw_activations(x_train, activation):
318
318
 
319
319
  elif activation == 'spiral':
320
320
  result = af.spiral_activation(x_train)
321
-
322
- return result
323
-
324
-
321
+
322
+ try: return result
323
+ except:
324
+ print('WARNING: error in drawing some activation.')
325
+ return x_train
326
+
325
327
  def plot_evaluate(x_test, y_test, y_preds, acc_list, W, activation_potentiation):
326
328
 
327
329
  from .metrics import metrics, confusion_matrix, roc_curve
@@ -321,7 +321,10 @@ def draw_activations(x_train, activation):
321
321
  elif activation == 'spiral':
322
322
  result = af.spiral_activation(x_train)
323
323
 
324
- return result
324
+ try: return result
325
+ except:
326
+ print('WARNING: error in drawing some activation.')
327
+ return x_train
325
328
 
326
329
 
327
330
  def plot_evaluate(x_test, y_test, y_preds, acc_list, W, activation_potentiation):
@@ -355,7 +358,7 @@ def plot_evaluate(x_test, y_test, y_preds, acc_list, W, activation_potentiation)
355
358
  fpr, tpr, thresholds = roc_curve(y_true, y_preds)
356
359
 
357
360
  roc_auc = cp.trapz(tpr, fpr)
358
- axs[1, 0].plot(fpr, tpr, color='darkorange', lw=2, label=f'ROC curve (area = {roc_auc:.2f})')
361
+ axs[1, 0].plot(fpr.get(), tpr.get(), color='darkorange', lw=2, label=f'ROC curve (area = {roc_auc:.2f})')
359
362
  axs[1, 0].plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
360
363
  axs[1, 0].set_xlim([0.0, 1.0])
361
364
  axs[1, 0].set_ylim([0.0, 1.05])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 4.1.6
3
+ Version: 4.1.8
4
4
  Summary: PyerualJetwork is a machine learning library written in Python for professionals, incorporating advanced, unique, new, and modern techniques.
5
5
  Author: Hasan Can Beydili
6
6
  Author-email: tchasancan@gmail.com
@@ -0,0 +1,24 @@
1
+ pyerualjetwork/__init__.py,sha256=uPTVoRI0TyHt86XYQOHZcvtk1faqxuocKknYhnKUZbY,2175
2
+ pyerualjetwork/activation_functions.py,sha256=WWOdMd5pI6ZKe-ieKCIsKAYPQODHuXYxx7tzhA5xjes,11767
3
+ pyerualjetwork/activation_functions_cuda.py,sha256=KmXJ5Cdig46XAMYakXFPEOlxSxtFJjD21-i3nGtxPjE,11807
4
+ pyerualjetwork/data_operations.py,sha256=ZM24BuPsIAtI0a_Exr4HgCjmlb285wEeO8juFY9sJr0,14680
5
+ pyerualjetwork/data_operations_cuda.py,sha256=UpoJoFhIwTU4xg9dVuLAxLAT4CkRaGsxvtJG9j1xrNo,17629
6
+ pyerualjetwork/help.py,sha256=OZghUy7GZTgEX_i3NYtgcpzUgCDOi6r2vVUF1ROkFiI,774
7
+ pyerualjetwork/loss_functions.py,sha256=6PyBI232SQRGuFnG3LDGvnv_PUdWzT2_2mUODJiejGI,618
8
+ pyerualjetwork/loss_functions_cuda.py,sha256=C93IZJcrOpT6HMK9x1O4AHJWXYTkN5WZiqdssPbvAPk,617
9
+ pyerualjetwork/memory_operations.py,sha256=_Wu9FJc6ozQTPOC2tXfXWPCwUIvPRuDjmLw_McntVSI,13470
10
+ pyerualjetwork/metrics.py,sha256=q7MkhnZDRbCjFBDDfUgrl8lBYnUT_1ro1LxeBq105pI,6077
11
+ pyerualjetwork/metrics_cuda.py,sha256=73h9GC7XwmnFCVzFEEiPQfF8CwHIz2wsCbxpZrJtYgw,5061
12
+ pyerualjetwork/model_operations.py,sha256=hnhR8dtoICNJWIwGgJ65-LN3GYN_DYH4LMe6YpZVbnI,12967
13
+ pyerualjetwork/model_operations_cuda.py,sha256=XnKKq54ZLaqCm-NaJ6d8IToACKcKg2Ttq6moowVRRWo,13365
14
+ pyerualjetwork/plan.py,sha256=5znxbnGO-3aL_SRDMRNNrDPJs_6hgU8yGiFnwPy69EY,34320
15
+ pyerualjetwork/plan_cuda.py,sha256=KoKjsoWTLM-q07G1Gy0-LYXGlp15Fno6JqHz-Jzi_yE,35983
16
+ pyerualjetwork/planeat.py,sha256=VtWtWndbKoFNYTWd1EsyKBV4Vp5U6cc7uWDgQ4WjHqo,40248
17
+ pyerualjetwork/planeat_cuda.py,sha256=fSn28ZbxctPvBjpKgtv_uGwwUdTEXkBizy76mMlZYJ0,40237
18
+ pyerualjetwork/ui.py,sha256=wu2BhU1k-w3Kcho5Jtq4SEKe68ftaUeRGneUOSCVDjU,575
19
+ pyerualjetwork/visualizations.py,sha256=QaYSIyVkJZ8NqpBKArQKkI1y37nCQo_KIM98IMssnRc,28766
20
+ pyerualjetwork/visualizations_cuda.py,sha256=F60vQ92AXlMgBka3InXnOtGoM25vQJAlBIU2AlYTwks,29200
21
+ pyerualjetwork-4.1.8.dist-info/METADATA,sha256=ZhjLwRdVpV6yuxJD4-ExuvsLeqo-EtSVdfqVqWw7wKs,7793
22
+ pyerualjetwork-4.1.8.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
23
+ pyerualjetwork-4.1.8.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
24
+ pyerualjetwork-4.1.8.dist-info/RECORD,,
@@ -1,24 +0,0 @@
1
- pyerualjetwork/__init__.py,sha256=47FoEu3nH5W85OrbFZXsfegly9PKg-oHIAk82AvVCKE,2450
2
- pyerualjetwork/activation_functions.py,sha256=WWOdMd5pI6ZKe-ieKCIsKAYPQODHuXYxx7tzhA5xjes,11767
3
- pyerualjetwork/activation_functions_cuda.py,sha256=KmXJ5Cdig46XAMYakXFPEOlxSxtFJjD21-i3nGtxPjE,11807
4
- pyerualjetwork/data_operations.py,sha256=ZM24BuPsIAtI0a_Exr4HgCjmlb285wEeO8juFY9sJr0,14680
5
- pyerualjetwork/data_operations_cuda.py,sha256=IrLQkyf5FNNy4kfFcYDToueRnMDdXk7W4ufzpgwxA4k,17267
6
- pyerualjetwork/help.py,sha256=OZghUy7GZTgEX_i3NYtgcpzUgCDOi6r2vVUF1ROkFiI,774
7
- pyerualjetwork/loss_functions.py,sha256=6PyBI232SQRGuFnG3LDGvnv_PUdWzT2_2mUODJiejGI,618
8
- pyerualjetwork/loss_functions_cuda.py,sha256=C93IZJcrOpT6HMK9x1O4AHJWXYTkN5WZiqdssPbvAPk,617
9
- pyerualjetwork/memory_operations.py,sha256=g_DU1g_Xx8BXZ253CV_DvhHI65cXaLNT4iBhlPuPN_w,13487
10
- pyerualjetwork/metrics.py,sha256=q7MkhnZDRbCjFBDDfUgrl8lBYnUT_1ro1LxeBq105pI,6077
11
- pyerualjetwork/metrics_cuda.py,sha256=73h9GC7XwmnFCVzFEEiPQfF8CwHIz2wsCbxpZrJtYgw,5061
12
- pyerualjetwork/model_operations.py,sha256=hnhR8dtoICNJWIwGgJ65-LN3GYN_DYH4LMe6YpZVbnI,12967
13
- pyerualjetwork/model_operations_cuda.py,sha256=XnKKq54ZLaqCm-NaJ6d8IToACKcKg2Ttq6moowVRRWo,13365
14
- pyerualjetwork/plan.py,sha256=ZadbCULBnfd8yrE21-shzifnILzQPZ9jEy6amQxuuvw,35251
15
- pyerualjetwork/plan_cuda.py,sha256=y1YoZQCSXGyLduG-IdcSPk2DPMAYG5G2pOfDefRZw0w,36287
16
- pyerualjetwork/planeat.py,sha256=6uEcCF4bV1_W1aQUTKQjfnDgWp6rP2oluKFo5Y37k7o,39517
17
- pyerualjetwork/planeat_cuda.py,sha256=GXYt_00rDKkDKJrhjE8hHOtu4U_pQZM1yZ6XrMpQo2c,39574
18
- pyerualjetwork/ui.py,sha256=wu2BhU1k-w3Kcho5Jtq4SEKe68ftaUeRGneUOSCVDjU,575
19
- pyerualjetwork/visualizations.py,sha256=9naPYMQKpkMcP_GEaBK90FEZAlImT_f-lgRqVCwvcb8,28660
20
- pyerualjetwork/visualizations_cuda.py,sha256=blOM-VQnAT_qzM3i_OWjL5C1qnUtYctEvja-a_X4Z0w,29085
21
- pyerualjetwork-4.1.6.dist-info/METADATA,sha256=xRiAQOkHwFGtNVJDRHGgGS6KbFbWm8B3C2dI-dP8GUM,7793
22
- pyerualjetwork-4.1.6.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
23
- pyerualjetwork-4.1.6.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
24
- pyerualjetwork-4.1.6.dist-info/RECORD,,