pyerualjetwork 2.6.4__py3-none-any.whl → 2.6.5__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.
plan/plan.py CHANGED
@@ -15,6 +15,7 @@ import math
15
15
  from scipy.special import expit, softmax
16
16
  import matplotlib.pyplot as plt
17
17
  import seaborn as sns
18
+ from tqdm import tqdm
18
19
 
19
20
  # BUILD -----
20
21
 
@@ -25,7 +26,6 @@ def fit(
25
26
  show_training,
26
27
  show_count= None,
27
28
  val= None,
28
- val_count= None,
29
29
  x_val= None,
30
30
  y_val= None,
31
31
  activation_potentiation=None # (float): Input activation_potentiation (optional)
@@ -39,7 +39,7 @@ def fit(
39
39
  y_train (list[num]): List of target labels. (one hot encoded)
40
40
  show_training (bool, str): True, None or'final'
41
41
  show_count (None, int): How many learning steps in total will be displayed in a single figure? (Adjust according to your hardware) Default: 10 (optional)
42
- val (None or True): validation in training process ? None or True Default: None
42
+ val (None, True or 'final'): validation in training process ? None, True or 'final' Default: None
43
43
  val_count (None, int): After how many examples learned will an accuracy test be performed? Default: 0.1 (%10) (optional)
44
44
  x_val (list[num]): List of validation data. (optional) Default: x_train
45
45
  y_val (list[num]): (list[num]): List of target labels. (one hot encoded) (optional) Default: y_train
@@ -60,14 +60,10 @@ def fit(
60
60
  x_val = x_train
61
61
  y_val = y_train
62
62
 
63
- if val == True and val_count == None:
64
-
65
- val_count = 0.1
66
-
67
- if val == True and val_count != None:
63
+ if val == True or val == 'final':
64
+
65
+ val_bar = tqdm(total=1, desc="Training / Validating Accuracy", ncols=120)
68
66
 
69
- val_count = int(len(x_train) * val_count)
70
- val_count_copy = val_count
71
67
 
72
68
  if show_count == None:
73
69
 
@@ -89,25 +85,23 @@ def fit(
89
85
 
90
86
  neurons = [len(class_count), len(class_count)]
91
87
  layers = ['fex']
92
- val_list = [None]
88
+ val_list = []
93
89
 
94
90
  x_train[0] = np.array(x_train[0])
95
91
  x_train[0] = x_train[0].ravel()
96
92
  x_train_size = len(x_train[0])
97
93
 
98
- W = weight_identification(
99
- len(layers) - 1, len(class_count), neurons, x_train_size)
94
+ STPW = weight_identification(
95
+ len(layers) - 1, len(class_count), neurons, x_train_size) # STPW = SHORT TIME POTENTIATION WEIGHT
96
+
97
+ LTPW = [1] * len(STPW) # LTPW = LONG TIME POTENTIATION WEIGHT
100
98
 
101
- trained_W = [1] * len(W)
102
- print(Fore.GREEN + "Train Started with 0 ERROR" + Style.RESET_ALL)
103
- start_time = time.time()
104
99
  y = decode_one_hot(y_train)
105
100
 
106
101
  for index, inp in enumerate(x_train):
107
-
102
+
108
103
  progress = index / len(x_train) * 100
109
104
 
110
- uni_start_time = time.time()
111
105
  inp = np.array(inp)
112
106
  inp = inp.ravel()
113
107
 
@@ -123,48 +117,37 @@ def fit(
123
117
  neural_layer = normalization(neural_layer)
124
118
 
125
119
  if Layer == 'fex':
126
- W[Lindex] = fex(neural_layer, W[Lindex], True, y[index], activation_potentiation)
120
+ STPW[Lindex] = fex(neural_layer, STPW[Lindex], True, y[index], activation_potentiation)
127
121
 
128
- for i, w in enumerate(W):
129
- trained_W[i] = trained_W[i] + w
122
+ for i, w in enumerate(STPW):
123
+ LTPW[i] = LTPW[i] + w
130
124
 
131
125
 
132
126
  if val == True:
127
+
128
+ if show_training == True:
129
+ try:
130
+ plt.close(fig)
133
131
 
134
- if index == val_count:
135
-
136
- if show_training == True:
137
- try:
138
- plt.close(fig)
139
-
140
- except:
141
- pass
142
-
143
- val_count += val_count_copy
144
-
145
- layers.append('cat')
146
- trained_W.append(np.eye(len(class_count)))
147
-
148
- validation_model = evaluate(x_val, y_val, None, trained_W)
149
-
150
- layers.pop()
151
- trained_W.pop()
152
-
153
- val_acc = validation_model[get_acc()]
132
+ except:
133
+ pass
154
134
 
155
- val_list.append(val_acc)
135
+ validation_model = evaluate(x_val, y_val, None, LTPW, activation_potentiation, None)
136
+
137
+ val_acc = validation_model[get_acc()]
156
138
 
139
+ val_list.append(val_acc)
140
+
141
+ if index == 0:
157
142
 
158
- plt.plot(val_list, linestyle='-',
159
- color='r')
143
+ val_bar.update(val_acc)
144
+
145
+ if index != 0:
146
+
147
+ val_acc = val_acc - val_list[index - 1]
160
148
 
161
- progress_status = f"{progress:.1f}"
162
- plt.title('Validation accuracy graph. Amount of data learned by the model: % ' + progress_status)
163
- plt.xlabel('Learning Progress')
164
- plt.ylabel('Accuracy')
165
- plt.ylim(0, 1)
166
- plt.draw()
167
- plt.pause(0.1)
149
+ val_bar.update(val_acc)
150
+
168
151
 
169
152
  if show_training == True:
170
153
 
@@ -220,21 +203,6 @@ def fit(
220
203
  W = weight_identification(
221
204
  len(layers) - 1, len(class_count), neurons, x_train_size)
222
205
 
223
- uni_end_time = time.time()
224
-
225
- calculating_est = round(
226
- (uni_end_time - uni_start_time) * (len(x_train) - index), 3)
227
-
228
- if calculating_est < 60:
229
- print('\rest......(sec):', calculating_est, '\n', end="")
230
-
231
- elif calculating_est > 60 and calculating_est < 3600:
232
- print('\rest......(min):', calculating_est/60, '\n', end="")
233
-
234
- elif calculating_est > 3600:
235
- print('\rest......(h):', calculating_est/3600, '\n', end="")
236
-
237
- print('\rTraining: ', index, "/", len(x_train), "\n", end="")
238
206
 
239
207
  if show_training == 'final':
240
208
 
@@ -257,25 +225,18 @@ def fit(
257
225
  plt.pause(0.1)
258
226
 
259
227
 
260
- EndTime = time.time()
261
-
262
- calculating_est = round(EndTime - start_time, 2)
263
-
264
- print(Fore.GREEN + " \nTrain Finished with 0 ERROR\n" + Style.RESET_ALL)
265
-
266
- if calculating_est < 60:
267
- print('Total training time(sec): ', calculating_est)
268
-
269
- elif calculating_est > 60 and calculating_est < 3600:
270
- print('Total training time(min): ', calculating_est/60)
271
-
272
- elif calculating_est > 3600:
273
- print('Total training time(h): ', calculating_est/3600)
274
-
228
+ if val == 'final':
275
229
 
230
+ validation_model = evaluate(x_val, y_val, None, LTPW, activation_potentiation, None)
231
+
232
+ val_acc = validation_model[get_acc()]
233
+
234
+ val_list.append(val_acc)
235
+
236
+ val_bar.update(val_acc)
276
237
 
277
238
 
278
- return trained_W
239
+ return LTPW
279
240
 
280
241
  # FUNCTIONS -----
281
242
 
@@ -490,7 +451,8 @@ def evaluate(
490
451
  y_test, # list[num]: Test labels.
491
452
  show_metrices, # show_metrices (bool): (True or False)
492
453
  W, # list[num]: Weight matrix list of the neural network.
493
- activation_potentiation=None # activation_potentiation (float or None): Threshold value for comparison. (optional)
454
+ activation_potentiation=None, # activation_potentiation (float or None): Threshold value for comparison. (optional)
455
+ acc_bar_status = True
494
456
  ) -> tuple:
495
457
  infoTestModel = """
496
458
  Tests the neural network model with the given test data.
@@ -501,6 +463,7 @@ def evaluate(
501
463
  show_metrices (bool): (True or False)
502
464
  W (list[num]): Weight matrix list of the neural network.
503
465
  activation_potentiation (float or None): Threshold value for comparison. (optional)
466
+ acc_bar_status (bool): Loading bar for accuracy (True or None)
504
467
 
505
468
  Returns:
506
469
  tuple: A tuple containing the predicted labels and the accuracy of the model.
@@ -517,9 +480,10 @@ def evaluate(
517
480
  for i, w in enumerate(W):
518
481
  Wc[i] = np.copy(w)
519
482
  print('\rCopying weights.....', i+1, '/', len(W), end="")
520
-
521
- print(Fore.GREEN + "\n\nTest Started with 0 ERROR\n" + Style.RESET_ALL)
522
- start_time = time.time()
483
+
484
+ # print(Fore.GREEN + "\n\nTest Started with 0 ERROR\n" + Style.RESET_ALL)
485
+ if acc_bar_status == True:
486
+ acc_bar = tqdm(total=1, desc="Test Accuracy", ncols=75)
523
487
  for inpIndex, Input in enumerate(x_test):
524
488
  Input = np.array(Input)
525
489
  Input = Input.ravel()
@@ -532,7 +496,7 @@ def evaluate(
532
496
 
533
497
  if Layer == 'fex':
534
498
  neural_layer = fex(neural_layer, W[index], False, None, activation_potentiation)
535
-
499
+
536
500
 
537
501
  for i, w in enumerate(Wc):
538
502
  W[i] = np.copy(w)
@@ -541,56 +505,25 @@ def evaluate(
541
505
  if RealOutput == PredictedOutput:
542
506
  true += 1
543
507
  acc = true / len(y_test)
544
- if show_metrices == True:
545
- acc_list.append(acc)
546
- y_preds[inpIndex] = PredictedOutput
547
-
548
- uni_end_time = time.time()
549
-
550
- calculating_est = round(
551
- (uni_end_time - uni_start_time) * (len(x_test) - inpIndex), 3)
552
-
553
- if calculating_est < 60:
554
- print('\rest......(sec):', calculating_est, '\n', end="")
555
- print('\rTest accuracy: ', acc, "\n", end="")
556
508
 
557
- elif calculating_est > 60 and calculating_est < 3600:
558
- print('\rest......(min):', calculating_est/60, '\n', end="")
559
- print('\rTest accuracy: ', acc, "\n", end="")
560
509
 
561
- elif calculating_est > 3600:
562
- print('\rest......(h):', calculating_est/3600, '\n', end="")
563
- print('\rTest accuracy: ', acc, "\n", end="")
510
+ acc_list.append(acc)
511
+ y_preds[inpIndex] = PredictedOutput
512
+
513
+ if acc_bar_status == True:
514
+ if inpIndex == 0:
515
+ acc_bar.update(acc)
516
+
517
+ else:
518
+ acc = acc - acc_list[inpIndex - 1]
519
+ acc_bar.update(acc)
520
+
564
521
  if show_metrices == True:
565
522
  plot_evaluate(y_test, y_preds, acc_list)
566
523
 
567
- EndTime = time.time()
524
+
568
525
  for i, w in enumerate(Wc):
569
526
  W[i] = np.copy(w)
570
-
571
- calculating_est = round(EndTime - start_time, 2)
572
-
573
- print(Fore.GREEN + "\nTest Finished with 0 ERROR\n")
574
-
575
- if calculating_est < 60:
576
- print('Total testing time(sec): ', calculating_est)
577
-
578
- elif calculating_est > 60 and calculating_est < 3600:
579
- print('Total testing time(min): ', calculating_est/60)
580
-
581
- elif calculating_est > 3600:
582
- print('Total testing time(h): ', calculating_est/3600)
583
-
584
- if acc >= 0.8:
585
- print(Fore.GREEN + '\nTotal Test accuracy: ',
586
- acc, '\n' + Style.RESET_ALL)
587
-
588
- elif acc < 0.8 and acc > 0.6:
589
- print(Fore.MAGENTA + '\nTotal Test accuracy: ',
590
- acc, '\n' + Style.RESET_ALL)
591
-
592
- elif acc <= 0.6:
593
- print(Fore.RED + '\nTotal Test accuracy: ', acc, '\n' + Style.RESET_ALL)
594
527
 
595
528
  except:
596
529
 
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyerualjetwork
3
+ Version: 2.6.5
4
+ Summary: Visual improvements, new option added for val paramater in fit function: 'final'. Removed: val_count parameter.
5
+ Author: Hasan Can Beydili
6
+ Author-email: tchasancan@gmail.com
7
+ Keywords: model evaluation,classifcation,potentiation learning artficial neural networks
8
+
@@ -0,0 +1,6 @@
1
+ plan/__init__.py,sha256=gmaz8lnQfl18MbOQwabBUPmShajK5S99jfyY-hQe8tc,502
2
+ plan/plan.py,sha256=QP0z-MfKFhSnWqAEBLZ2L1sJUhTnkefeXAsgJTA_fYU,53321
3
+ pyerualjetwork-2.6.5.dist-info/METADATA,sha256=GbAd2Jfv-c3Lt_Ut0MgjmHg1ETBNvAePdVqRiXA-pWw,338
4
+ pyerualjetwork-2.6.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
+ pyerualjetwork-2.6.5.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
+ pyerualjetwork-2.6.5.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: pyerualjetwork
3
- Version: 2.6.4
4
- Summary: Code improvements
5
- Author: Hasan Can Beydili
6
- Author-email: tchasancan@gmail.com
7
- Keywords: model evaluation,classifcation,pruning learning artficial neural networks
8
-
@@ -1,6 +0,0 @@
1
- plan/__init__.py,sha256=gmaz8lnQfl18MbOQwabBUPmShajK5S99jfyY-hQe8tc,502
2
- plan/plan.py,sha256=XcEAeyweDvP4WRRNdL_hOue_fOeqf1_rXsJ75q4sEdk,55940
3
- pyerualjetwork-2.6.4.dist-info/METADATA,sha256=9_sisdjKeZGNIwLdOa_OFXmcPXrEga9FgRUyIfO-e-w,239
4
- pyerualjetwork-2.6.4.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
- pyerualjetwork-2.6.4.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
- pyerualjetwork-2.6.4.dist-info/RECORD,,