pyerualjetwork 1.3.5__py3-none-any.whl → 1.3.7__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 +60 -37
- pyerualjetwork-1.3.7.dist-info/METADATA +8 -0
- pyerualjetwork-1.3.7.dist-info/RECORD +6 -0
- pyerualjetwork-1.3.5.dist-info/METADATA +0 -8
- pyerualjetwork-1.3.5.dist-info/RECORD +0 -6
- {pyerualjetwork-1.3.5.dist-info → pyerualjetwork-1.3.7.dist-info}/WHEEL +0 -0
- {pyerualjetwork-1.3.5.dist-info → pyerualjetwork-1.3.7.dist-info}/top_level.txt +0 -0
plan/plan.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
"""
|
3
|
-
Created on Thu May 30
|
2
|
+
Created on Thu May 30 22:12:49 2024
|
4
3
|
|
5
|
-
@author: hasan
|
4
|
+
@author: hasan can beydili
|
6
5
|
"""
|
7
|
-
|
8
6
|
import numpy as np
|
9
7
|
import time
|
10
8
|
from colorama import Fore,Style
|
@@ -19,13 +17,13 @@ def TrainPLAN(
|
|
19
17
|
x_train: List[Union[int, float]],
|
20
18
|
y_train: List[Union[int, float, str]], # At least two.. and one hot encoded
|
21
19
|
class_count: int,
|
22
|
-
layers
|
23
|
-
neurons
|
24
|
-
membran_thresholds
|
25
|
-
membran_potentials
|
26
|
-
normalizations
|
27
|
-
activations
|
28
|
-
visualize
|
20
|
+
layers: List[str],
|
21
|
+
neurons: List[Union[int, float]],
|
22
|
+
membran_thresholds: List[str],
|
23
|
+
membran_potentials: List[Union[int, float]],
|
24
|
+
normalizations: List[str],
|
25
|
+
activations: List[str],
|
26
|
+
visualize: str
|
29
27
|
) -> str:
|
30
28
|
|
31
29
|
infoPLAN = """
|
@@ -155,7 +153,7 @@ def TrainPLAN(
|
|
155
153
|
x_train_size = len(x_train[0])
|
156
154
|
|
157
155
|
W = WeightIdentification(len(layers) - 1,class_count,neurons,x_train_size)
|
158
|
-
Divides = SynapticDividing(class_count,W)
|
156
|
+
Divides, Piece = SynapticDividing(class_count,W)
|
159
157
|
trained_W = [1] * len(W)
|
160
158
|
print(Fore.GREEN + "Train Started with 0 ERROR" + Style.RESET_ALL,)
|
161
159
|
train_predictions = [None] * len(y_train)
|
@@ -178,9 +176,11 @@ def TrainPLAN(
|
|
178
176
|
for i, ul in enumerate(Ul):
|
179
177
|
if ul == 1.0:
|
180
178
|
k = i
|
179
|
+
|
181
180
|
cs = Divides[int(k)][Windex][0]
|
181
|
+
|
182
182
|
|
183
|
-
W[Windex] = SynapticPruning(w, cs, 'row', int(k),class_count)
|
183
|
+
W[Windex] = SynapticPruning(w, cs, 'row', int(k),class_count,Piece[Windex],1)
|
184
184
|
|
185
185
|
neural_layer = inp
|
186
186
|
|
@@ -197,9 +197,9 @@ def TrainPLAN(
|
|
197
197
|
neural_layer = Softmax(neural_layer)
|
198
198
|
|
199
199
|
if Layer == 'fex':
|
200
|
-
neural_layer,W[Lindex] = Fex(neural_layer, W[Lindex], membran_thresholds[Lindex], membran_potentials[Lindex])
|
200
|
+
neural_layer,W[Lindex] = Fex(neural_layer, W[Lindex], membran_thresholds[Lindex], membran_potentials[Lindex], Piece[Windex],1)
|
201
201
|
elif Layer == 'cat':
|
202
|
-
neural_layer,W[Lindex] = Cat(neural_layer, W[Lindex], membran_thresholds[Lindex], membran_potentials[Lindex],1)
|
202
|
+
neural_layer,W[Lindex] = Cat(neural_layer, W[Lindex], membran_thresholds[Lindex], membran_potentials[Lindex],1, Piece[Windex])
|
203
203
|
|
204
204
|
RealOutput = np.argmax(y_train[index])
|
205
205
|
PredictedOutput = np.argmax(neural_layer)
|
@@ -319,7 +319,9 @@ def SynapticPruning(
|
|
319
319
|
cs, # list[list[num]]: Synaptic connections between neurons.
|
320
320
|
key, # int: key for identifying synaptic connections.
|
321
321
|
Class, # int: Class label for the current training instance.
|
322
|
-
class_count
|
322
|
+
class_count, # int: Total number of classes in the dataset.
|
323
|
+
piece, # ???
|
324
|
+
is_training # int: 1 or 0
|
323
325
|
|
324
326
|
) -> str:
|
325
327
|
infoPruning = """
|
@@ -335,18 +337,31 @@ def SynapticPruning(
|
|
335
337
|
Returns:
|
336
338
|
numpy array: Weight matrix.
|
337
339
|
"""
|
338
|
-
|
340
|
+
|
339
341
|
|
340
342
|
Class += 1 # because index start 0
|
341
343
|
|
342
|
-
if
|
343
|
-
|
344
|
-
ce = cs / Class
|
344
|
+
if Class != 1:
|
345
|
+
|
345
346
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
347
|
+
|
348
|
+
ce = cs / Class
|
349
|
+
|
350
|
+
if is_training == 1:
|
351
|
+
|
352
|
+
p = piece
|
353
|
+
|
354
|
+
for i in range(Class - 3):
|
355
|
+
|
356
|
+
piece+=p
|
357
|
+
|
358
|
+
if Class!= 2:
|
359
|
+
ce += piece
|
360
|
+
|
361
|
+
w[int(ce)-1::-1,:] = 0
|
362
|
+
|
363
|
+
|
364
|
+
w[cs:,:] = 0
|
350
365
|
|
351
366
|
else:
|
352
367
|
|
@@ -401,32 +416,36 @@ def SynapticDividing(
|
|
401
416
|
# Boş bir üç boyutlu liste oluşturma
|
402
417
|
Divides = [[[0] for _ in range(len(W))] for _ in range(class_count)]
|
403
418
|
|
419
|
+
|
404
420
|
for i in range(len(W)):
|
405
421
|
|
406
422
|
|
407
423
|
Piece[i] = int(math.floor(W[i].shape[0] / class_count))
|
408
424
|
|
409
|
-
cs = 0
|
425
|
+
cs = 0
|
410
426
|
# j = Classes, i = Weights, [0] = CutStart.
|
411
427
|
|
412
428
|
for i in range(len(W)):
|
413
429
|
for j in range(class_count):
|
414
430
|
cs = cs + Piece[i]
|
415
431
|
Divides[j][i][0] = cs
|
432
|
+
#pruning_param[i] = cs
|
416
433
|
#print('Divides: ' + j + i + ' = ' + Divides[j][i][0])
|
417
434
|
#input()
|
418
|
-
|
435
|
+
|
419
436
|
j = 0
|
420
437
|
cs = 0
|
421
438
|
|
422
|
-
return Divides
|
439
|
+
return Divides, Piece
|
423
440
|
|
424
441
|
|
425
442
|
def Fex(
|
426
443
|
Input, # list[num]: Input data.
|
427
444
|
w, # list[list[num]]: Weight matrix of the neural network.
|
428
445
|
membran_threshold, # str: Sign for threshold comparison ('<', '>', '==', '!=').
|
429
|
-
membran_potential
|
446
|
+
membran_potential, # num: Threshold value for comparison.
|
447
|
+
piece, # ???
|
448
|
+
is_training # num: 1 or 0
|
430
449
|
) -> tuple:
|
431
450
|
"""
|
432
451
|
Applies feature extraction process to the input data using synaptic pruning.
|
@@ -450,7 +469,7 @@ def Fex(
|
|
450
469
|
elif membran_threshold == '!=':
|
451
470
|
PruneIndex = np.where(Input != membran_potential)
|
452
471
|
|
453
|
-
w = SynapticPruning(w, PruneIndex, 'col', 0, 0)
|
472
|
+
w = SynapticPruning(w, PruneIndex, 'col', 0, 0, piece, is_training)
|
454
473
|
|
455
474
|
neural_layer = np.dot(w, Input)
|
456
475
|
return neural_layer,w
|
@@ -460,7 +479,8 @@ def Cat(
|
|
460
479
|
w, # list[list[num]]: Weight matrix of the neural network.
|
461
480
|
membran_threshold, # str: Sign for threshold comparison ('<', '>', '==', '!=').
|
462
481
|
membran_potential, # num: Threshold value for comparison.
|
463
|
-
isTrain
|
482
|
+
isTrain,
|
483
|
+
piece # int: Flag indicating if the function is called during training (1 for training, 0 otherwise).
|
464
484
|
) -> tuple:
|
465
485
|
"""
|
466
486
|
Applies categorization process to the input data using synaptic pruning if specified.
|
@@ -486,7 +506,7 @@ def Cat(
|
|
486
506
|
PruneIndex = np.where(Input != membran_potential)
|
487
507
|
if isTrain == 1 and membran_threshold != 'none':
|
488
508
|
|
489
|
-
w = SynapticPruning(w, PruneIndex, 'col', 0, 0)
|
509
|
+
w = SynapticPruning(w, PruneIndex, 'col', 0, 0, piece, isTrain)
|
490
510
|
|
491
511
|
|
492
512
|
neural_layer = np.dot(w, Input)
|
@@ -564,6 +584,8 @@ def Relu(
|
|
564
584
|
return np.maximum(0, x)
|
565
585
|
|
566
586
|
|
587
|
+
|
588
|
+
|
567
589
|
def TestPLAN(
|
568
590
|
x_test, # list[list[num]]: Test input data.
|
569
591
|
y_test, # list[num]: Test labels.
|
@@ -620,9 +642,9 @@ def TestPLAN(
|
|
620
642
|
neural_layer = Softmax(neural_layer)
|
621
643
|
|
622
644
|
if layers[index] == 'fex':
|
623
|
-
neural_layer,useless = Fex(neural_layer, W[index], membran_thresholds[index], membran_potentials[index])
|
645
|
+
neural_layer,useless = Fex(neural_layer, W[index], membran_thresholds[index], membran_potentials[index],0,0)
|
624
646
|
if layers[index] == 'cat':
|
625
|
-
neural_layer,useless = Cat(neural_layer, W[index], membran_thresholds[index], membran_potentials[index],0)
|
647
|
+
neural_layer,useless = Cat(neural_layer, W[index], membran_thresholds[index], membran_potentials[index],0,0)
|
626
648
|
for i, w in enumerate(Wc):
|
627
649
|
W[i] = np.copy(w)
|
628
650
|
RealOutput = np.argmax(y_test[inpIndex])
|
@@ -979,12 +1001,12 @@ def PredictFromDiscPLAN(Input,model_name,model_path,log_type):
|
|
979
1001
|
if layers[index] == 'fex':
|
980
1002
|
neural_layer,useless = Fex(neural_layer, W[index],
|
981
1003
|
membran_thresholds[index],
|
982
|
-
membran_potentials[index])
|
1004
|
+
membran_potentials[index],0,0)
|
983
1005
|
if layers[index] == 'cat':
|
984
1006
|
neural_layer,useless = Cat(neural_layer, W[index],
|
985
1007
|
membran_thresholds[index],
|
986
1008
|
membran_potentials[index],
|
987
|
-
0)
|
1009
|
+
0,0)
|
988
1010
|
except:
|
989
1011
|
print(Fore.RED + "ERROR: The input was probably entered incorrectly. from: PredictFromDiscPLAN" + infoPredictFromDİscPLAN + Style.RESET_ALL)
|
990
1012
|
return 'e'
|
@@ -1031,11 +1053,12 @@ def PredictFromRamPLAN(Input,layers,membran_thresholds,membran_potentials,normal
|
|
1031
1053
|
if layers[index] == 'fex':
|
1032
1054
|
neural_layer,useless = Fex(neural_layer, W[index],
|
1033
1055
|
membran_thresholds[index],
|
1034
|
-
membran_potentials[index])
|
1056
|
+
membran_potentials[index],0,0)
|
1035
1057
|
if layers[index] == 'cat':
|
1036
1058
|
neural_layer,useless = Cat(neural_layer, W[index],
|
1037
1059
|
membran_thresholds[index],
|
1038
|
-
membran_potentials[index],
|
1060
|
+
membran_potentials[index],
|
1061
|
+
0,0)
|
1039
1062
|
except:
|
1040
1063
|
print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: PredictFromRamPLAN." + infoPredictFromRamPLAN + Style.RESET_ALL)
|
1041
1064
|
return 'e'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: pyerualjetwork
|
3
|
+
Version: 1.3.7
|
4
|
+
Summary: Advanced python deep learning library. MASSIVE Technic Update, unlocked class limits. (Documentation in desc. Examples in GİTHUB: https://github.com/HCB06/PyerualJetwork)
|
5
|
+
Author: Hasan Can Beydili
|
6
|
+
Author-email: tchasancan@gmail.com
|
7
|
+
Keywords: model evaluation,classifcation,pruning learning artficial neural networks
|
8
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
plan/__init__.py,sha256=LQbg-AnTUz7KA1E77-mg7X-zRM-7IiK7c3zK-j063rc,375
|
2
|
+
plan/plan.py,sha256=7E8SRs8CEz6P29SM-G1VDypebXG-5oeMI2V8h0tepyU,44862
|
3
|
+
pyerualjetwork-1.3.7.dist-info/METADATA,sha256=1Apa30bZ6idAW9qxHzSnaJAkNDJB0ADs8f3z-cfDYq0,393
|
4
|
+
pyerualjetwork-1.3.7.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
5
|
+
pyerualjetwork-1.3.7.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
|
6
|
+
pyerualjetwork-1.3.7.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: pyerualjetwork
|
3
|
-
Version: 1.3.5
|
4
|
-
Summary: Advanced python deep learning library. New Features: 'SyntheticAugmentation' function added for unbalanced datasets. Changes for variable names to snake_case (Function names are still PascalCase). (Documentation in desc. Examples in GİTHUB: https://github.com/HCB06/PyerualJetwork)
|
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=LQbg-AnTUz7KA1E77-mg7X-zRM-7IiK7c3zK-j063rc,375
|
2
|
-
plan/plan.py,sha256=GxjRfztryI-GN_1p0dIwONgwMZW40tkslVY5N6BfjBw,44286
|
3
|
-
pyerualjetwork-1.3.5.dist-info/METADATA,sha256=Go_Ix7kNK67fvUKKmWYZdnDW_qBl-wAgAcuCaCxbxTI,504
|
4
|
-
pyerualjetwork-1.3.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
5
|
-
pyerualjetwork-1.3.5.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
|
6
|
-
pyerualjetwork-1.3.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|