pyerualjetwork 5.35__py3-none-any.whl → 5.36__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.
- pyerualjetwork/__init__.py +1 -1
- pyerualjetwork/cpu/data_ops.py +2 -4
- pyerualjetwork/cpu/model_ops.py +49 -46
- pyerualjetwork/cuda/model_ops.py +109 -94
- {pyerualjetwork-5.35.dist-info → pyerualjetwork-5.36.dist-info}/METADATA +1 -1
- {pyerualjetwork-5.35.dist-info → pyerualjetwork-5.36.dist-info}/RECORD +8 -8
- {pyerualjetwork-5.35.dist-info → pyerualjetwork-5.36.dist-info}/WHEEL +0 -0
- {pyerualjetwork-5.35.dist-info → pyerualjetwork-5.36.dist-info}/top_level.txt +0 -0
pyerualjetwork/__init__.py
CHANGED
@@ -42,7 +42,7 @@ PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welco
|
|
42
42
|
- Contact: tchasancan@gmail.com
|
43
43
|
"""
|
44
44
|
|
45
|
-
__version__ = "5.
|
45
|
+
__version__ = "5.36"
|
46
46
|
__update__ = """* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES
|
47
47
|
* PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main
|
48
48
|
* PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
pyerualjetwork/cpu/data_ops.py
CHANGED
@@ -31,7 +31,6 @@ PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welco
|
|
31
31
|
from tqdm import tqdm
|
32
32
|
import numpy as np
|
33
33
|
from colorama import Fore, Style
|
34
|
-
import sys
|
35
34
|
import math
|
36
35
|
|
37
36
|
def encode_one_hot(y_train, y_test=None, summary=False):
|
@@ -268,9 +267,8 @@ def auto_balancer(x_train, y_train, dtype=np.float32):
|
|
268
267
|
|
269
268
|
print(Fore.GREEN + "Data Succesfully Balanced from: " + str(len(x_train)
|
270
269
|
) + " to: " + str(len(BalancedInputs)) + ". from: auto_balancer " + Style.RESET_ALL)
|
271
|
-
except:
|
272
|
-
|
273
|
-
sys.exit()
|
270
|
+
except Exception as e:
|
271
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
|
274
272
|
|
275
273
|
BalancedInputs = BalancedInputs.astype(dtype, copy=False)
|
276
274
|
BalancedLabels = BalancedLabels.astype(dtype=y_train.dtype, copy=False)
|
pyerualjetwork/cpu/model_ops.py
CHANGED
@@ -47,7 +47,6 @@ PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welco
|
|
47
47
|
|
48
48
|
import numpy as np
|
49
49
|
from colorama import Fore, Style
|
50
|
-
import sys
|
51
50
|
from datetime import datetime
|
52
51
|
import pickle
|
53
52
|
from scipy import io
|
@@ -128,13 +127,11 @@ def save_model(model_name,
|
|
128
127
|
test_acc= float(test_acc)
|
129
128
|
|
130
129
|
if weights_type != 'txt' and weights_type != 'npy' and weights_type != 'mat' and weights_type != 'pkl':
|
131
|
-
|
132
|
-
sys.exit()
|
130
|
+
raise ValueError(Fore.RED + "ERROR: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' or 'pkl' from: save_model" + Style.RESET_ALL)
|
133
131
|
|
134
132
|
if weights_format != 'd' and weights_format != 'f' and weights_format != 'raw':
|
135
|
-
|
136
|
-
|
137
|
-
|
133
|
+
raise ValueError(Fore.RED + "ERROR: Weight Format Type must be 'd' or 'f' or 'raw' from: save_model" + Style.RESET_ALL)
|
134
|
+
|
138
135
|
NeuronCount = []
|
139
136
|
SynapseCount = []
|
140
137
|
|
@@ -145,10 +142,14 @@ def save_model(model_name,
|
|
145
142
|
NeuronCount.append(np.shape(W)[1])
|
146
143
|
NeuronCount.append(np.shape(W)[0])
|
147
144
|
SynapseCount.append(np.shape(W)[0] * np.shape(W)[1])
|
148
|
-
except:
|
149
|
-
|
150
|
-
|
151
|
-
|
145
|
+
except AttributeError as e:
|
146
|
+
raise AttributeError(Fore.RED + "ERROR: W does not have a shape attribute. Check if W is a valid matrix." + Style.RESET_ALL) from e
|
147
|
+
except IndexError as e:
|
148
|
+
raise IndexError(Fore.RED + "ERROR: W has an unexpected shape format. Ensure it has two dimensions." + Style.RESET_ALL) from e
|
149
|
+
except (TypeError, ValueError) as e:
|
150
|
+
raise TypeError(Fore.RED + "ERROR: W is not a valid numeric matrix." + Style.RESET_ALL) from e
|
151
|
+
except Exception as e:
|
152
|
+
raise RuntimeError(Fore.RED + f"ERROR: An unexpected error occurred in save_model: {e}" + Style.RESET_ALL) from e
|
152
153
|
|
153
154
|
elif model_type == 'MLP' or model_type == 'PTNN':
|
154
155
|
|
@@ -160,10 +161,14 @@ def save_model(model_name,
|
|
160
161
|
try:
|
161
162
|
NeuronCount.append(np.shape(W[i])[0])
|
162
163
|
SynapseCount.append(np.shape(W[i])[0] * np.shape(W[i])[1])
|
163
|
-
except:
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
except AttributeError as e:
|
165
|
+
raise AttributeError(Fore.RED + "ERROR: W does not have a shape attribute. Check if W is a valid matrix." + Style.RESET_ALL) from e
|
166
|
+
except IndexError as e:
|
167
|
+
raise IndexError(Fore.RED + "ERROR: W has an unexpected shape format. Ensure it has two dimensions." + Style.RESET_ALL) from e
|
168
|
+
except (TypeError, ValueError) as e:
|
169
|
+
raise TypeError(Fore.RED + "ERROR: W is not a valid numeric matrix." + Style.RESET_ALL) from e
|
170
|
+
except Exception as e:
|
171
|
+
raise RuntimeError(Fore.RED + f"ERROR: An unexpected error occurred in save_model: {e}" + Style.RESET_ALL) from e
|
167
172
|
|
168
173
|
|
169
174
|
SynapseCount.append(' ')
|
@@ -267,10 +272,9 @@ def save_model(model_name,
|
|
267
272
|
w = {'w': W}
|
268
273
|
io.savemat(model_path + model_name + f'_weights.mat', w)
|
269
274
|
|
270
|
-
except:
|
271
275
|
|
272
|
-
|
273
|
-
|
276
|
+
except OSError as e:
|
277
|
+
raise OSError(Fore.RED + f"ERROR: An OSError error occurred in save_model at saving weights. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
|
274
278
|
|
275
279
|
if show_info:
|
276
280
|
print(df)
|
@@ -309,11 +313,9 @@ def load_model(model_name,
|
|
309
313
|
|
310
314
|
df = pd.read_pickle(model_path + model_name + '.pkl')
|
311
315
|
|
312
|
-
except:
|
313
|
-
|
314
|
-
print(Fore.RED + "ERROR: Model Path or Model Name error. acceptable form: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: load_model" + Style.RESET_ALL)
|
316
|
+
except OSError as e:
|
317
|
+
raise OSError(Fore.RED + f"ERROR: An OSError error occurred in load_model at loading model params. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
|
315
318
|
|
316
|
-
sys.exit()
|
317
319
|
|
318
320
|
|
319
321
|
scaler_params = df['STANDARD SCALER'].tolist()
|
@@ -357,20 +359,25 @@ def load_model(model_name,
|
|
357
359
|
if model_type == 'MLP' or model_type == 'PTNN': allow_pickle = True
|
358
360
|
else: allow_pickle = False
|
359
361
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
362
|
+
try:
|
363
|
+
if WeightType == 'txt':
|
364
|
+
W = (np.loadtxt(model_path + model_name + f'_weights.txt'))
|
365
|
+
elif WeightType == 'npy':
|
366
|
+
W = (np.load(model_path + model_name + f'_weights.npy', allow_pickle=allow_pickle))
|
367
|
+
elif WeightType == 'mat':
|
368
|
+
W = (sio.loadmat(model_path + model_name + f'_weights.mat'))
|
369
|
+
elif WeightType == 'pkl':
|
370
|
+
with open(model_path + model_name + f'_weights.pkl', 'rb') as f:
|
371
|
+
W = pickle.load(f)
|
372
|
+
else:
|
373
|
+
|
374
|
+
raise ValueError(
|
375
|
+
Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
|
376
|
+
|
377
|
+
except OSError as e:
|
378
|
+
raise OSError(Fore.RED + f"ERROR: An OSError error occurred in load_model at loading weights. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
|
379
|
+
|
370
380
|
|
371
|
-
raise ValueError(
|
372
|
-
Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
|
373
|
-
|
374
381
|
if WeightType == 'mat':
|
375
382
|
W = W['w']
|
376
383
|
|
@@ -448,9 +455,8 @@ def predict_from_storage(Input, model_name, model_path=''):
|
|
448
455
|
|
449
456
|
return result
|
450
457
|
|
451
|
-
except:
|
452
|
-
|
453
|
-
sys.exit()
|
458
|
+
except Exception as e:
|
459
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred in predict_from_storage {e}" + Style.RESET_ALL) from e
|
454
460
|
|
455
461
|
|
456
462
|
def reverse_predict_from_storage(output, model_name, model_path=''):
|
@@ -476,9 +482,8 @@ def reverse_predict_from_storage(output, model_name, model_path=''):
|
|
476
482
|
try:
|
477
483
|
Input = W.T @ output
|
478
484
|
return Input
|
479
|
-
except:
|
480
|
-
|
481
|
-
sys.exit()
|
485
|
+
except Exception as e:
|
486
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
|
482
487
|
|
483
488
|
|
484
489
|
|
@@ -552,9 +557,8 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], ac
|
|
552
557
|
|
553
558
|
return result
|
554
559
|
|
555
|
-
except:
|
556
|
-
|
557
|
-
sys.exit()
|
560
|
+
except Exception as e:
|
561
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred in predict_from_memory {e}" + Style.RESET_ALL) from e
|
558
562
|
|
559
563
|
def reverse_predict_from_memory(output, W):
|
560
564
|
|
@@ -575,9 +579,8 @@ def reverse_predict_from_memory(output, W):
|
|
575
579
|
Input = W.T @ output
|
576
580
|
return Input
|
577
581
|
|
578
|
-
except:
|
579
|
-
|
580
|
-
sys.exit()
|
582
|
+
except Exception as e:
|
583
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
|
581
584
|
|
582
585
|
|
583
586
|
def get_weights():
|
pyerualjetwork/cuda/model_ops.py
CHANGED
@@ -49,7 +49,6 @@ PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welco
|
|
49
49
|
import cupy as cp
|
50
50
|
import numpy as np
|
51
51
|
from colorama import Fore, Style
|
52
|
-
import sys
|
53
52
|
from datetime import datetime
|
54
53
|
import pickle
|
55
54
|
from scipy import io
|
@@ -139,27 +138,31 @@ def save_model(model_name,
|
|
139
138
|
test_acc= float(test_acc)
|
140
139
|
|
141
140
|
if weights_type != 'txt' and weights_type != 'npy' and weights_type != 'mat' and weights_type != 'pkl':
|
142
|
-
|
143
|
-
sys.exit()
|
141
|
+
raise ValueError(Fore.RED + "ERROR: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' or 'pkl' from: save_model" + Style.RESET_ALL)
|
144
142
|
|
145
143
|
if weights_format != 'd' and weights_format != 'f' and weights_format != 'raw':
|
146
|
-
|
147
|
-
sys.exit()
|
144
|
+
raise ValueError(Fore.RED + "ERROR: Weight Format Type must be 'd' or 'f' or 'raw' from: save_model" + Style.RESET_ALL)
|
148
145
|
|
149
146
|
NeuronCount = []
|
150
147
|
SynapseCount = []
|
151
148
|
|
152
149
|
if model_type == 'PLAN':
|
153
150
|
class_count = W.shape[0]
|
154
|
-
|
151
|
+
|
155
152
|
try:
|
156
153
|
NeuronCount.append(cp.shape(W)[1])
|
157
154
|
NeuronCount.append(cp.shape(W)[0])
|
158
155
|
SynapseCount.append(cp.shape(W)[0] * cp.shape(W)[1])
|
159
|
-
|
156
|
+
|
157
|
+
except AttributeError as e:
|
158
|
+
raise AttributeError(Fore.RED + "ERROR: W does not have a shape attribute. Check if W is a valid matrix." + Style.RESET_ALL) from e
|
159
|
+
except IndexError as e:
|
160
|
+
raise IndexError(Fore.RED + "ERROR: W has an unexpected shape format. Ensure it has two dimensions." + Style.RESET_ALL) from e
|
161
|
+
except (TypeError, ValueError) as e:
|
162
|
+
raise TypeError(Fore.RED + "ERROR: W is not a valid numeric matrix." + Style.RESET_ALL) from e
|
163
|
+
except Exception as e:
|
164
|
+
raise RuntimeError(Fore.RED + f"ERROR: An unexpected error occurred in save_model: {e}" + Style.RESET_ALL) from e
|
160
165
|
|
161
|
-
print(Fore.RED + "ERROR: Weight matrices have a problem from: save_model" + Style.RESET_ALL)
|
162
|
-
sys.exit()
|
163
166
|
|
164
167
|
elif model_type == 'MLP' or model_type == 'PTNN':
|
165
168
|
|
@@ -176,10 +179,15 @@ def save_model(model_name,
|
|
176
179
|
try:
|
177
180
|
NeuronCount.append(cp.shape(W[i])[0])
|
178
181
|
SynapseCount.append(cp.shape(W[i])[0] * cp.shape(W[i])[1])
|
179
|
-
except:
|
180
182
|
|
181
|
-
|
182
|
-
|
183
|
+
except AttributeError as e:
|
184
|
+
raise AttributeError(Fore.RED + "ERROR: W does not have a shape attribute. Check if W is a valid matrix." + Style.RESET_ALL) from e
|
185
|
+
except IndexError as e:
|
186
|
+
raise IndexError(Fore.RED + "ERROR: W has an unexpected shape format. Ensure it has two dimensions." + Style.RESET_ALL) from e
|
187
|
+
except (TypeError, ValueError) as e:
|
188
|
+
raise TypeError(Fore.RED + "ERROR: W is not a valid numeric matrix." + Style.RESET_ALL) from e
|
189
|
+
except Exception as e:
|
190
|
+
raise RuntimeError(Fore.RED + f"ERROR: An unexpected error occurred in save_model: {e}" + Style.RESET_ALL) from e
|
183
191
|
|
184
192
|
SynapseCount.append(' ')
|
185
193
|
|
@@ -241,50 +249,53 @@ def save_model(model_name,
|
|
241
249
|
df = pd.DataFrame(data)
|
242
250
|
df.to_pickle(model_path + model_name + '.pkl')
|
243
251
|
|
252
|
+
try:
|
244
253
|
|
245
|
-
|
246
|
-
|
247
|
-
cp.savetxt(model_path + model_name + f'_weights.txt', W, fmt='%f')
|
254
|
+
if weights_type == 'txt' and weights_format == 'f':
|
248
255
|
|
249
|
-
|
256
|
+
cp.savetxt(model_path + model_name + f'_weights.txt', W, fmt='%f')
|
250
257
|
|
251
|
-
|
258
|
+
if weights_type == 'txt' and weights_format == 'raw':
|
252
259
|
|
253
|
-
|
260
|
+
cp.savetxt(model_path + model_name + f'_weights.txt', W)
|
254
261
|
|
255
|
-
|
256
|
-
if weights_type == 'pkl' and weights_format == 'f':
|
262
|
+
###
|
257
263
|
|
258
|
-
|
259
|
-
|
264
|
+
|
265
|
+
if weights_type == 'pkl' and weights_format == 'f':
|
260
266
|
|
261
|
-
|
262
|
-
|
263
|
-
with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
|
264
|
-
pickle.dump(W, f)
|
267
|
+
with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
|
268
|
+
pickle.dump(W.astype(float), f)
|
265
269
|
|
266
|
-
|
270
|
+
if weights_type == 'pkl' and weights_format =='raw':
|
271
|
+
|
272
|
+
with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
|
273
|
+
pickle.dump(W, f)
|
267
274
|
|
268
|
-
|
275
|
+
###
|
269
276
|
|
270
|
-
|
277
|
+
if weights_type == 'npy' and weights_format == 'f':
|
271
278
|
|
272
|
-
|
279
|
+
cp.save(model_path + model_name + f'_weights.npy', W, W.astype(float))
|
273
280
|
|
274
|
-
|
281
|
+
if weights_type == 'npy' and weights_format == 'raw':
|
275
282
|
|
276
|
-
|
283
|
+
cp.save(model_path + model_name + f'_weights.npy', W)
|
277
284
|
|
278
|
-
|
285
|
+
###
|
279
286
|
|
280
|
-
|
281
|
-
io.savemat(model_path + model_name + f'_weights.mat', w)
|
287
|
+
if weights_type == 'mat' and weights_format == 'f':
|
282
288
|
|
283
|
-
|
284
|
-
|
285
|
-
w = {'w': W}
|
286
|
-
io.savemat(model_path + model_name + f'_weights.mat', w)
|
289
|
+
w = {'w': W.astype(float)}
|
290
|
+
io.savemat(model_path + model_name + f'_weights.mat', w)
|
287
291
|
|
292
|
+
if weights_type == 'mat' and weights_format == 'raw':
|
293
|
+
|
294
|
+
w = {'w': W}
|
295
|
+
io.savemat(model_path + model_name + f'_weights.mat', w)
|
296
|
+
|
297
|
+
except OSError as e:
|
298
|
+
raise OSError(Fore.RED + f"ERROR: An OSError error occurred in save_model at saving weights. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
|
288
299
|
|
289
300
|
if show_info:
|
290
301
|
print(df)
|
@@ -322,11 +333,8 @@ def load_model(model_name,
|
|
322
333
|
|
323
334
|
df = pd.read_pickle(model_path + model_name + '.pkl')
|
324
335
|
|
325
|
-
except:
|
326
|
-
|
327
|
-
print(Fore.RED + "ERROR: Model Path or Model Name error. acceptable form: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: load_model" + Style.RESET_ALL)
|
328
|
-
|
329
|
-
sys.exit()
|
336
|
+
except OSError as e:
|
337
|
+
raise OSError(Fore.RED + f"ERROR: An OSError error occurred in load_model at loading model params. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
|
330
338
|
|
331
339
|
|
332
340
|
scaler_params_cpu = df['STANDARD SCALER'].tolist()
|
@@ -356,7 +364,6 @@ def load_model(model_name,
|
|
356
364
|
activation_potentiation = [x for x in activation_potentiation if not (isinstance(x, float) and np.isnan(x))]
|
357
365
|
activation_potentiation = [item for item in activation_potentiation if item != '']
|
358
366
|
|
359
|
-
|
360
367
|
device_version = __version__
|
361
368
|
|
362
369
|
try:
|
@@ -374,24 +381,28 @@ def load_model(model_name,
|
|
374
381
|
if model_type == 'MLP' or model_type == 'PTNN': allow_pickle = True
|
375
382
|
else: allow_pickle = False
|
376
383
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
384
|
+
try:
|
385
|
+
if WeightType == 'txt':
|
386
|
+
W = (np.loadtxt(model_path + model_name + f'_weights.txt'))
|
387
|
+
elif WeightType == 'npy':
|
388
|
+
W = (np.load(model_path + model_name + f'_weights.npy', allow_pickle=allow_pickle))
|
389
|
+
elif WeightType == 'mat':
|
390
|
+
W = (sio.loadmat(model_path + model_name + f'_weights.mat'))
|
391
|
+
elif WeightType == 'pkl':
|
392
|
+
with open(model_path + model_name + f'_weights.pkl', 'rb') as f:
|
393
|
+
W = pickle.load(f)
|
394
|
+
else:
|
395
|
+
raise ValueError(
|
389
396
|
Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
|
397
|
+
|
398
|
+
except OSError as e:
|
399
|
+
raise OSError(Fore.RED + f"ERROR: An OSError error occurred in load_model at loading weights. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
|
400
|
+
|
390
401
|
|
391
402
|
if WeightType == 'mat':
|
392
403
|
W = W['w']
|
393
404
|
|
394
|
-
if model_type == 'MLP':
|
405
|
+
if model_type == 'MLP' or model_type == 'PTNN':
|
395
406
|
W = W.tolist()
|
396
407
|
W = [cp.array(item) for item in W]
|
397
408
|
|
@@ -472,9 +483,8 @@ def predict_from_storage(Input, model_name, model_path='', dtype=cp.float32):
|
|
472
483
|
|
473
484
|
return result
|
474
485
|
|
475
|
-
except:
|
476
|
-
|
477
|
-
sys.exit(),
|
486
|
+
except Exception as e:
|
487
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred in predict_from_storage {e}" + Style.RESET_ALL) from e
|
478
488
|
|
479
489
|
|
480
490
|
|
@@ -505,9 +515,8 @@ def reverse_predict_from_storage(output, model_name, model_path='', dtype=cp.flo
|
|
505
515
|
try:
|
506
516
|
Input = W.T @ output
|
507
517
|
return Input
|
508
|
-
except:
|
509
|
-
|
510
|
-
sys.exit()
|
518
|
+
except Exception as e:
|
519
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
|
511
520
|
|
512
521
|
|
513
522
|
def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], activation_potentiation=None, model_type='PLAN'):
|
@@ -536,45 +545,52 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], ac
|
|
536
545
|
from .data_ops import standard_scaler
|
537
546
|
from .activation_functions import apply_activation
|
538
547
|
|
539
|
-
if
|
540
|
-
activations = [activations]
|
541
|
-
elif isinstance(activations, list):
|
542
|
-
activations = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activations]
|
548
|
+
if model_type != 'PLAN' and model_type != 'MLP' and model_type != 'PTNN': raise ValueError("model_type parameter must be 'PLAN', 'MLP' or 'PTNN'.")
|
543
549
|
|
544
|
-
|
550
|
+
try:
|
545
551
|
|
546
|
-
|
547
|
-
layer = Input
|
548
|
-
for i in range(len(W)):
|
549
|
-
if i != len(W) - 1 and i != 0: layer = apply_activation(layer, activations[i])
|
552
|
+
Input = standard_scaler(None, Input, scaler_params)
|
550
553
|
|
551
|
-
|
554
|
+
if isinstance(activations, str):
|
555
|
+
activations = [activations]
|
556
|
+
elif isinstance(activations, list):
|
557
|
+
activations = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activations]
|
552
558
|
|
553
|
-
|
559
|
+
if model_type == 'MLP':
|
560
|
+
layer = Input
|
561
|
+
for i in range(len(W)):
|
562
|
+
if i != len(W) - 1 and i != 0: layer = apply_activation(layer, activations[i])
|
554
563
|
|
555
|
-
|
564
|
+
layer = layer @ W[i].T
|
556
565
|
|
557
|
-
|
558
|
-
result = Input @ W.T
|
559
|
-
|
560
|
-
if model_type == 'PTNN':
|
566
|
+
result = layer
|
561
567
|
|
562
|
-
if
|
563
|
-
activation_potentiation = [activation_potentiation]
|
564
|
-
elif isinstance(activation_potentiation, list):
|
565
|
-
activation_potentiation = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activation_potentiation]
|
568
|
+
if model_type == 'PLAN':
|
566
569
|
|
567
|
-
|
568
|
-
|
570
|
+
Input = apply_activation(Input, activations)
|
571
|
+
result = Input @ W.T
|
572
|
+
|
573
|
+
if model_type == 'PTNN':
|
569
574
|
|
570
|
-
|
571
|
-
|
575
|
+
if isinstance(activation_potentiation, str):
|
576
|
+
activation_potentiation = [activation_potentiation]
|
577
|
+
elif isinstance(activation_potentiation, list):
|
578
|
+
activation_potentiation = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activation_potentiation]
|
572
579
|
|
573
|
-
|
580
|
+
Input = apply_activation(Input, activation_potentiation)
|
581
|
+
layer = Input @ W[0].T
|
574
582
|
|
575
|
-
|
583
|
+
for i in range(1, len(W)):
|
584
|
+
if i != len(W) - 1: layer = apply_activation(layer, activations[i])
|
576
585
|
|
577
|
-
|
586
|
+
layer = layer @ W[i].T
|
587
|
+
|
588
|
+
result = layer
|
589
|
+
|
590
|
+
return result
|
591
|
+
|
592
|
+
except Exception as e:
|
593
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred in predict_from_memory {e}" + Style.RESET_ALL) from e
|
578
594
|
|
579
595
|
|
580
596
|
|
@@ -601,9 +617,8 @@ def reverse_predict_from_memory(output, W, dtype=cp.float32):
|
|
601
617
|
Input = W.T @ output
|
602
618
|
return Input
|
603
619
|
|
604
|
-
except:
|
605
|
-
|
606
|
-
sys.exit()
|
620
|
+
except Exception as e:
|
621
|
+
raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
|
607
622
|
|
608
623
|
|
609
624
|
def get_weights():
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pyerualjetwork
|
3
|
-
Version: 5.
|
3
|
+
Version: 5.36
|
4
4
|
Summary: PyereualJetwork is a GPU-accelerated machine learning library in Python for professionals and researchers. It features PLAN, MLP, Deep Learning training, and ENE (Eugenic NeuroEvolution) for genetic optimization, applicable to genetic algorithms or Reinforcement Learning (RL). The library includes data pre-processing, visualizations, model saving/loading, prediction, evaluation, training, and detailed or simplified memory management.
|
5
5
|
Author: Hasan Can Beydili
|
6
6
|
Author-email: tchasancan@gmail.com
|
@@ -1,4 +1,4 @@
|
|
1
|
-
pyerualjetwork/__init__.py,sha256=
|
1
|
+
pyerualjetwork/__init__.py,sha256=tChKNLQYWO_Y9Rg8bAQILFpJolJbGuceL3F6TrZF78A,2704
|
2
2
|
pyerualjetwork/fitness_functions.py,sha256=D9JVCr9DFid_xXgBD4uCKxdW2k10MVDE5HZRSOK4Igg,1237
|
3
3
|
pyerualjetwork/help.py,sha256=Nyi0gHAN9ZnO4wgQLeENt0n7tSCZ3hJmjaJ853eGjCE,831
|
4
4
|
pyerualjetwork/issue_solver.py,sha256=3pZTGotS29sy3pIuGQoJFUePibtSzS-tNoU80T_Usgk,3131
|
@@ -6,11 +6,11 @@ pyerualjetwork/memory_ops.py,sha256=TUFh9SYWCKL6N-vNdWId_EwU313TuZomQCHOrltrD-4,
|
|
6
6
|
pyerualjetwork/ui.py,sha256=JBTFYz5R24XwNKhA3GSW-oYAoiIBxAE3kFGXkvm5gqw,656
|
7
7
|
pyerualjetwork/cpu/__init__.py,sha256=0yAYner_-v7SmT3P7JV2itU8xJUQdQpb40dhAMQiZkc,829
|
8
8
|
pyerualjetwork/cpu/activation_functions.py,sha256=zZSoOQ452Ykp_RsHVxklxesJmmFgufyIB4F3WQjudEQ,6689
|
9
|
-
pyerualjetwork/cpu/data_ops.py,sha256=
|
9
|
+
pyerualjetwork/cpu/data_ops.py,sha256=SPsIcjU0JPHfsnEmGjD8q-yTlpgYk-KPOPJ44dfp-nU,16143
|
10
10
|
pyerualjetwork/cpu/ene.py,sha256=7ZPR7NDhuXCFSucH0l-_vUTDILnQOH-Zxv83Yy5gLL8,44451
|
11
11
|
pyerualjetwork/cpu/loss_functions.py,sha256=6PyBI232SQRGuFnG3LDGvnv_PUdWzT2_2mUODJiejGI,618
|
12
12
|
pyerualjetwork/cpu/metrics.py,sha256=WhZ8iEqWehaygPRADUlhA5j_Qv3UwqV_eMxpyRVkeVs,6070
|
13
|
-
pyerualjetwork/cpu/model_ops.py,sha256=
|
13
|
+
pyerualjetwork/cpu/model_ops.py,sha256=1KNgjUeYCO_TsA5RtbNiuIiBJzq8-rL2dE6jxKqCBU0,21481
|
14
14
|
pyerualjetwork/cpu/nn.py,sha256=AiL1q-pWr-tzTtQlzoKRnqHQVEvgrUPLUl6_RY02T5s,32032
|
15
15
|
pyerualjetwork/cpu/visualizations.py,sha256=rOQsc-W8b71z7ovXSoF49lx4fmpvlaHLsyj9ejWnhnI,28164
|
16
16
|
pyerualjetwork/cuda/__init__.py,sha256=NbqvAS4jlMdoFdXa5_hi5ukXQ5zAZR_5BQ4QAqtiKug,879
|
@@ -19,10 +19,10 @@ pyerualjetwork/cuda/data_ops.py,sha256=SiNodFNmWyTPY_KnKuAi9biPRdpTAYY3XM01bRSUP
|
|
19
19
|
pyerualjetwork/cuda/ene.py,sha256=dwH5l7CQqj4kUbcj8vC9gIgEdjFfRN-jw-06ABN-TiU,44976
|
20
20
|
pyerualjetwork/cuda/loss_functions.py,sha256=C93IZJcrOpT6HMK9x1O4AHJWXYTkN5WZiqdssPbvAPk,617
|
21
21
|
pyerualjetwork/cuda/metrics.py,sha256=PjDBoRvr6va8vRvDIJJGBO4-I4uumrk3NCM1Vz4NJTo,5054
|
22
|
-
pyerualjetwork/cuda/model_ops.py,sha256=
|
22
|
+
pyerualjetwork/cuda/model_ops.py,sha256=cij0UKy4G0Zg5Z_VFCIdBEjWUOBQcsgEsGDCQSuuJ_U,23021
|
23
23
|
pyerualjetwork/cuda/nn.py,sha256=EDdiWNUdrEHZXQ9K7qM74Q7OpacAgWM5MsQC8YANlY4,33164
|
24
24
|
pyerualjetwork/cuda/visualizations.py,sha256=9l5BhXqXoeopdhLvVGvjH1TKYZb9JdKOsSE2IYD02zs,28569
|
25
|
-
pyerualjetwork-5.
|
26
|
-
pyerualjetwork-5.
|
27
|
-
pyerualjetwork-5.
|
28
|
-
pyerualjetwork-5.
|
25
|
+
pyerualjetwork-5.36.dist-info/METADATA,sha256=1jv9MpaFV0bt2FrrC2Ln8kS0OAkt_O8laYyYmkyIrTo,8020
|
26
|
+
pyerualjetwork-5.36.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
27
|
+
pyerualjetwork-5.36.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
|
28
|
+
pyerualjetwork-5.36.dist-info/RECORD,,
|
File without changes
|
File without changes
|