pyerualjetwork 2.7.8__py3-none-any.whl → 2.8.0__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/Untitled-1.py ADDED
@@ -0,0 +1,31 @@
1
+
2
+
3
+ import plan
4
+ import time
5
+ from colorama import Fore
6
+ import numpy as np
7
+ from sklearn.datasets import load_digits
8
+
9
+ # TRAIN
10
+
11
+ data = load_digits()
12
+
13
+ X = data.data
14
+ y = data.target
15
+
16
+ X = plan.normalization(X)
17
+
18
+ x_train, x_test, y_train, y_test = plan.split(X, y, 0.4, 42)
19
+
20
+
21
+ y_train, y_test = plan.encode_one_hot(y_train, y_test)
22
+
23
+
24
+ x_test, y_test = plan.auto_balancer(x_test, y_test)
25
+
26
+
27
+ W = plan.fit(x_train, y_train, val=True)
28
+
29
+ # TEST
30
+
31
+ test_model = plan.evaluate(x_test, y_test,show_metrices=True, W=W)
plan/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  # Bu dosya, plan modülünün ana giriş noktasıdır.
4
4
 
5
- from .plan import auto_balancer, normalization, Softmax, Sigmoid, Relu, weight_identification, fex, fit, evaluate, save_model, load_model, predict_model_ssd, predict_model_ram, get_weights, get_df, get_preds, get_acc, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate, manuel_balancer, weight_normalization
5
+ from .plan import auto_balancer, normalization, Softmax, Sigmoid, Relu, weight_identification, fex, fit, evaluate, save_model, load_model, predict_model_ssd, predict_model_ram, get_weights, get_df, get_preds, get_acc, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate, manuel_balancer, weight_normalization, plot_decision_space
plan/plan.py CHANGED
@@ -2,7 +2,7 @@
2
2
  """
3
3
  Created on Tue Jun 18 23:32:16 2024
4
4
 
5
- @author: hasan
5
+ @author: hasan can
6
6
  """
7
7
 
8
8
  import pandas as pd
@@ -137,25 +137,31 @@ def fit(
137
137
  if Layer == 'fex':
138
138
  STPW[Lindex] = fex(neural_layer, STPW[Lindex], True, y[index], activation_potentiation)
139
139
 
140
+ STPW = normalization(STPW)
141
+
140
142
  for i, w in enumerate(STPW):
141
143
  LTPW[i] = LTPW[i] + w
142
144
 
143
145
 
144
- if val == True and index == val_count:
145
-
146
-
147
- val_count += val_count_copy
146
+ if val == True:
148
147
 
149
- validation_model = evaluate(x_val, y_val, LTPW, activation_potentiation, None)
148
+ validation_model = evaluate(x_val, y_val, LTPW,bar_status=False, activation_potentiation=activation_potentiation, show_metrices=None)
150
149
 
151
150
  val_acc = validation_model[get_acc()]
151
+ val_preds = validation_model[get_preds()]
152
+
153
+
154
+ plot_decision_space(x_val, val_preds, s=100, color='tab20')
155
+
152
156
 
157
+ plt.pause(0.0001)
158
+
153
159
  val_list.append(val_acc)
154
160
 
155
161
  if v_iter == 0:
156
162
 
157
163
  val_bar.update(val_acc)
158
-
164
+ pass
159
165
 
160
166
  if v_iter != 0:
161
167
 
@@ -243,16 +249,21 @@ def fit(
243
249
 
244
250
  if val == 'final':
245
251
 
246
- validation_model = evaluate(x_val, y_val, LTPW, activation_potentiation, bar_status=None, show_metrices=None)
247
-
252
+ validation_model = evaluate(x_val, y_val, LTPW,bar_status=False, activation_potentiation=activation_potentiation, show_metrices=None)
253
+
248
254
  val_acc = validation_model[get_acc()]
249
-
255
+ val_preds = validation_model[get_preds()]
256
+
257
+
258
+ plot_decision_space(x_val, val_preds, s=100, color='tab20')
259
+
250
260
  val_list.append(val_acc)
251
261
 
252
262
  val_bar.update(val_acc)
253
-
263
+
264
+
254
265
  LTPW = normalization(LTPW)
255
-
266
+
256
267
  return LTPW
257
268
 
258
269
  # FUNCTIONS -----
@@ -485,23 +496,28 @@ def evaluate(
485
496
  Returns:
486
497
  tuple: A tuple containing the predicted labels and the accuracy of the model.
487
498
  """
499
+
500
+ predict_probabilitys = []
501
+ real_classes = []
502
+ predict_classes = []
503
+
488
504
  try:
489
505
  layers = ['fex']
490
506
 
491
507
  Wc = [0] * len(W) # Wc = Weight copy
492
508
  true = 0
493
- y_preds = [-1] * len(y_test)
509
+ y_preds = []
494
510
  acc_list = []
495
511
 
496
512
  for i, w in enumerate(W):
497
513
  Wc[i] = np.copy(w)
498
514
 
499
-
515
+
500
516
  if bar_status == True:
501
517
 
502
518
  test_progress = tqdm(total=len(x_test),leave=False, desc='Testing',ncols=120)
503
519
  acc_bar = tqdm(total=1, desc="Test Accuracy", ncols=120)
504
-
520
+
505
521
 
506
522
  for inpIndex, Input in enumerate(x_test):
507
523
  Input = np.array(Input)
@@ -516,15 +532,25 @@ def evaluate(
516
532
 
517
533
  for i, w in enumerate(Wc):
518
534
  W[i] = np.copy(w)
535
+
536
+ neural_layer = Softmax(neural_layer)
537
+ max_value = max(neural_layer)
538
+
539
+ predict_probabilitys.append(max_value)
540
+
541
+
519
542
  RealOutput = np.argmax(y_test[inpIndex])
543
+ real_classes.append(RealOutput)
520
544
  PredictedOutput = np.argmax(neural_layer)
545
+ predict_classes.append(PredictedOutput)
546
+
521
547
  if RealOutput == PredictedOutput:
522
548
  true += 1
523
549
  acc = true / len(y_test)
524
550
 
525
551
 
526
552
  acc_list.append(acc)
527
- y_preds[inpIndex] = PredictedOutput
553
+ y_preds.append(PredictedOutput)
528
554
 
529
555
  if bar_status == True:
530
556
  test_progress.update(1)
@@ -534,14 +560,14 @@ def evaluate(
534
560
  else:
535
561
  acc = acc - acc_list[inpIndex - 1]
536
562
  acc_bar.update(acc)
537
-
563
+
538
564
  if show_metrices == True:
539
- plot_evaluate(y_test, y_preds, acc_list)
565
+ plot_evaluate(x_test, y_test, y_preds, acc_list)
540
566
 
541
567
 
542
568
  for i, w in enumerate(Wc):
543
569
  W[i] = np.copy(w)
544
-
570
+
545
571
  except:
546
572
 
547
573
  print(Fore.RED + 'ERROR:' + infoTestModel + Style.RESET_ALL)
@@ -1055,7 +1081,6 @@ def synthetic_augmentation(x_train, y_train):
1055
1081
  classes = np.arange(y_train.shape[1])
1056
1082
  class_count = len(classes)
1057
1083
 
1058
- # Calculate class distribution
1059
1084
  class_distribution = {i: 0 for i in range(class_count)}
1060
1085
  for label in y:
1061
1086
  class_distribution[np.argmax(label)] += 1
@@ -1396,7 +1421,7 @@ def confusion_matrix(y_true, y_pred, class_count):
1396
1421
  return confusion
1397
1422
 
1398
1423
 
1399
- def plot_evaluate(y_test, y_preds, acc_list):
1424
+ def plot_evaluate(x_test, y_test, y_preds, acc_list):
1400
1425
 
1401
1426
  acc = acc_list[len(acc_list) - 1]
1402
1427
  y_true = decode_one_hot(y_test)
@@ -1479,42 +1504,91 @@ def plot_evaluate(y_test, y_preds, acc_list):
1479
1504
 
1480
1505
 
1481
1506
 
1482
- # Precision, Recall, F1 Score, Accuracy
1507
+
1483
1508
  metric = ['Precision', 'Recall', 'F1 Score', 'Accuracy']
1484
1509
  values = [precision, recall, f1, acc]
1485
1510
  colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728']
1486
1511
 
1487
- #
1512
+
1488
1513
  bars = axs[0, 1].bar(metric, values, color=colors)
1489
1514
 
1490
1515
 
1491
1516
  for bar, value in zip(bars, values):
1492
- axs[0, 1].text(bar.get_x() + bar.get_width() / 2, bar.get_height() - 0.05, f'{value:.2f}',
1517
+ axs[0, 1].text(bar.get_x() + bar.get_width() / 2, bar.get_height() - 0.05, f'{value:.2f}',
1493
1518
  ha='center', va='bottom', fontsize=12, color='white', weight='bold')
1494
1519
 
1495
- axs[0, 1].set_ylim(0, 1) # Y eksenini 0 ile 1 arasında sınırla
1520
+ axs[0, 1].set_ylim(0, 1)
1496
1521
  axs[0, 1].set_xlabel('Metrics')
1497
1522
  axs[0, 1].set_ylabel('Score')
1498
1523
  axs[0, 1].set_title('Precision, Recall, F1 Score, and Accuracy (Weighted)')
1499
1524
  axs[0, 1].grid(True, axis='y', linestyle='--', alpha=0.7)
1500
1525
 
1501
- # Accuracy
1502
- plt.plot(acc_list, marker='o', linestyle='-',
1503
- color='r', label='Accuracy')
1526
+
1527
+ if x_test.shape[1] > 2:
1528
+
1529
+ X_pca = pca(x_test, n_components=2)
1530
+ else:
1531
+ X_pca = x_test
1504
1532
 
1533
+ num_classes = len(y_test[0])
1505
1534
 
1506
- plt.axhline(y=1, color='g', linestyle='--', label='Maximum Accuracy')
1535
+
1536
+ cmap = plt.get_cmap('tab20')
1537
+
1538
+ axs[1,1].scatter(X_pca[:, 0], X_pca[:, 1], c=y_preds, edgecolor='k', s=100, cmap=cmap, vmin=0, vmax=num_classes - 1)
1539
+ axs[1,1].set_title("Decision Space")
1540
+
1541
+ plt.show()
1542
+
1543
+ def pca(X, n_components):
1544
+ """
1545
+ PCA algoritmasını uygulayan fonksiyon.
1507
1546
 
1547
+ Parameters:
1548
+ X (numpy array): Giriş verisi (n_samples, n_features)
1549
+ n_components (int): Saklanacak ana bileşen sayısı
1508
1550
 
1509
- plt.xlabel('Samples')
1510
- plt.ylabel('Accuracy')
1511
- plt.title('Accuracy History')
1512
- plt.legend()
1551
+ Returns:
1552
+ X_reduced (numpy array): (n_samples, n_components)
1553
+ """
1513
1554
 
1555
+ X_meaned = X - np.mean(X, axis=0)
1514
1556
 
1515
- plt.tight_layout()
1516
- plt.show()
1557
+ covariance_matrix = np.cov(X_meaned, rowvar=False)
1558
+
1559
+ eigenvalues, eigenvectors = np.linalg.eigh(covariance_matrix)
1560
+
1561
+ sorted_index = np.argsort(eigenvalues)[::-1]
1562
+ sorted_eigenvectors = eigenvectors[:, sorted_index]
1563
+ sorted_eigenvalues = eigenvalues[sorted_index]
1564
+
1565
+ eigenvectors_subset = sorted_eigenvectors[:, :n_components]
1566
+
1567
+ X_reduced = np.dot(X_meaned, eigenvectors_subset)
1568
+
1569
+ return X_reduced
1570
+
1571
+ def plot_decision_space(x, y, s=100, color='tab20'):
1572
+
1573
+ if x.shape[1] > 2:
1574
+
1575
+ X_pca = pca(x, n_components=2)
1576
+ else:
1577
+ X_pca = x
1517
1578
 
1579
+
1580
+ num_classes = len(np.unique(y))
1581
+
1582
+
1583
+ cmap = plt.get_cmap(color)
1584
+
1585
+
1586
+ plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y, edgecolor='k', s=s, cmap=cmap, vmin=0, vmax=num_classes - 1)
1587
+ plt.title("Decision Space")
1588
+
1589
+ plt.draw()
1590
+
1591
+
1518
1592
  def manuel_balancer(x_train, y_train, target_samples_per_class):
1519
1593
  """
1520
1594
  Generates synthetic examples to balance classes to the specified number of examples per class.
@@ -1,8 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 2.7.8
4
- Summary: Code improvements
3
+ Version: 2.8.0
4
+ Summary: Code improvoments
5
+ Home-page: UNKNOWN
5
6
  Author: Hasan Can Beydili
6
7
  Author-email: tchasancan@gmail.com
8
+ License: UNKNOWN
7
9
  Keywords: model evaluation,classifcation,potentiation learning artficial neural networks
10
+ Platform: UNKNOWN
11
+
12
+ UNKNOWN
8
13
 
@@ -0,0 +1,7 @@
1
+ plan/Untitled-1.py,sha256=DbHjYRG0-vHpMfNNQXZCHIKm68DzwbNnDrF9xoEr7u0,526
2
+ plan/__init__.py,sha256=WStB_zoAADCWXzIqieDZo4frPQMEZzxXnRZ6QiQKSGY,523
3
+ plan/plan.py,sha256=aZgJxaaZNyYnApF24Zj6sbGmk5D4GT2EBhAtHp1ncQk,54726
4
+ pyerualjetwork-2.8.0.dist-info/METADATA,sha256=PnX6wxeHQmH6Nf0jRcXfwTGSc7XzU1tZBTKaJC62CW8,312
5
+ pyerualjetwork-2.8.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
6
+ pyerualjetwork-2.8.0.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
7
+ pyerualjetwork-2.8.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: bdist_wheel (0.42.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- plan/__init__.py,sha256=gmaz8lnQfl18MbOQwabBUPmShajK5S99jfyY-hQe8tc,502
2
- plan/plan.py,sha256=h1u6hk_wTjbCGkKhnAz6jidxTogmMTM2AEm7nxE9WQQ,52805
3
- pyerualjetwork-2.7.8.dist-info/METADATA,sha256=921fYXjv_44__3jjG8aZWt_iHE3I6rbNdHEar_vIDOw,244
4
- pyerualjetwork-2.7.8.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
5
- pyerualjetwork-2.7.8.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
- pyerualjetwork-2.7.8.dist-info/RECORD,,