pyerualjetwork 2.5.5__py3-none-any.whl → 2.5.6__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
@@ -1,3 +1,12 @@
1
+ # optic
2
+
3
+ # -*- coding: utf-8 -*-
4
+ """
5
+ Created on Fri Jun 21 05:21:35 2024
6
+
7
+ @author: hasan
8
+ """
9
+
1
10
  # -*- coding: utf-8 -*-
2
11
 
3
12
 
@@ -23,8 +32,13 @@ import seaborn as sns
23
32
 
24
33
  def fit(
25
34
  x_train: List[Union[int, float]],
26
- y_train: List[Union[int, float, str]], # At least two.. and one hot encoded
35
+ y_train: List[Union[int, float]], # At least two.. and one hot encoded
27
36
  show_training,
37
+ show_count= None,
38
+ val_count= None,
39
+ val= None,
40
+ x_val= None,
41
+ y_val= None,
28
42
  activation_potential=None # (float): Input activation potential (optional)
29
43
  ) -> str:
30
44
 
@@ -33,26 +47,48 @@ def fit(
33
47
 
34
48
  Args:
35
49
  x_train (list[num]): List of input data.
36
- y_train (list[num]): List of y_train. (one hot encoded)
37
- show_training (bool, str): True, None or 'final'
38
- activation_potential (float): Input activation potential (optional)
50
+ y_train (list[num]): List of target labels. (one hot encoded)
51
+ show_training (bool, str): True, None or'final'
52
+ 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)
53
+ val_count (None, int): After how many examples learned will an accuracy test be performed? Default: 100 (optional)
54
+ x_val (list[num]): List of validation data. (optional) Default: x_train
55
+ y_val (list[num]): (list[num]): List of target labels. (one hot encoded) (optional) Default: y_train
56
+ activation_potential (float): Input activation potential (for binary injection) (optional) in range: -1, 1
39
57
  Returns:
40
58
  list([num]): (Weight matrices list, train_predictions list, Train_acc).
41
59
  error handled ?: Process status ('e')
42
60
  """
43
-
44
- if activation_potential != None:
45
-
46
- if activation_potential < 0 or activation_potential > 1:
47
-
48
- print(Fore.RED + "ERROR101: ACTIVATION potential value must be in range 0-1. from: fit",infoPLAN)
49
- return 'e'
61
+
50
62
 
51
63
  if len(x_train) != len(y_train):
64
+
52
65
  print(Fore.RED + "ERROR301: x_train list and y_train list must be same length. from: fit", infoPLAN)
53
66
  return 'e'
67
+
68
+ if x_val == None and y_val == None:
69
+
70
+ x_val = x_train
71
+ y_val = y_train
72
+
73
+ if val == True and val_count == None:
74
+
75
+ val_count = 100
76
+
77
+
78
+ if show_training == True or show_training == 'final' and show_count == None:
79
+
80
+ show_count = 10
81
+
82
+ if show_training == True or show_training == 'final':
54
83
 
84
+ row, col = shape_control(x_train)
85
+
86
+ if row == 0:
87
+
88
+ return 'e'
89
+
55
90
  class_count = set()
91
+
56
92
  for sublist in y_train:
57
93
 
58
94
  class_count.add(tuple(sublist))
@@ -63,6 +99,7 @@ def fit(
63
99
 
64
100
  neurons = [len(class_count), len(class_count)]
65
101
  layers = ['fex']
102
+ val_list = [None]
66
103
 
67
104
  x_train[0] = np.array(x_train[0])
68
105
  x_train[0] = x_train[0].ravel()
@@ -77,6 +114,9 @@ def fit(
77
114
  y = decode_one_hot(y_train)
78
115
 
79
116
  for index, inp in enumerate(x_train):
117
+
118
+ progress = index / len(x_train) * 100
119
+
80
120
  uni_start_time = time.time()
81
121
  inp = np.array(inp)
82
122
  inp = inp.ravel()
@@ -98,43 +138,64 @@ def fit(
98
138
  for i, w in enumerate(W):
99
139
  trained_W[i] = trained_W[i] + w
100
140
 
101
- if show_training == True or show_training == 'final':
102
-
103
- try:
104
- row = x_train[1].shape[0]
105
- col = x_train[1].shape[1]
106
-
107
- except:
108
-
109
- print(Fore.MAGENTA + 'WARNING: You trying show_training but inputs is raveled. x_train inputs should be reshaped for show_training.' + Style.RESET_ALL)
110
-
111
- try:
112
- row, col = find_numbers(len(x_train[0]))
113
-
114
- except:
115
-
116
- print(Fore.RED + 'ERROR: Change show_training to None. Input length cannot be reshaped', infoPLAN + Style.RESET_ALL)
117
- return 'e'
118
-
141
+
142
+ if val == True:
143
+
144
+ if index %val_count == 0:
145
+
146
+ layers.append('cat')
147
+ trained_W.append(np.eye(len(class_count)))
148
+
149
+ validation_model = evaluate(x_val, y_val, None, trained_W)
150
+
151
+ layers.pop()
152
+ trained_W.pop()
153
+
154
+ val_acc = validation_model[get_acc()]
155
+
156
+ val_list.append(val_acc)
157
+
158
+
159
+ plt.plot(val_list, linestyle='-',
160
+ color='r')
161
+
162
+ progress_status = f"{progress:.1f}"
163
+ plt.title('Validation accuracy graph. Amount of data learned by the model: % ' + progress_status)
164
+ plt.xlabel('Learning Progress')
165
+ plt.ylabel('Accuracy')
166
+ plt.ylim(0, 1)
167
+ plt.draw()
168
+ plt.pause(0.1)
169
+
170
+ if show_training == True:
171
+
172
+ if index %show_count == 0:
173
+
174
+ if index != 0:
175
+ plt.close(fig)
176
+
177
+ fig, ax = plt.subplots(1, len(class_count), figsize=(18, 14))
119
178
 
120
- if show_training == True:
121
179
 
122
- fig, ax = plt.subplots(1, len(class_count), figsize=(18, 14))
123
-
124
- for j in range(len(class_count)):
125
-
126
- mat = trained_W[0][j,:].reshape(row, col)
127
-
128
- ax[j].imshow(mat, interpolation='sinc', cmap='viridis')
129
- ax[j].set_aspect('equal')
130
-
131
- ax[j].set_xticks([])
132
- ax[j].set_yticks([])
133
- ax[j].set_title(f'{j+1}. Neuron')
134
-
135
-
136
- plt.show()
137
-
180
+ for j in range(len(class_count)):
181
+
182
+ mat = trained_W[0][j,:].reshape(row, col)
183
+
184
+ ax[j].imshow(mat, interpolation='sinc', cmap='viridis')
185
+ ax[j].set_aspect('equal')
186
+
187
+ ax[j].set_xticks([])
188
+ ax[j].set_yticks([])
189
+ ax[j].set_title(f'{j+1}. Neuron')
190
+
191
+ progress_status = f"{progress:.1f}"
192
+ fig.suptitle('Neurons Learning Progress: % ' + progress_status)
193
+ plt.draw()
194
+ plt.pause(0.1)
195
+
196
+
197
+
198
+
138
199
  W = weight_identification(
139
200
  len(layers) - 1, len(class_count), neurons, x_train_size)
140
201
 
@@ -156,32 +217,24 @@ def fit(
156
217
 
157
218
  if show_training == 'final':
158
219
 
159
- fig, ax = plt.subplots(1, len(class_count), figsize=(18, 14))
160
-
161
- try:
162
-
163
- row = x_train[1].shape[0]
164
- col = x_train[1].shape[1]
165
-
166
- except:
167
-
168
- print(Fore.MAGENTA + 'WARNING: You try train showing but inputs is raveled. x_train inputs should be reshaped for training_show.', infoPLAN + Style.RESET_ALL)
220
+ fig, ax = plt.subplots(1, len(class_count), figsize=(18, 14))
169
221
 
170
- row, col = find_numbers(len(x_train[0]))
222
+ for j in range(len(class_count)):
171
223
 
172
- for j in range(len(class_count)):
224
+ mat = trained_W[0][j,:].reshape(row, col)
173
225
 
174
- mat = trained_W[0][j,:].reshape(row, col)
226
+ ax[j].imshow(mat, interpolation='sinc', cmap='viridis')
227
+ ax[j].set_aspect('equal')
228
+
229
+ ax[j].set_xticks([])
230
+ ax[j].set_yticks([])
231
+ ax[j].set_title(f'{j+1}. Neuron')
175
232
 
176
- ax[j].imshow(mat, interpolation='sinc', cmap='viridis')
177
- ax[j].set_aspect('equal')
178
-
179
- ax[j].set_xticks([])
180
- ax[j].set_yticks([])
181
- ax[j].set_title(f'{j+1}. Neuron')
233
+ progress_status = f"{progress:.1f}"
234
+ fig.suptitle('Neurons Learning Progress: % ' + progress_status)
235
+ plt.draw()
236
+ plt.pause(0.1)
182
237
 
183
-
184
- plt.show()
185
238
 
186
239
  EndTime = time.time()
187
240
 
@@ -206,6 +259,26 @@ def fit(
206
259
 
207
260
  # FUNCTIONS -----
208
261
 
262
+ def shape_control(x_train):
263
+
264
+ try:
265
+ row = x_train[1].shape[0]
266
+ col = x_train[1].shape[1]
267
+
268
+ except:
269
+
270
+ print(Fore.MAGENTA + 'WARNING: You trying show_training but inputs is raveled. x_train inputs should be reshaped for show_training.' + Style.RESET_ALL)
271
+
272
+ try:
273
+ row, col = find_numbers(len(x_train[0]))
274
+
275
+ except:
276
+
277
+ print(Fore.RED + 'ERROR: Change show_training to None. Input length cannot be reshaped', infoPLAN + Style.RESET_ALL)
278
+ return [0, 0]
279
+
280
+ return row, col
281
+
209
282
  def find_numbers(n):
210
283
  if n <= 1:
211
284
  raise ValueError("Parameter 'n' must be greater than 1.")
@@ -1588,4 +1661,4 @@ def get_preds():
1588
1661
 
1589
1662
  def get_acc():
1590
1663
 
1591
- return 2
1664
+ return 2
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 2.5.5
4
- Summary: standard_scaler function improved. Changes possibily nan values to 0
3
+ Version: 2.5.6
4
+ Summary: New optional parameters added for fit function, x_val, y_val show_count, val_count, val. For more information please read user document
5
5
  Author: Hasan Can Beydili
6
6
  Author-email: tchasancan@gmail.com
7
7
  Keywords: model evaluation,classifcation,pruning learning artficial neural networks
@@ -0,0 +1,6 @@
1
+ plan/__init__.py,sha256=gmaz8lnQfl18MbOQwabBUPmShajK5S99jfyY-hQe8tc,502
2
+ plan/plan.py,sha256=-D6-2c5OtH5DMRJX8P5NISo_DbOvpaf2rHYvFfgDI80,55021
3
+ pyerualjetwork-2.5.6.dist-info/METADATA,sha256=NyHNKEa9B2FAUGaHeM41O7aiObTgLVIb3wvc8JxcTrw,357
4
+ pyerualjetwork-2.5.6.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
+ pyerualjetwork-2.5.6.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
+ pyerualjetwork-2.5.6.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- plan/__init__.py,sha256=gmaz8lnQfl18MbOQwabBUPmShajK5S99jfyY-hQe8tc,502
2
- plan/plan.py,sha256=Dt_PXXMLx0J4e-gqyRAN4YqPZA2UX0YlCaKrd5Rqd5Q,53491
3
- pyerualjetwork-2.5.5.dist-info/METADATA,sha256=9320HpScX-TASWWJNe3uruu1-8kOZe-pBAQKDXkF6ag,290
4
- pyerualjetwork-2.5.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
- pyerualjetwork-2.5.5.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
- pyerualjetwork-2.5.5.dist-info/RECORD,,