pyerualjetwork 2.3.0__tar.gz → 2.3.8__tar.gz

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.
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyerualjetwork
3
+ Version: 2.3.8
4
+ Summary: Weights post process function added: [weight_post_process](optional after training before testing.), new function: manuel_balancer. And scaler_params added for scaled models.
5
+ Author: Hasan Can Beydili
6
+ Author-email: tchasancan@gmail.com
7
+ Keywords: model evaluation,classifcation,pruning learning artficial neural networks
@@ -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_bi 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, get_pot, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate, manuel_balancer
5
+ from .plan_bi 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, get_pot, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate, manuel_balancer, weight_normalization
@@ -17,6 +17,7 @@ def fit(
17
17
  x_train: List[Union[int, float]],
18
18
  y_train: List[Union[int, float, str]], # At least two.. and one hot encoded
19
19
  activation_potential: Union[float],
20
+ show_training
20
21
  ) -> str:
21
22
 
22
23
  infoPLAN = """
@@ -26,6 +27,7 @@ def fit(
26
27
  x_train (list[num]): List of input data.
27
28
  y_train (list[num]): List of y_train. (one hot encoded)
28
29
  activation_potential (float): Input activation potential
30
+ show_training (bool, str): True, None or 'final'
29
31
 
30
32
  Returns:
31
33
  list([num]): (Weight matrices list, train_predictions list, Train_acc).
@@ -85,6 +87,34 @@ def fit(
85
87
 
86
88
  for i, w in enumerate(W):
87
89
  trained_W[i] = trained_W[i] + w
90
+
91
+ if show_training == True:
92
+
93
+ fig, ax = plt.subplots(1, 10, figsize=(18, 14))
94
+
95
+ try:
96
+ row = x_train[1].shape[0]
97
+ col = x_train[1].shape[1]
98
+ except:
99
+ print(Fore.RED + 'ERROR: You try train showing but inputs is raveled. x_train inputs to must be reshape for training_show.', infoPLAN + Style.RESET_ALL)
100
+ return 'e'
101
+
102
+ for j in range(10):
103
+
104
+
105
+ mat = trained_W[0][j,:].reshape(row, col)
106
+
107
+
108
+
109
+ ax[j].imshow(mat, interpolation='sinc', cmap='viridis')
110
+ ax[j].set_aspect('equal')
111
+
112
+ ax[j].set_xticks([])
113
+ ax[j].set_yticks([])
114
+ ax[j].set_title(f'{j+1}. Neuron')
115
+
116
+
117
+ plt.show()
88
118
 
89
119
 
90
120
  W = weight_identification(len(layers) - 1, len(class_count), neurons, x_train_size)
@@ -126,15 +156,28 @@ def fit(
126
156
  layers.append('cat')
127
157
  trained_W.append(np.eye(len(class_count)))
128
158
 
129
- for i in range(len(class_count)):
130
-
131
- for j in range(len(layers)):
159
+ return trained_W
132
160
 
133
- if layers[j] == 'fex':
161
+ def weight_normalization(
162
+ W,
163
+ class_count
164
+ ) -> str:
165
+ """
166
+ Row(Neuron) based normalization. For unbalanced models.
167
+
168
+ Args:
169
+ W (list(num)): Trained weight matrix list.
170
+ class_count (int): Class count of model.
171
+
172
+ Returns:
173
+ list([numpy_arrays],[...]): posttrained weight matices of the model. .
174
+ """
175
+
176
+ for i in range(class_count):
134
177
 
135
- trained_W[j][i,:] = normalization(trained_W[j][i,:])
178
+ W[0][i,:] = normalization(W[0][i,:])
136
179
 
137
- return trained_W
180
+ return W
138
181
 
139
182
  # FUNCTIONS -----
140
183
 
@@ -754,7 +797,7 @@ def predict_model_ssd(Input, model_name, model_path):
754
797
 
755
798
  if scaler_params != None:
756
799
 
757
- Input = standard_scaler(Input, None, scaler_params)
800
+ Input = standard_scaler(None, Input, scaler_params)
758
801
 
759
802
  layers = ['fex','cat']
760
803
 
@@ -798,7 +841,7 @@ def predict_model_ram(Input, activation_potential, scaler_params, W):
798
841
  """
799
842
  if scaler_params != None:
800
843
 
801
- Input = standard_scaler(Input, None, scaler_params)
844
+ Input = standard_scaler(None, Input, scaler_params)
802
845
 
803
846
  layers = ['fex','cat']
804
847
 
@@ -941,24 +984,30 @@ def standard_scaler(x_train, x_test, scaler_params=None):
941
984
  tuple
942
985
  Standardized training and test datasets
943
986
  """
944
- try:
987
+ try:
945
988
 
946
- if scaler_params == None:
989
+ if scaler_params == None and x_test != None:
990
+
947
991
  mean = np.mean(x_train, axis=0)
948
992
  std = np.std(x_train, axis=0)
949
- scaler_params = [mean, std]
950
-
951
- if x_test == None:
952
-
953
- train_data_scaled = (x_train - mean) / std
954
- return scaler_params, train_data_scaled
955
-
956
- elif scaler_params == None:
957
993
  train_data_scaled = (x_train - mean) / std
958
994
  test_data_scaled = (x_test - mean) / std
995
+
996
+ scaler_params = [mean, std]
997
+
959
998
  return scaler_params, train_data_scaled, test_data_scaled
999
+
1000
+ if scaler_params == None and x_test == None:
960
1001
 
961
- elif scaler_params != None:
1002
+ mean = np.mean(x_train, axis=0)
1003
+ std = np.std(x_train, axis=0)
1004
+ train_data_scaled = (x_train - mean) / std
1005
+
1006
+ scaler_params = [mean, std]
1007
+
1008
+ return scaler_params, train_data_scaled
1009
+
1010
+ if scaler_params != None:
962
1011
  test_data_scaled = (x_test - scaler_params[0]) / scaler_params[1]
963
1012
  return test_data_scaled
964
1013
 
@@ -966,7 +1015,6 @@ def standard_scaler(x_train, x_test, scaler_params=None):
966
1015
  print(
967
1016
  Fore.RED + "ERROR: x_train and x_test must be list[numpyarray] from standard_scaler" + info_standard_scaler)
968
1017
 
969
-
970
1018
  def encode_one_hot(y_train, y_test):
971
1019
  info_one_hot_encode = """
972
1020
  Performs one-hot encoding on y_train and y_test data..
@@ -1320,7 +1368,7 @@ def plot_evaluate(y_test, y_preds, acc_list):
1320
1368
  axs[0, 1].set_ylim(0, 1) # Y eksenini 0 ile 1 arasında sınırla
1321
1369
  axs[0, 1].set_xlabel('Metrics')
1322
1370
  axs[0, 1].set_ylabel('Score')
1323
- axs[0, 1].set_title('Precision, Recall, F1 Score, and Accuracy (Wighted)')
1371
+ axs[0, 1].set_title('Precision, Recall, F1 Score, and Accuracy (Weighted)')
1324
1372
  axs[0, 1].grid(True, axis='y', linestyle='--', alpha=0.7)
1325
1373
 
1326
1374
  # Accuracy
@@ -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_di 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
5
+ from .plan_di 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
@@ -21,7 +21,8 @@ import seaborn as sns
21
21
  def fit(
22
22
  x_train: List[Union[int, float]],
23
23
  # At least two.. and one hot encoded
24
- y_train: List[Union[int, float, str]],
24
+ y_train: List[Union[int, float, str]], # At least two.. and one hot encoded
25
+ show_training
25
26
  ) -> str:
26
27
 
27
28
  infoPLAN = """
@@ -30,7 +31,7 @@ def fit(
30
31
  Args:
31
32
  x_train (list[num]): List of input data.
32
33
  y_train (list[num]): List of y_train. (one hot encoded)
33
- activation_potential (float): Input activation potential
34
+ show_training (bool, str): True, None or 'final'
34
35
 
35
36
  Returns:
36
37
  list([num]): (Weight matrices list, train_predictions list, Train_acc).
@@ -57,13 +58,14 @@ def fit(
57
58
  x_train[0] = x_train[0].ravel()
58
59
  x_train_size = len(x_train[0])
59
60
 
60
- W = weight_identification(
61
+ W = pdi.weight_identification(
61
62
  len(layers) - 1, len(class_count), neurons, x_train_size)
62
63
 
63
64
  trained_W = [1] * len(W)
64
65
  print(Fore.GREEN + "Train Started with 0 ERROR" + Style.RESET_ALL)
65
66
  start_time = time.time()
66
- y = decode_one_hot(y_train)
67
+ y = pdi.decode_one_hot(y_train)
68
+
67
69
  for index, inp in enumerate(x_train):
68
70
  uni_start_time = time.time()
69
71
  inp = np.array(inp)
@@ -78,15 +80,40 @@ def fit(
78
80
 
79
81
  for Lindex, Layer in enumerate(layers):
80
82
 
81
- neural_layer = normalization(neural_layer)
83
+ neural_layer = pdi.normalization(neural_layer)
82
84
 
83
85
  if Layer == 'fex':
84
- W[Lindex] = fex(neural_layer, W[Lindex], True, y[index])
86
+ W[Lindex] = pdi.fex(neural_layer, W[Lindex], True, y[index])
85
87
 
86
88
  for i, w in enumerate(W):
87
89
  trained_W[i] = trained_W[i] + w
88
90
 
89
- W = weight_identification(
91
+ if show_training == True:
92
+
93
+ fig, ax = plt.subplots(1, 10, figsize=(18, 14))
94
+
95
+ try:
96
+ row = x_train[1].shape[0]
97
+ col = x_train[1].shape[1]
98
+ except:
99
+ print(Fore.RED + 'ERROR: You try train showing but inputs is raveled. x_train inputs to must be reshape for training_show.', infoPLAN + Style.RESET_ALL)
100
+ return 'e'
101
+
102
+ for j in range(10):
103
+
104
+ mat = trained_W[0][j,:].reshape(row, col)
105
+
106
+ ax[j].imshow(mat, interpolation='sinc', cmap='viridis')
107
+ ax[j].set_aspect('equal')
108
+
109
+ ax[j].set_xticks([])
110
+ ax[j].set_yticks([])
111
+ ax[j].set_title(f'{j+1}. Neuron')
112
+
113
+
114
+ plt.show()
115
+
116
+ W = pdi.weight_identification(
90
117
  len(layers) - 1, len(class_count), neurons, x_train_size)
91
118
 
92
119
  uni_end_time = time.time()
@@ -105,6 +132,31 @@ def fit(
105
132
 
106
133
  print('\rTraining: ', index, "/", len(x_train), "\n", end="")
107
134
 
135
+ if show_training == 'final':
136
+
137
+ fig, ax = plt.subplots(1, 10, figsize=(18, 14))
138
+
139
+ try:
140
+ row = x_train[1].shape[0]
141
+ col = x_train[1].shape[1]
142
+ except:
143
+ print(Fore.RED + 'ERROR: You try train showing but inputs is raveled. x_train inputs to must be reshape for training_show.', infoPLAN + Style.RESET_ALL)
144
+ return 'e'
145
+
146
+ for j in range(10):
147
+
148
+ mat = trained_W[0][j,:].reshape(row, col)
149
+
150
+ ax[j].imshow(mat, interpolation='sinc', cmap='viridis')
151
+ ax[j].set_aspect('equal')
152
+
153
+ ax[j].set_xticks([])
154
+ ax[j].set_yticks([])
155
+ ax[j].set_title(f'{j+1}. Neuron')
156
+
157
+
158
+ plt.show()
159
+
108
160
  EndTime = time.time()
109
161
 
110
162
  calculating_est = round(EndTime - start_time, 2)
@@ -122,20 +174,32 @@ def fit(
122
174
 
123
175
  layers.append('cat')
124
176
  trained_W.append(np.eye(len(class_count)))
125
-
126
- for i in range(len(class_count)):
127
-
128
- for j in range(len(layers)):
129
-
130
- if layers[j] == 'fex':
131
-
132
- trained_W[j][i,:] = normalization(trained_W[j][i,:])
133
177
 
134
-
178
+
135
179
  return trained_W
136
180
 
137
181
  # FUNCTIONS -----
138
182
 
183
+ def weight_normalization(
184
+ W,
185
+ class_count
186
+ ) -> str:
187
+ """
188
+ Row(Neuron) based normalization. For unbalanced models.
189
+
190
+ Args:
191
+ W (list(num)): Trained weight matrix list.
192
+ class_count (int): Class count of model.
193
+
194
+ Returns:
195
+ list([numpy_arrays],[...]): posttrained weight matices of the model. .
196
+ """
197
+
198
+ for i in range(class_count):
199
+
200
+ W[0][i,:] = normalization(W[0][i,:])
201
+
202
+ return W
139
203
 
140
204
  def weight_identification(
141
205
  layer_count, # int: Number of layers in the neural network.
@@ -733,7 +797,7 @@ def predict_model_ssd(Input, model_name, model_path):
733
797
 
734
798
  if scaler_params != None:
735
799
 
736
- Input = standard_scaler(Input, None, scaler_params)
800
+ Input = standard_scaler(None, Input, scaler_params)
737
801
 
738
802
  layers = ['fex', 'cat']
739
803
 
@@ -778,7 +842,7 @@ def predict_model_ram(Input, scaler_params, W):
778
842
 
779
843
  if scaler_params != None:
780
844
 
781
- Input = standard_scaler(Input, None, scaler_params)
845
+ Input = standard_scaler(None, Input, scaler_params)
782
846
 
783
847
  layers = ['fex', 'cat']
784
848
 
@@ -921,24 +985,30 @@ def standard_scaler(x_train, x_test, scaler_params=None):
921
985
  tuple
922
986
  Standardized training and test datasets
923
987
  """
924
- try:
988
+ try:
925
989
 
926
- if scaler_params == None:
990
+ if scaler_params == None and x_test != None:
991
+
927
992
  mean = np.mean(x_train, axis=0)
928
993
  std = np.std(x_train, axis=0)
929
- scaler_params = [mean, std]
930
-
931
- if x_test == None:
932
-
933
- train_data_scaled = (x_train - mean) / std
934
- return scaler_params, train_data_scaled
935
-
936
- elif scaler_params == None:
937
994
  train_data_scaled = (x_train - mean) / std
938
995
  test_data_scaled = (x_test - mean) / std
996
+
997
+ scaler_params = [mean, std]
998
+
939
999
  return scaler_params, train_data_scaled, test_data_scaled
1000
+
1001
+ if scaler_params == None and x_test == None:
940
1002
 
941
- elif scaler_params != None:
1003
+ mean = np.mean(x_train, axis=0)
1004
+ std = np.std(x_train, axis=0)
1005
+ train_data_scaled = (x_train - mean) / std
1006
+
1007
+ scaler_params = [mean, std]
1008
+
1009
+ return scaler_params, train_data_scaled
1010
+
1011
+ if scaler_params != None:
942
1012
  test_data_scaled = (x_test - scaler_params[0]) / scaler_params[1]
943
1013
  return test_data_scaled
944
1014
 
@@ -946,7 +1016,6 @@ def standard_scaler(x_train, x_test, scaler_params=None):
946
1016
  print(
947
1017
  Fore.RED + "ERROR: x_train and x_test must be list[numpyarray] from standard_scaler" + info_standard_scaler)
948
1018
 
949
-
950
1019
  def encode_one_hot(y_train, y_test):
951
1020
  info_one_hot_encode = """
952
1021
  Performs one-hot encoding on y_train and y_test data..
@@ -1293,7 +1362,7 @@ def plot_evaluate(y_test, y_preds, acc_list):
1293
1362
  axs[0, 1].set_ylim(0, 1) # Y eksenini 0 ile 1 arasında sınırla
1294
1363
  axs[0, 1].set_xlabel('Metrics')
1295
1364
  axs[0, 1].set_ylabel('Score')
1296
- axs[0, 1].set_title('Precision, Recall, F1 Score, and Accuracy (Wighted)')
1365
+ axs[0, 1].set_title('Precision, Recall, F1 Score, and Accuracy (Weighted)')
1297
1366
  axs[0, 1].grid(True, axis='y', linestyle='--', alpha=0.7)
1298
1367
 
1299
1368
  # Accuracy
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyerualjetwork
3
+ Version: 2.3.8
4
+ Summary: Weights post process function added: [weight_post_process](optional after training before testing.), new function: manuel_balancer. And scaler_params added for scaled models.
5
+ Author: Hasan Can Beydili
6
+ Author-email: tchasancan@gmail.com
7
+ Keywords: model evaluation,classifcation,pruning learning artficial neural networks
@@ -5,10 +5,10 @@ from setuptools import setup, find_packages
5
5
  setup(
6
6
 
7
7
  name = "pyerualjetwork",
8
- version = "2.3.0",
8
+ version = "2.3.8",
9
9
  author = "Hasan Can Beydili",
10
10
  author_email = "tchasancan@gmail.com",
11
- description= "Weights now noramlized, new function: manuel_balancer. And scaler_params added for scaled models.",
11
+ description= "Weights post process function added: [weight_post_process](optional after training before testing.), new function: manuel_balancer. And scaler_params added for scaled models.",
12
12
  packages = find_packages(),
13
13
  keywords = ["model evaluation", "classifcation", 'pruning learning artficial neural networks'],
14
14
 
@@ -1,7 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: pyerualjetwork
3
- Version: 2.3.0
4
- Summary: Weights now noramlized, new function: manuel_balancer. And scaler_params added for scaled models.
5
- Author: Hasan Can Beydili
6
- Author-email: tchasancan@gmail.com
7
- Keywords: model evaluation,classifcation,pruning learning artficial neural networks
@@ -1,7 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: pyerualjetwork
3
- Version: 2.3.0
4
- Summary: Weights now noramlized, new function: manuel_balancer. And scaler_params added for scaled models.
5
- Author: Hasan Can Beydili
6
- Author-email: tchasancan@gmail.com
7
- Keywords: model evaluation,classifcation,pruning learning artficial neural networks
File without changes