pyerualjetwork 1.1.2__py3-none-any.whl → 1.2.9__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/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ # pyerualjetwork/PLAN/__init__.py
2
+
3
+ # Bu dosya, plan modülünün ana giriş noktasıdır.
4
+
5
+ from .plan import AutoBalancer, Normalization, Softmax, Sigmoid, Relu, SynapticPruning, SynapticDividing, WeightIdentification, Fex, Cat, TrainPLAN, TestPLAN, SavePLAN, LoadPLAN, PredictFromDiscPLAN, PredictFromRamPLAN, GetWeights, GetDf, GetPreds, GetAcc
@@ -3,160 +3,170 @@ import time
3
3
  from colorama import Fore,Style
4
4
  from typing import List, Union
5
5
  import math
6
+ from scipy.special import expit, softmax
7
+ import matplotlib.pyplot as plt
8
+ import seaborn as sns
9
+
6
10
  # BUILD -----
7
- def TrainDPNN(
8
- Inputs: List[Union[int, float]],
9
- Labels: List[Union[int, float, str]], # At least two.. and one hot encoded
11
+ def TrainPLAN(
12
+ TrainInputs: List[Union[int, float]],
13
+ TrainLabels: List[Union[int, float, str]], # At least two.. and one hot encoded
10
14
  ClassCount: int,
11
15
  Layers: List[str],
12
16
  Neurons: List[Union[int, float]],
13
- ThresholdSigns: List[str],
14
- ThresholdValues: List[Union[int, float]],
17
+ MembranThresholds: List[str],
18
+ MembranPotentials: List[Union[int, float]],
15
19
  Normalizations: List[str],
16
- Activations: List[str]
20
+ Activations: List[str],
21
+ Visualize: str
17
22
  ) -> str:
18
23
 
19
- infoDPNN = """
20
- Creates and configures a DPNN model.
24
+ infoPLAN = """
25
+ Creates and configures a PLAN model.
21
26
 
22
27
  Args:
23
- Inputs (list[num]): List of input data.
24
- Labels (list[num]): List of labels. (one hot encoded)
28
+ TrainInputs (list[num]): List of input data.
29
+ TrainLabels (list[num]): List of TrainLabels. (one hot encoded)
25
30
  ClassCount (int): Number of classes.
26
31
  Layers (list[str]): List of layer names. (options: 'fex' (Feature Extraction), 'cat' (Catalyser))
27
32
  Neurons (list[num]): List of neuron counts for each layer.
28
- ThresholdSigns (list[str]): List of threshold signs.
29
- ThresholdValues (list[num]): List of threshold values.
33
+ MembranThresholds (list[str]): List of MembranThresholds.
34
+ MembranPotentials (list[num]): List of MembranPotentials.
30
35
  Normalizations (List[str]): Whether normalization will be performed at indexed layers ("y" or "n").
31
36
  Activations (list[str]): List of activation functions.
37
+ Visualize (str): Visualize Training procces or not visualize ('y' or 'n')
32
38
 
33
39
  Returns:
34
- list([num]): (Weight matrices list, TrainPredictions list.).
40
+ list([num]): (Weight matrices list, TrainPredictions list, TrainAcc).
35
41
  error handled ?: Process status ('e')
36
42
  """
37
43
 
44
+ if Visualize != 'y' and Visualize != 'n':
45
+ print(Fore.RED + "ERROR109: Visualize parameter must be 'y' or 'n'. TrainPLAN",infoPLAN)
46
+ return 'e'
47
+
48
+
38
49
  LastNeuron = Neurons[-1:][0]
39
50
  if LastNeuron != ClassCount:
40
- print(Fore.RED + "ERROR108: Last layer of neuron count must be equal class count. from: TrainDPNN",infoDPNN)
51
+ print(Fore.RED + "ERROR108: Last layer of neuron count must be equal class count. from: TrainPLAN",infoPLAN)
41
52
  return 'e'
42
53
 
43
- if len(Normalizations) != len(ThresholdValues):
54
+ if len(Normalizations) != len(MembranPotentials):
44
55
 
45
- print(Fore.RED + "ERROR307: Normalization list length must be equal to length of ThresholdSigns List,ThresholdValues List,Layers List,Neurons List. from: TrainDPNN",infoDPNN)
56
+ print(Fore.RED + "ERROR307: Normalization list length must be equal to length of MembranThresholds List,MembranPotentials List,Layers List,Neurons List. from: TrainPLAN",infoPLAN)
46
57
  return 'e'
47
58
 
48
- if len(Inputs) != len(Labels):
49
- print(Fore.RED + "ERROR301: Inputs list and Labels list must be same length.",infoDPNN)
59
+ if len(TrainInputs) != len(TrainLabels):
60
+ print(Fore.RED + "ERROR301: TrainInputs list and TrainLabels list must be same length.",infoPLAN)
50
61
  return 'e'
51
62
 
52
- for i, Value in enumerate(ThresholdValues):
63
+ for i, Value in enumerate(MembranPotentials):
53
64
 
54
65
  if Normalizations[i] != 'y' and Normalizations[i] != 'n':
55
- print(Fore.RED + "ERROR105: Normalization list must be 'y' or 'n'.",infoDPNN)
66
+ print(Fore.RED + "ERROR105: Normalization list must be 'y' or 'n'.",infoPLAN)
56
67
  return 'e'
57
68
 
58
- if ThresholdSigns[i] == 'none':
59
- print(Fore.MAGENTA + "WARNING102: We are advise to do not put 'none' Threshold sign. But some cases improves performance of the model from: TrainDPNN",infoDPNN + Style.RESET_ALL)
69
+ if MembranThresholds[i] == 'none':
70
+ print(Fore.MAGENTA + "WARNING102: We are advise to do not put 'none' Threshold sign. But some cases improves performance of the model from: TrainPLAN",infoPLAN + Style.RESET_ALL)
60
71
  time.sleep(3)
61
72
 
62
73
  if isinstance(Value, str):
63
- print(Fore.RED + "ERROR201: Threshold values must be numeric. from: TrainDPNN")
74
+ print(Fore.RED + "ERROR201: MEMBRAN POTENTIALS must be numeric. from: TrainPLAN")
64
75
  return 'e'
65
76
 
66
77
  if isinstance(Neurons[i], str):
67
78
  print(Fore.RED + "ERROR202: Neurons list must be numeric.")
68
79
  return 'e'
69
80
 
70
- if len(ThresholdSigns) != len(ThresholdValues):
71
- print(Fore.RED + "ERROR302: Threshold signs list and Threshold Values list must be same length. from: TrainDPNN",infoDPNN)
81
+ if len(MembranThresholds) != len(MembranPotentials):
82
+ print(Fore.RED + "ERROR302: MEMBRAN THRESHOLDS list and MEMBRAN POTENTIALS list must be same length. from: TrainPLAN",infoPLAN)
72
83
  return 'e'
73
84
 
74
85
  if len(Layers) != len(Neurons):
75
- print(Fore.RED + "ERROR303: Layers list and Neurons list must same length. from: TrainDPNN",infoDPNN)
86
+ print(Fore.RED + "ERROR303: Layers list and Neurons list must same length. from: TrainPLAN",infoPLAN)
76
87
  return 'e'
77
88
 
78
- if len(ThresholdValues) != len(Layers) or len(ThresholdSigns) != len(Layers):
79
- print(Fore.RED + "ERROR306: Threshold Values and Threshold Signs lists length must be same Layers list length. from: TrainDPNN",infoDPNN)
89
+ if len(MembranPotentials) != len(Layers) or len(MembranThresholds) != len(Layers):
90
+ print(Fore.RED + "ERROR306: MEMBRAN POTENTIALS and MEMBRAN THRESHOLDS lists length must be same Layers list length. from: TrainPLAN",infoPLAN)
80
91
  return 'e'
81
92
 
82
93
 
83
94
  for Activation in Activations:
84
95
  if Activation != 'softmax' and Activation != 'sigmoid' and Activation != 'relu' and Activation != 'none':
85
- print(Fore.RED + "ERROR108: Activations list must be 'sigmoid' or 'softmax' or 'relu' or 'none' from: TrainDPNN",infoDPNN)
96
+ print(Fore.RED + "ERROR108: Activations list must be 'sigmoid' or 'softmax' or 'relu' or 'none' from: TrainPLAN",infoPLAN)
86
97
  return 'e'
87
98
 
88
99
 
89
100
  for index, Neuron in enumerate(Neurons):
90
101
  if Neuron < 1:
91
- print(Fore.RED + "ERROR101: Neurons list must be positive non zero integer. from: TrainDPNN",infoDPNN)
102
+ print(Fore.RED + "ERROR101: Neurons list must be positive non zero integer. from: TrainPLAN",infoPLAN)
92
103
  return 'e'
93
104
 
94
105
  if index + 1 != len(Neurons) and Neuron % 2 != 0:
95
- print(Fore.MAGENTA + "WARNING101: We strongly advise to do Neuron counts be should even numbers. from: TrainDPNN",infoDPNN)
106
+ print(Fore.MAGENTA + "WARNING101: We strongly advise to do Neuron counts be should even numbers. from: TrainPLAN",infoPLAN)
96
107
  time.sleep(3)
97
108
 
98
109
  if Neuron < ClassCount:
99
- print(Fore.RED + "ERROR102: Neuron count must be greater than class count(For DPNN). from: TrainDPNN")
110
+ print(Fore.RED + "ERROR102: Neuron count must be greater than class count(For PLAN). from: TrainPLAN")
100
111
  return 'e'
101
112
 
102
113
  if Layers[index] != 'fex' and Layers[index] != 'cat':
103
- print(Fore.RED + "ERROR107: Layers list must be 'fex'(Feature Extraction Layer) or 'cat' (Catalyser Layer). from: TrainDPNN",infoDPNN)
114
+ print(Fore.RED + "ERROR107: Layers list must be 'fex'(Feature Extraction Layer) or 'cat' (Catalyser Layer). from: TrainPLAN",infoPLAN)
104
115
  return 'e'
105
116
 
106
- if len(ThresholdSigns) != len(ThresholdValues):
107
- print(Fore.RED + "ERROR305: Threshold signs list and Threshold values list must be same length. from: TrainDPNN",infoDPNN)
117
+ if len(MembranThresholds) != len(MembranPotentials):
118
+ print(Fore.RED + "ERROR305: MEMBRAN THRESHOLDS list and MEMBRAN POTENTIALS list must be same length. from: TrainPLAN",infoPLAN)
108
119
  return 'e'
109
120
 
110
121
 
111
- for i, Sign in enumerate(ThresholdSigns):
122
+ for i, Sign in enumerate(MembranThresholds):
112
123
  if Sign != '>' and Sign != '<' and Sign != '==' and Sign != '!=' and Sign != 'none':
113
- print(Fore.RED + "ERROR104: Threshold signs must be '>' or '<' or '==' or '!='. or 'none' from: TrainDPNN",infoDPNN)
124
+ print(Fore.RED + "ERROR104: MEMBRAN THRESHOLDS must be '>' or '<' or '==' or '!='. or 'none' WE SUGGEST '<' FOR FEX LAYER AND '==' FOR CAT LAYER (Your data, your hyperparameter) from: TrainPLAN",infoPLAN)
114
125
  return 'e'
115
126
 
116
127
  if Layers[i] == 'fex' and Sign == 'none':
117
- print(Fore.RED + "ERROR109: at layer type 'fex', pairing with 'none' Threshold is not acceptlable. if you want to 'none' put '==' and make threshold value '0'. from: TrainDPNN ",infoDPNN)
128
+ print(Fore.RED + "ERROR109: at layer type 'fex', pairing with 'none' Threshold is not acceptlable. if you want to 'none' put '==' and make threshold value '0'. from: TrainPLAN ",infoPLAN)
118
129
  return 'e'
119
130
 
120
- UniqueLabels = set()
121
- for sublist in Labels:
131
+ UniqueTrainLabels = set()
132
+ for sublist in TrainLabels:
122
133
 
123
- UniqueLabels.add(tuple(sublist))
134
+ UniqueTrainLabels.add(tuple(sublist))
124
135
 
125
136
 
126
- UniqueLabels = list(UniqueLabels)
137
+ UniqueTrainLabels = list(UniqueTrainLabels)
127
138
 
128
- Labels = [tuple(sublist) for sublist in Labels]
139
+ TrainLabels = [tuple(sublist) for sublist in TrainLabels]
129
140
 
130
141
 
131
- if len(UniqueLabels) != ClassCount:
132
- print(Fore.RED + "ERROR106: Label variety length must be same Class Count. from: TrainDPNN",infoDPNN)
142
+ if len(UniqueTrainLabels) != ClassCount:
143
+ print(Fore.RED + "ERROR106: Label variety length must be same Class Count. from: TrainPLAN",infoPLAN)
133
144
  return 'e'
134
145
 
135
- Inputs[0] = np.array(Inputs[0])
136
- Inputs[0] = Inputs[0].ravel()
137
- InputSize = len(Inputs[0])
146
+ TrainInputs[0] = np.array(TrainInputs[0])
147
+ TrainInputs[0] = TrainInputs[0].ravel()
148
+ TrainInputsize = len(TrainInputs[0])
138
149
 
139
- W = WeightIdentification(len(Layers) - 1,ClassCount,Neurons,InputSize)
150
+ W = WeightIdentification(len(Layers) - 1,ClassCount,Neurons,TrainInputsize)
140
151
  Divides = SynapticDividing(ClassCount,W)
141
152
  TrainedWs = [1] * len(W)
142
153
  print(Fore.GREEN + "Train Started with 0 ERROR" + Style.RESET_ALL,)
143
- TrainPredictions = [1] * len(Labels)
154
+ TrainPredictions = [None] * len(TrainLabels)
144
155
  true = 0
145
- Inputs, Labels = AutoBalancer(Inputs, Labels, ClassCount)
146
156
  StartTime = time.time()
147
- for index, inp in enumerate(Inputs):
157
+ for index, inp in enumerate(TrainInputs):
148
158
  UniStartTime = time.time()
149
159
  inp = np.array(inp)
150
160
  inp = inp.ravel()
151
161
 
152
- if InputSize != len(inp):
153
- print(Fore.RED +"ERROR304: All input matrices or vectors in inputs list, must be same size. from: TrainDPNN",infoDPNN + Style.RESET_ALL)
162
+ if TrainInputsize != len(inp):
163
+ print(Fore.RED +"ERROR304: All input matrices or vectors in TrainInputs list, must be same size. from: TrainPLAN",infoPLAN + Style.RESET_ALL)
154
164
  return 'e'
155
165
 
156
166
 
157
- for Ulindex, Ul in enumerate(UniqueLabels):
167
+ for Ulindex, Ul in enumerate(UniqueTrainLabels):
158
168
 
159
- if Ul == Labels[index]:
169
+ if Ul == TrainLabels[index]:
160
170
  for Windex, w in enumerate(W):
161
171
  for i, ul in enumerate(Ul):
162
172
  if ul == 1.0:
@@ -180,16 +190,34 @@ def TrainDPNN(
180
190
  NeuralLayer = Softmax(NeuralLayer)
181
191
 
182
192
  if Layer == 'fex':
183
- NeuralLayer,W[Lindex] = Fex(NeuralLayer, W[Lindex], ThresholdSigns[Lindex], ThresholdValues[Lindex])
193
+ NeuralLayer,W[Lindex] = Fex(NeuralLayer, W[Lindex], MembranThresholds[Lindex], MembranPotentials[Lindex])
184
194
  elif Layer == 'cat':
185
- NeuralLayer,W[Lindex] = Cat(NeuralLayer, W[Lindex], ThresholdSigns[Lindex], ThresholdValues[Lindex],1)
195
+ NeuralLayer,W[Lindex] = Cat(NeuralLayer, W[Lindex], MembranThresholds[Lindex], MembranPotentials[Lindex],1)
186
196
 
187
- RealOutput = np.argmax(Labels[index])
197
+ RealOutput = np.argmax(TrainLabels[index])
188
198
  PredictedOutput = np.argmax(NeuralLayer)
189
199
  if RealOutput == PredictedOutput:
190
200
  true += 1
191
- Acc = true / len(Labels)
192
- TrainPredictions[index] = PredictedOutput+1
201
+ Acc = true / len(TrainLabels)
202
+ TrainPredictions[index] = PredictedOutput
203
+
204
+ if Visualize == 'y':
205
+
206
+ TrainLabelsVisual = np.copy(TrainLabels)
207
+ TrainLabelsVisual = np.argmax(TrainLabelsVisual, axis=1)
208
+
209
+ plt.figure(figsize=(12, 6))
210
+ sns.kdeplot(TrainLabelsVisual, label='Real Outputs', shade=True)
211
+ sns.kdeplot(TrainPredictions, label='Predictions', shade=True)
212
+ plt.legend()
213
+ plt.xlabel('Class')
214
+ plt.ylabel('Data size')
215
+ plt.title('Predictions and Real Outputs for Training KDE Plot')
216
+ plt.show()
217
+
218
+ if index + 1 != len(TrainInputs):
219
+
220
+ plt.close('all')
193
221
 
194
222
  if index == 0:
195
223
  for i, w in enumerate(W):
@@ -200,12 +228,12 @@ def TrainDPNN(
200
228
  TrainedWs[i] = TrainedWs[i] + w
201
229
 
202
230
 
203
- W = WeightIdentification(len(Layers) - 1,ClassCount,Neurons,InputSize)
231
+ W = WeightIdentification(len(Layers) - 1,ClassCount,Neurons,TrainInputsize)
204
232
 
205
233
 
206
234
  UniEndTime = time.time()
207
235
 
208
- CalculatingEst = round((UniEndTime - UniStartTime) * (len(Inputs) - index),3)
236
+ CalculatingEst = round((UniEndTime - UniStartTime) * (len(TrainInputs) - index),3)
209
237
 
210
238
  if CalculatingEst < 60:
211
239
  print('\rest......(sec):',CalculatingEst,'\n',end= "")
@@ -246,7 +274,7 @@ def TrainDPNN(
246
274
 
247
275
 
248
276
 
249
- return TrainedWs,TrainPredictions
277
+ return TrainedWs,TrainPredictions,Acc
250
278
 
251
279
  # FUNCTIONS -----
252
280
 
@@ -254,7 +282,7 @@ def WeightIdentification(
254
282
  LayerCount, # int: Number of layers in the neural network.
255
283
  ClassCount, # int: Number of classes in the classification task.
256
284
  Neurons, # list[num]: List of neuron counts for each layer.
257
- InputSize # int: Size of the input data.
285
+ TrainInputsize # int: Size of the input data.
258
286
  ) -> str:
259
287
  """
260
288
  Identifies the weights for a neural network model.
@@ -263,7 +291,7 @@ def WeightIdentification(
263
291
  LayerCount (int): Number of layers in the neural network.
264
292
  ClassCount (int): Number of classes in the classification task.
265
293
  Neurons (list[num]): List of neuron counts for each layer.
266
- InputSize (int): Size of the input data.
294
+ TrainInputsize (int): Size of the input data.
267
295
 
268
296
  Returns:
269
297
  list([numpy_arrays],[...]): Weight matices of the model. .
@@ -272,7 +300,7 @@ def WeightIdentification(
272
300
 
273
301
  Wlen = LayerCount + 1
274
302
  W = [None] * Wlen
275
- W[0] = np.ones((Neurons[0],InputSize))
303
+ W[0] = np.ones((Neurons[0],TrainInputsize))
276
304
  ws = LayerCount - 1
277
305
  for w in range(ws):
278
306
  W[w + 1] = np.ones((Neurons[w + 1],Neurons[w]))
@@ -390,8 +418,8 @@ def SynapticDividing(
390
418
  def Fex(
391
419
  Input, # list[num]: Input data.
392
420
  w, # list[list[num]]: Weight matrix of the neural network.
393
- ThresholdsSign, # str: Sign for threshold comparison ('<', '>', '==', '!=').
394
- ThresholdValue # num: Threshold value for comparison.
421
+ MembranThreshold, # str: Sign for threshold comparison ('<', '>', '==', '!=').
422
+ MembranPotential # num: Threshold value for comparison.
395
423
  ) -> tuple:
396
424
  """
397
425
  Applies feature extraction process to the input data using synaptic pruning.
@@ -399,21 +427,21 @@ def Fex(
399
427
  Args:
400
428
  Input (list[num]): Input data.
401
429
  w (list[list[num]]): Weight matrix of the neural network.
402
- ThresholdsSign (str): Sign for threshold comparison ('<', '>', '==', '!=').
403
- ThresholdValue (num): Threshold value for comparison.
430
+ MembranThreshold (str): Sign for threshold comparison ('<', '>', '==', '!=').
431
+ MembranPotential (num): Threshold value for comparison.
404
432
 
405
433
  Returns:
406
434
  tuple: A tuple (vector) containing the neural layer result and the updated weight matrix.
407
435
  """
408
436
 
409
- if ThresholdsSign == '<':
410
- PruneIndex = np.where(Input < ThresholdValue)
411
- elif ThresholdsSign == '>':
412
- PruneIndex = np.where(Input > ThresholdValue)
413
- elif ThresholdsSign == '==':
414
- PruneIndex = np.where(Input == ThresholdValue)
415
- elif ThresholdsSign == '!=':
416
- PruneIndex = np.where(Input != ThresholdValue)
437
+ if MembranThreshold == '<':
438
+ PruneIndex = np.where(Input < MembranPotential)
439
+ elif MembranThreshold == '>':
440
+ PruneIndex = np.where(Input > MembranPotential)
441
+ elif MembranThreshold == '==':
442
+ PruneIndex = np.where(Input == MembranPotential)
443
+ elif MembranThreshold == '!=':
444
+ PruneIndex = np.where(Input != MembranPotential)
417
445
 
418
446
  w = SynapticPruning(w, PruneIndex, 'col', 0, 0)
419
447
 
@@ -423,8 +451,8 @@ def Fex(
423
451
  def Cat(
424
452
  Input, # list[num]: Input data.
425
453
  w, # list[list[num]]: Weight matrix of the neural network.
426
- ThresholdsSign, # str: Sign for threshold comparison ('<', '>', '==', '!=').
427
- ThresholdValue, # num: Threshold value for comparison.
454
+ MembranThreshold, # str: Sign for threshold comparison ('<', '>', '==', '!=').
455
+ MembranPotential, # num: Threshold value for comparison.
428
456
  isTrain # int: Flag indicating if the function is called during training (1 for training, 0 otherwise).
429
457
  ) -> tuple:
430
458
  """
@@ -433,23 +461,23 @@ def Cat(
433
461
  Args:
434
462
  Input (list[num]): Input data.
435
463
  w (list[list[num]]): Weight matrix of the neural network.
436
- ThresholdsSign (str): Sign for threshold comparison ('<', '>', '==', '!=').
437
- ThresholdValue (num): Threshold value for comparison.
464
+ MembranThreshold (str): Sign for threshold comparison ('<', '>', '==', '!=').
465
+ MembranPotential (num): Threshold value for comparison.
438
466
  isTrain (int): Flag indicating if the function is called during training (1 for training, 0 otherwise).
439
467
 
440
468
  Returns:
441
469
  tuple: A tuple containing the neural layer (vector) result and the possibly updated weight matrix.
442
470
  """
443
471
 
444
- if ThresholdsSign == '<':
445
- PruneIndex = np.where(Input < ThresholdValue)
446
- elif ThresholdsSign == '>':
447
- PruneIndex = np.where(Input > ThresholdValue)
448
- elif ThresholdsSign == '==':
449
- PruneIndex = np.where(Input == ThresholdValue)
450
- elif ThresholdsSign == '!=':
451
- PruneIndex = np.where(Input != ThresholdValue)
452
- if isTrain == 1 and ThresholdsSign != 'none':
472
+ if MembranThreshold == '<':
473
+ PruneIndex = np.where(Input < MembranPotential)
474
+ elif MembranThreshold == '>':
475
+ PruneIndex = np.where(Input > MembranPotential)
476
+ elif MembranThreshold == '==':
477
+ PruneIndex = np.where(Input == MembranPotential)
478
+ elif MembranThreshold == '!=':
479
+ PruneIndex = np.where(Input != MembranPotential)
480
+ if isTrain == 1 and MembranThreshold != 'none':
453
481
 
454
482
  w = SynapticPruning(w, PruneIndex, 'col', 0, 0)
455
483
 
@@ -493,19 +521,8 @@ def Softmax(
493
521
  Returns:
494
522
  list[num]: Transformed data after applying softmax function.
495
523
  """
496
-
497
-
498
- MaxX = np.max(x)
499
-
500
- x -= MaxX
501
-
502
- ExpX = np.exp(x)
503
-
504
- SumExpX = np.sum(ExpX)
505
524
 
506
- SoftmaxX = ExpX / SumExpX
507
-
508
- return SoftmaxX
525
+ return softmax(x)
509
526
 
510
527
 
511
528
  def Sigmoid(
@@ -520,18 +537,7 @@ def Sigmoid(
520
537
  Returns:
521
538
  list[num]: Transformed data after applying sigmoid function.
522
539
  """
523
-
524
- PositiveMask = x >= 0
525
- NegativeMask = ~PositiveMask
526
-
527
- ExpXPositive = np.exp(-np.clip(x[PositiveMask], -709, None))
528
- ExpXNegative = np.exp(np.clip(x[NegativeMask], None, 709))
529
-
530
- SigmoidX = np.zeros_like(x, dtype=float)
531
- SigmoidX[PositiveMask] = 1 / (1 + ExpXPositive)
532
- SigmoidX[NegativeMask] = ExpXNegative / (1 + ExpXNegative)
533
-
534
- return SigmoidX
540
+ return expit(x)
535
541
 
536
542
 
537
543
  def Relu(
@@ -551,14 +557,15 @@ def Relu(
551
557
  return np.maximum(0, x)
552
558
 
553
559
 
554
- def TestDPNN(
560
+ def TestPLAN(
555
561
  TestInputs, # list[list[num]]: Test input data.
556
562
  TestLabels, # list[num]: Test labels.
557
563
  Layers, # list[str]: List of layer names.
558
- ThresholdSigns, # list[str]: List of threshold signs for each layer.
559
- ThresholdValues, # list[num]: List of threshold values for each layer.
564
+ MembranThresholds, # list[str]: List of MEMBRAN THRESHOLDS for each layer.
565
+ MembranPotentials, # list[num]: List of MEMBRAN POTENTIALS for each layer.
560
566
  Normalizations, # str: Whether normalization will be performed ("y" or "n").
561
- Activation, # str: Activation function list for the neural network.
567
+ Activations, # str: Activation function list for the neural network.
568
+ Visualize, # Visualize Testing procces or not visualize ('y' or 'n')
562
569
  W # list[list[num]]: Weight matrix of the neural network.
563
570
  ) -> tuple:
564
571
  infoTestModel = """
@@ -568,8 +575,8 @@ def TestDPNN(
568
575
  TestInputs (list[list[num]]): Test input data.
569
576
  TestLabels (list[num]): Test labels.
570
577
  Layers (list[str]): List of layer names.
571
- ThresholdSigns (list[str]): List of threshold signs for each layer.
572
- ThresholdValues (list[num]): List of threshold values for each layer.
578
+ MembranThresholds (list[str]): List of MEMBRAN THRESHOLDS for each layer.
579
+ MembranPotentials (list[num]): List of MEMBRAN POTENTIALS for each layer.
573
580
  Normalizatios list([str]): Whether normalization will be performed ("yes" or "no").
574
581
  Activation (str): Activation function for the neural network.
575
582
  W (list[list[num]]): Weight matrix of the neural network.
@@ -582,7 +589,7 @@ def TestDPNN(
582
589
  try:
583
590
  Wc = [0] * len(W)
584
591
  true = 0
585
- TestPredictions = [1] * len(TestLabels)
592
+ TestPredictions = [None] * len(TestLabels)
586
593
  for i, w in enumerate(W):
587
594
  Wc[i] = np.copy(w)
588
595
  print('\rCopying weights.....',i+1,'/',len(W),end = "")
@@ -598,17 +605,17 @@ def TestDPNN(
598
605
  for index, Layer in enumerate(Layers):
599
606
  if Normalizations[index] == 'y':
600
607
  NeuralLayer = Normalization(NeuralLayer)
601
- if Activation[index] == 'relu':
608
+ if Activations[index] == 'relu':
602
609
  NeuralLayer = Relu(NeuralLayer)
603
- elif Activation[index] == 'sigmoid':
610
+ elif Activations[index] == 'sigmoid':
604
611
  NeuralLayer = Sigmoid(NeuralLayer)
605
- elif Activation[index] == 'softmax':
612
+ elif Activations[index] == 'softmax':
606
613
  NeuralLayer = Softmax(NeuralLayer)
607
614
 
608
615
  if Layers[index] == 'fex':
609
- NeuralLayer,useless = Fex(NeuralLayer, W[index], ThresholdSigns[index], ThresholdValues[index])
616
+ NeuralLayer,useless = Fex(NeuralLayer, W[index], MembranThresholds[index], MembranPotentials[index])
610
617
  if Layers[index] == 'cat':
611
- NeuralLayer,useless = Cat(NeuralLayer, W[index], ThresholdSigns[index], ThresholdValues[index],0)
618
+ NeuralLayer,useless = Cat(NeuralLayer, W[index], MembranThresholds[index], MembranPotentials[index],0)
612
619
  for i, w in enumerate(Wc):
613
620
  W[i] = np.copy(w)
614
621
  RealOutput = np.argmax(TestLabels[inpIndex])
@@ -616,7 +623,26 @@ def TestDPNN(
616
623
  if RealOutput == PredictedOutput:
617
624
  true += 1
618
625
  Acc = true / len(TestLabels)
619
- TestPredictions[inpIndex] = PredictedOutput+1
626
+ TestPredictions[inpIndex] = PredictedOutput
627
+
628
+ if Visualize == 'y':
629
+
630
+ TestLabelsVisual = np.copy(TestLabels)
631
+ TestLabelsVisual = np.argmax(TestLabelsVisual, axis=1)
632
+
633
+ plt.figure(figsize=(12, 6))
634
+ sns.kdeplot(TestLabelsVisual, label='Real Outputs', shade=True)
635
+ sns.kdeplot(TestPredictions, label='Predictions', shade=True)
636
+ plt.legend()
637
+ plt.xlabel('Class')
638
+ plt.ylabel('Data size')
639
+ plt.title('Predictions and Real Outputs for Testing KDE Plot')
640
+ plt.show()
641
+
642
+ if inpIndex + 1 != len(TestInputs):
643
+
644
+ plt.close('all')
645
+
620
646
  UniEndTime = time.time()
621
647
 
622
648
  CalculatingEst = round((UniEndTime - UniStartTime) * (len(TestInputs) - inpIndex),3)
@@ -661,44 +687,44 @@ def TestDPNN(
661
687
 
662
688
  except:
663
689
 
664
- print(Fore.RED + "ERROR: Testing model parameters like 'Layers' 'ThresholdCounts' must be same as trained model. Check parameters. Are you sure weights are loaded ? from: TestDPNN" + infoTestModel + Style.RESET_ALL)
690
+ print(Fore.RED + "ERROR: Testing model parameters like 'Layers' 'MembranCounts' must be same as trained model. Check parameters. Are you sure weights are loaded ? from: TestPLAN" + infoTestModel + Style.RESET_ALL)
665
691
  return 'e'
666
692
 
667
- return TestPredictions,Acc
693
+ return W,TestPredictions,Acc
668
694
 
669
- def SaveDPNN(ModelName,
695
+ def SavePLAN(ModelName,
670
696
  ModelType,
671
697
  Layers,
672
698
  ClassCount,
673
- ThresholdSigns,
674
- ThresholdValues,
699
+ MembranThresholds,
700
+ MembranPotentials,
675
701
  Normalizations,
676
702
  Activations,
677
703
  TestAcc,
678
704
  LogType,
679
705
  WeightsType,
680
- WeightFormat,
681
- SavePath,
706
+ WeightsFormat,
707
+ ModelPath,
682
708
  W
683
709
  ):
684
710
 
685
- infoSaveDPNN = """
711
+ infoSavePLAN = """
686
712
  Function to save a deep learning model.
687
713
 
688
714
  Arguments:
689
715
  ModelName (str): Name of the model.
690
- ModelType (str): Type of the model.(options: DPNN)
716
+ ModelType (str): Type of the model.(options: PLAN)
691
717
  Layers (list): List containing 'fex' and 'cat' layers.
692
718
  ClassCount (int): Number of classes.
693
- ThresholdSigns (list): List containing threshold signs.
694
- ThresholdValues (list): List containing threshold values.
719
+ MembranThresholds (list): List containing MEMBRAN THRESHOLDS.
720
+ MembranPotentials (list): List containing MEMBRAN POTENTIALS.
695
721
  DoNormalization (str): is that normalized data ? 'y' or 'n'.
696
722
  Activations (list): List containing activation functions for each layer.
697
723
  TestAcc (float): Test accuracy of the model.
698
724
  LogType (str): Type of log to save (options: 'csv', 'txt', 'hdf5').
699
725
  WeightsType (str): Type of weights to save (options: 'txt', 'npy', 'mat').
700
726
  WeightFormat (str): Format of the weights (options: 'd', 'f', 'raw').
701
- SavePath (str): Path where the model will be saved. For example: C:/Users/beydili/Desktop/denemeDPNN/
727
+ ModelPath (str): Path where the model will be saved. For example: C:/Users/beydili/Desktop/denemePLAN/
702
728
  W: Weights of the model.
703
729
 
704
730
  Returns:
@@ -709,15 +735,15 @@ def SaveDPNN(ModelName,
709
735
  pass
710
736
 
711
737
  if LogType != 'csv' and LogType != 'txt' and LogType != 'hdf5':
712
- print(Fore.RED + "ERROR109: Save Log Type (File Extension) must be 'csv' or 'txt' or 'hdf5' from: SaveDPNN" + infoSaveDPNN + Style.RESET_ALL)
738
+ print(Fore.RED + "ERROR109: Save Log Type (File Extension) must be 'csv' or 'txt' or 'hdf5' from: SavePLAN" + infoSavePLAN + Style.RESET_ALL)
713
739
  return 'e'
714
740
 
715
741
  if WeightsType != 'txt' and WeightsType != 'npy' and WeightsType != 'mat':
716
- print(Fore.RED + "ERROR110: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' from: SaveDPNN" + infoSaveDPNN + Style.RESET_ALL)
742
+ print(Fore.RED + "ERROR110: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' from: SavePLAN" + infoSavePLAN + Style.RESET_ALL)
717
743
  return 'e'
718
744
 
719
- if WeightFormat != 'd' and WeightFormat != 'f' and WeightFormat != 'raw':
720
- print(Fore.RED + "ERROR111: Weight Format Type must be 'd' or 'f' or 'raw' from: SaveDPNN" + infoSaveDPNN + Style.RESET_ALL)
745
+ if WeightsFormat != 'd' and WeightsFormat != 'f' and WeightsFormat != 'raw':
746
+ print(Fore.RED + "ERROR111: Weight Format Type must be 'd' or 'f' or 'raw' from: SavePLAN" + infoSavePLAN + Style.RESET_ALL)
721
747
  return 'e'
722
748
 
723
749
  NeuronCount = 0
@@ -728,7 +754,7 @@ def SaveDPNN(ModelName,
728
754
  SynapseCount += np.shape(w)[0] * np.shape(w)[1]
729
755
  except:
730
756
 
731
- print(Fore.RED + "ERROR: Weight matrices has a problem from: SaveDPNN" + infoSaveDPNN + Style.RESET_ALL)
757
+ print(Fore.RED + "ERROR: Weight matrices has a problem from: SavePLAN" + infoSavePLAN + Style.RESET_ALL)
732
758
  return 'e'
733
759
  import pandas as pd
734
760
  from datetime import datetime
@@ -739,8 +765,8 @@ def SaveDPNN(ModelName,
739
765
  'LAYERS': Layers,
740
766
  'LAYER COUNT': len(Layers),
741
767
  'CLASS COUNT': ClassCount,
742
- 'THRESHOLD SIGNS': ThresholdSigns,
743
- 'THRESHOLD VALUES': ThresholdValues,
768
+ 'MEMBRAN THRESHOLDS': MembranThresholds,
769
+ 'MEMBRAN POTENTIALS': MembranPotentials,
744
770
  'NORMALIZATION': Normalizations,
745
771
  'ACTIVATIONS': Activations,
746
772
  'NEURON COUNT': NeuronCount,
@@ -748,8 +774,8 @@ def SaveDPNN(ModelName,
748
774
  'TEST ACCURACY': TestAcc,
749
775
  'SAVE DATE': datetime.now(),
750
776
  'WEIGHTS TYPE': WeightsType,
751
- 'WEIGHTS FORMAT': WeightFormat,
752
- 'SAVE PATH': SavePath
777
+ 'WEIGHTS FORMAT': WeightsFormat,
778
+ 'MODEL PATH': ModelPath
753
779
  }
754
780
  try:
755
781
 
@@ -757,81 +783,81 @@ def SaveDPNN(ModelName,
757
783
 
758
784
  if LogType == 'csv':
759
785
 
760
- df.to_csv(SavePath + ModelName + '.csv', sep='\t', index=False)
786
+ df.to_csv(ModelPath + ModelName + '.csv', sep='\t', index=False)
761
787
 
762
788
  elif LogType == 'txt':
763
789
 
764
- df.to_csv(SavePath + ModelName + '.txt', sep='\t', index=False)
790
+ df.to_csv(ModelPath + ModelName + '.txt', sep='\t', index=False)
765
791
 
766
792
  elif LogType == 'hdf5':
767
793
 
768
- df.to_hdf(SavePath + ModelName + '.h5', key='data', mode='w')
794
+ df.to_hdf(ModelPath + ModelName + '.h5', key='data', mode='w')
769
795
 
770
796
  except:
771
797
 
772
- print(Fore.RED + "ERROR: Model log not saved. Check the log parameters from: SaveDPNN" + infoSaveDPNN + Style.RESET_ALL)
798
+ print(Fore.RED + "ERROR: Model log not saved probably ModelPath incorrect. Check the log parameters from: SavePLAN" + infoSavePLAN + Style.RESET_ALL)
773
799
  return 'e'
774
800
  try:
775
801
 
776
- if WeightsType == 'txt' and WeightFormat == 'd':
802
+ if WeightsType == 'txt' and WeightsFormat == 'd':
777
803
 
778
804
  for i, w in enumerate(W):
779
- np.savetxt(SavePath + ModelName + str(i+1) + 'w.txt' , w, fmt='%d')
805
+ np.savetxt(ModelPath + ModelName + str(i+1) + 'w.txt' , w, fmt='%d')
780
806
 
781
- if WeightsType == 'txt' and WeightFormat == 'f':
807
+ if WeightsType == 'txt' and WeightsFormat == 'f':
782
808
 
783
809
  for i, w in enumerate(W):
784
- np.savetxt(SavePath + ModelName + str(i+1) + 'w.txt' , w, fmt='%f')
810
+ np.savetxt(ModelPath + ModelName + str(i+1) + 'w.txt' , w, fmt='%f')
785
811
 
786
- if WeightsType == 'txt' and WeightFormat == 'raw':
812
+ if WeightsType == 'txt' and WeightsFormat == 'raw':
787
813
 
788
814
  for i, w in enumerate(W):
789
- np.savetxt(SavePath + ModelName + str(i+1) + 'w.txt' , w)
815
+ np.savetxt(ModelPath + ModelName + str(i+1) + 'w.txt' , w)
790
816
 
791
817
 
792
818
  ###
793
819
 
794
820
 
795
- if WeightsType == 'npy' and WeightFormat == 'd':
821
+ if WeightsType == 'npy' and WeightsFormat == 'd':
796
822
 
797
823
  for i, w in enumerate(W):
798
- np.save(SavePath + ModelName + str(i+1) + 'w.npy', w.astype(int))
824
+ np.save(ModelPath + ModelName + str(i+1) + 'w.npy', w.astype(int))
799
825
 
800
- if WeightsType == 'npy' and WeightFormat == 'f':
826
+ if WeightsType == 'npy' and WeightsFormat == 'f':
801
827
 
802
828
  for i, w in enumerate(W):
803
- np.save(SavePath + ModelName + str(i+1) + 'w.npy' , w, w.astype(float))
829
+ np.save(ModelPath + ModelName + str(i+1) + 'w.npy' , w, w.astype(float))
804
830
 
805
- if WeightsType == 'npy' and WeightFormat == 'raw':
831
+ if WeightsType == 'npy' and WeightsFormat == 'raw':
806
832
 
807
833
  for i, w in enumerate(W):
808
- np.save(SavePath + ModelName + str(i+1) + 'w.npy' , w)
834
+ np.save(ModelPath + ModelName + str(i+1) + 'w.npy' , w)
809
835
 
810
836
 
811
837
  ###
812
838
 
813
839
 
814
- if WeightsType == 'mat' and WeightFormat == 'd':
840
+ if WeightsType == 'mat' and WeightsFormat == 'd':
815
841
 
816
842
  for i, w in enumerate(W):
817
843
  w = {'w': w.astype(int)}
818
- io.savemat(SavePath + ModelName + str(i+1) + 'w.mat', w)
844
+ io.savemat(ModelPath + ModelName + str(i+1) + 'w.mat', w)
819
845
 
820
- if WeightsType == 'mat' and WeightFormat == 'f':
846
+ if WeightsType == 'mat' and WeightsFormat == 'f':
821
847
 
822
848
  for i, w in enumerate(W):
823
849
  w = {'w': w.astype(float)}
824
- io.savemat(SavePath + ModelName + str(i+1) + 'w.mat', w)
850
+ io.savemat(ModelPath + ModelName + str(i+1) + 'w.mat', w)
825
851
 
826
- if WeightsType == 'mat' and WeightFormat == 'raw':
852
+ if WeightsType == 'mat' and WeightsFormat == 'raw':
827
853
 
828
854
  for i, w in enumerate(W):
829
855
  w = {'w': w}
830
- io.savemat(SavePath + ModelName + str(i+1) + 'w.mat', w)
856
+ io.savemat(ModelPath + ModelName + str(i+1) + 'w.mat', w)
831
857
 
832
858
  except:
833
859
 
834
- print(Fore.RED + "ERROR: Model Weights not saved. Check the Weight parameters. SaveFilePath expl: 'C:/Users/hasancanbeydili/Desktop/denemeDPNN/' from: SaveDPNN" + infoSaveDPNN + Style.RESET_ALL)
860
+ print(Fore.RED + "ERROR: Model Weights not saved. Check the Weight parameters. SaveFilePath expl: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: SavePLAN" + infoSavePLAN + Style.RESET_ALL)
835
861
  return 'e'
836
862
  print(df)
837
863
  message = (
@@ -843,20 +869,20 @@ def SaveDPNN(ModelName,
843
869
  return print(message)
844
870
 
845
871
 
846
- def LoadDPNN(ModelName,
847
- LoadPath,
872
+ def LoadPLAN(ModelName,
873
+ ModelPath,
848
874
  LogType,
849
875
  ):
850
- infoLoadDPNN = """
876
+ infoLoadPLAN = """
851
877
  Function to load a deep learning model.
852
878
 
853
879
  Arguments:
854
880
  ModelName (str): Name of the model.
855
- LoadPath (str): Path where the model is saved.
881
+ ModelPath (str): Path where the model is saved.
856
882
  LogType (str): Type of log to load (options: 'csv', 'txt', 'hdf5').
857
883
 
858
884
  Returns:
859
- lists: W(list[num]), Layers, ThresholdSigns, ThresholdValues, Normalization,Activations
885
+ lists: W(list[num]), Layers, MembranThresholds, MembranPotentials, Normalization,Activations
860
886
  """
861
887
  pass
862
888
 
@@ -867,25 +893,25 @@ def LoadDPNN(ModelName,
867
893
  try:
868
894
 
869
895
  if LogType == 'csv':
870
- df = pd.read_csv(LoadPath + ModelName + '.' + LogType)
896
+ df = pd.read_csv(ModelPath + ModelName + '.' + LogType)
871
897
 
872
898
 
873
899
  if LogType == 'txt':
874
- df = pd.read_csv(LoadPath + ModelName + '.' + LogType, delimiter='\t')
900
+ df = pd.read_csv(ModelPath + ModelName + '.' + LogType, delimiter='\t')
875
901
 
876
902
 
877
903
  if LogType == 'hdf5':
878
- df = pd.read_hdf(LoadPath + ModelName + '.' + LogType)
904
+ df = pd.read_hdf(ModelPath + ModelName + '.' + LogType)
879
905
  except:
880
- print(Fore.RED + "ERROR: Model Path error. Accaptable form: 'C:/Users/hasancanbeydili/Desktop/denemeDPNN/' from: LoadDPNN" + infoLoadDPNN + Style.RESET_ALL)
906
+ print(Fore.RED + "ERROR: Model Path error. Accaptable form: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: LoadPLAN" + infoLoadPLAN + Style.RESET_ALL)
881
907
 
882
908
  ModelName = str(df['MODEL NAME'].iloc[0])
883
909
  Layers = df['LAYERS'].tolist()
884
910
  LayerCount = int(df['LAYER COUNT'].iloc[0])
885
911
  ClassCount = int(df['CLASS COUNT'].iloc[0])
886
- ThresholdSigns = df['THRESHOLD SIGNS'].tolist()
887
- ThresholdValues = df['THRESHOLD VALUES'].tolist()
888
- Normalization = df['NORMALIZATION'].tolist()
912
+ MembranThresholds = df['MEMBRAN THRESHOLDS'].tolist()
913
+ MembranPotentials = df['MEMBRAN POTENTIALS'].tolist()
914
+ Normalizations = df['NORMALIZATION'].tolist()
889
915
  Activations = df['ACTIVATIONS'].tolist()
890
916
  NeuronCount = int(df['NEURON COUNT'].iloc[0])
891
917
  SynapseCount = int(df['SYNAPSE COUNT'].iloc[0])
@@ -893,27 +919,27 @@ def LoadDPNN(ModelName,
893
919
  ModelType = str(df['MODEL TYPE'].iloc[0])
894
920
  WeightType = str(df['WEIGHTS TYPE'].iloc[0])
895
921
  WeightFormat = str(df['WEIGHTS FORMAT'].iloc[0])
896
- SavePath = str(df['SAVE PATH'].iloc[0])
922
+ ModelPath = str(df['MODEL PATH'].iloc[0])
897
923
 
898
924
  W = [0] * LayerCount
899
925
 
900
926
  if WeightType == 'txt':
901
- for i in range(LayerCount):
902
- W[i] = np.loadtxt(LoadPath + ModelName + str(i+1) + 'w.txt')
927
+ for i in range(LayerCount):
928
+ W[i] = np.loadtxt(ModelPath + ModelName + str(i+1) + 'w.txt')
903
929
  elif WeightType == 'npy':
904
930
  for i in range(LayerCount):
905
- W[i] = np.load(LoadPath + ModelName + str(i+1) + 'w.npy')
931
+ W[i] = np.load(ModelPath + ModelName + str(i+1) + 'w.npy')
906
932
  elif WeightType == 'mat':
907
933
  for i in range(LayerCount):
908
- W[i] = sio.loadmat(LoadPath + ModelName + str(i+1) + 'w.mat')
934
+ W[i] = sio.loadmat(ModelPath + ModelName + str(i+1) + 'w.mat')
909
935
  else:
910
- raise ValueError(Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy' or 'mat' from: LoadDPNN." + infoLoadDPNN + Style.RESET_ALL)
936
+ raise ValueError(Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy' or 'mat' from: LoadPLAN." + infoLoadPLAN + Style.RESET_ALL)
911
937
  print(Fore.GREEN + "Model loaded succesfully" + Style.RESET_ALL)
912
- return W,Layers,ThresholdSigns,ThresholdValues,Normalization,Activations,df
938
+ return W,Layers,MembranThresholds,MembranPotentials,Normalizations,Activations,df
913
939
 
914
- def PredictFromDiscDPNN(Input,ModelName,ModelPath,LogType):
915
- infoPredictFromDİscDPNN = """
916
- Function to make a prediction using a divided pruning deep learning neural network (DPNN).
940
+ def PredictFromDiscPLAN(Input,ModelName,ModelPath,LogType):
941
+ infoPredictFromDİscPLAN = """
942
+ Function to make a prediction using a divided pruning deep learning neural network (PLAN).
917
943
 
918
944
  Arguments:
919
945
  Input (list or ndarray): Input data for the model (single vector or single matrix).
@@ -924,7 +950,7 @@ def PredictFromDiscDPNN(Input,ModelName,ModelPath,LogType):
924
950
  Returns:
925
951
  ndarray: Output from the model.
926
952
  """
927
- W,Layers,ThresholdSigns,ThresholdValues,Normalization,Activations = LoadDPNN(ModelName,ModelPath,
953
+ W,Layers,MembranThresholds,MembranPotentials,Normalizations,Activations = LoadPLAN(ModelName,ModelPath,
928
954
  LogType)[0:6]
929
955
  Wc = [0] * len(W)
930
956
  for i, w in enumerate(W):
@@ -945,31 +971,31 @@ def PredictFromDiscDPNN(Input,ModelName,ModelPath,LogType):
945
971
 
946
972
  if Layers[index] == 'fex':
947
973
  NeuralLayer,useless = Fex(NeuralLayer, W[index],
948
- ThresholdSigns[index],
949
- ThresholdValues[index])
974
+ MembranThresholds[index],
975
+ MembranPotentials[index])
950
976
  if Layers[index] == 'cat':
951
977
  NeuralLayer,useless = Cat(NeuralLayer, W[index],
952
- ThresholdSigns[index],
953
- ThresholdValues[index],
978
+ MembranThresholds[index],
979
+ MembranPotentials[index],
954
980
  0)
955
981
  except:
956
- print(Fore.RED + "ERROR: The input was probably entered incorrectly. from: PredictFromDiscDPNN" + infoPredictFromDİscDPNN + Style.RESET_ALL)
982
+ print(Fore.RED + "ERROR: The input was probably entered incorrectly. from: PredictFromDiscPLAN" + infoPredictFromDİscPLAN + Style.RESET_ALL)
957
983
  return 'e'
958
984
  for i, w in enumerate(Wc):
959
985
  W[i] = np.copy(w)
960
986
  return NeuralLayer
961
987
 
962
988
 
963
- def PredictFromRamDPNN(Input,Layers,ThresholdSigns,ThresholdValues,Normalizations,Activations,W):
964
- infoPredictFromRamDPNN = """
965
- Function to make a prediction using a divided pruning learning neural network (DPNN)
989
+ def PredictFromRamPLAN(Input,Layers,MembranThresholds,MembranPotentials,Normalizations,Activations,W):
990
+ infoPredictFromRamPLAN = """
991
+ Function to make a prediction using a pruning learning artificial neural network (PLAN)
966
992
  from weights and parameters stored in memory.
967
993
 
968
994
  Arguments:
969
995
  Input (list or ndarray): Input data for the model (single vector or single matrix).
970
996
  Layers (list): Number and types of layers.
971
- ThresholdSigns (list): Threshold signs.
972
- ThresholdValues (list): Threshold values.
997
+ MembranThresholds (list): MEMBRAN THRESHOLDS.
998
+ MembranPotentials (list): MEMBRAN POTENTIALS.
973
999
  DoNormalization (str): Whether to normalize ('y' or 'n').
974
1000
  Activations (list): Activation functions for each layer.
975
1001
  W (list of ndarrays): Weights of the model.
@@ -997,14 +1023,14 @@ def PredictFromRamDPNN(Input,Layers,ThresholdSigns,ThresholdValues,Normalization
997
1023
 
998
1024
  if Layers[index] == 'fex':
999
1025
  NeuralLayer,useless = Fex(NeuralLayer, W[index],
1000
- ThresholdSigns[index],
1001
- ThresholdValues[index])
1026
+ MembranThresholds[index],
1027
+ MembranPotentials[index])
1002
1028
  if Layers[index] == 'cat':
1003
1029
  NeuralLayer,useless = Cat(NeuralLayer, W[index],
1004
- ThresholdSigns[index],
1005
- ThresholdValues[index],0)
1030
+ MembranThresholds[index],
1031
+ MembranPotentials[index],0)
1006
1032
  except:
1007
- print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: PredictFromRamDPNN." + infoPredictFromRamDPNN + Style.RESET_ALL)
1033
+ print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: PredictFromRamPLAN." + infoPredictFromRamPLAN + Style.RESET_ALL)
1008
1034
  return 'e'
1009
1035
  for i, w in enumerate(Wc):
1010
1036
  W[i] = np.copy(w)
@@ -1029,7 +1055,6 @@ def AutoBalancer(TrainInputs, TrainLabels, ClassCount):
1029
1055
 
1030
1056
  if len(set(ClassCounts)) == 1:
1031
1057
  print(Fore.WHITE + "INFO: All training data have already balanced. from: AutoBalancer" + Style.RESET_ALL)
1032
- time.sleep(1.5)
1033
1058
  return TrainInputs, TrainLabels
1034
1059
 
1035
1060
  MinCount = min(ClassCounts)
@@ -1045,10 +1070,26 @@ def AutoBalancer(TrainInputs, TrainLabels, ClassCount):
1045
1070
  BalancedInputs = [TrainInputs[idx] for idx in BalancedIndices]
1046
1071
  BalancedLabels = [TrainLabels[idx] for idx in BalancedIndices]
1047
1072
 
1048
- print(Fore.GREEN + "All Training Data Succesfully Balanced from: " + str(len(TrainInputs)) + " to: " + str(len(BalancedInputs)) + ". from: AutoBalancer ")
1049
- time.sleep(1.5)
1073
+ print(Fore.GREEN + "All Training Data Succesfully Balanced from: " + str(len(TrainInputs)) + " to: " + str(len(BalancedInputs)) + ". from: AutoBalancer " + Style.RESET_ALL)
1050
1074
  except:
1051
1075
  print(Fore.RED + "ERROR: Inputs and labels must be same length check parameters" + infoAutoBalancer)
1052
1076
  return 'e'
1053
1077
 
1054
- return BalancedInputs, BalancedLabels
1078
+ return BalancedInputs, BalancedLabels
1079
+
1080
+
1081
+ def GetWeights():
1082
+
1083
+ return 0
1084
+
1085
+ def GetDf():
1086
+
1087
+ return 6
1088
+
1089
+ def GetPreds():
1090
+
1091
+ return 1
1092
+
1093
+ def GetAcc():
1094
+
1095
+ return 2
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyerualjetwork
3
+ Version: 1.2.9
4
+ Summary: Advanced python deep learning library. New Visualize parameter added ('y' or 'n') for TrainPlan and TestPLAN funcs. (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
+ Requires-Dist: numpy
9
+ Requires-Dist: scipy
10
+ Requires-Dist: time
11
+ Requires-Dist: math
12
+ Requires-Dist: colorama
13
+ Requires-Dist: typing
14
+ Provides-Extra: visualization
15
+ Requires-Dist: matplotlib ; extra == 'visualization'
16
+ Requires-Dist: seaborn ; extra == 'visualization'
17
+
@@ -0,0 +1,6 @@
1
+ plan/__init__.py,sha256=4trwhtGaeJd2tncziQAKrPT-Jjz6Q8nBG0n3SlyH1a4,352
2
+ plan/plan.py,sha256=GVJdUx0F1C-h5MJAVXTvWvgHzzS0Gs8ze28E6uXMnH4,42347
3
+ pyerualjetwork-1.2.9.dist-info/METADATA,sha256=M6KntwKkuqtaDM2RWwhFXF2chklxSi99kWKeu9R7zTU,693
4
+ pyerualjetwork-1.2.9.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
+ pyerualjetwork-1.2.9.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
+ pyerualjetwork-1.2.9.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.38.4)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1 @@
1
+ plan
DPNN/__init__.py DELETED
@@ -1,2 +0,0 @@
1
- from DPNN import AutoBalancer ,Normalization,Softmax,Sigmoid,Relu,SynapticPruning,SynapticDividing,WeightIdentification,Fex,Cat,TrainDPNN,TestDPNN,SaveDPNN,LoadDPNN,PredictFromDiscDPNN,PredictFromRamDPNN
2
- import DPNN as pyerualjetwork
@@ -1,8 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: pyerualjetwork
3
- Version: 1.1.2
4
- Summary: Advanced python deep learning library.(More document coming soon..)
5
- Author: Hasan Can Beydili
6
- Author-email: tchasancan@gmail.com
7
- Keywords: model evaluation,classifcation,divided pruning neural networks
8
-
@@ -1,6 +0,0 @@
1
- DPNN/DPNN.py,sha256=YX4G0vaDOZHRF1tXITiIiE6MdidhQEESYh257dzLxn0,40243
2
- DPNN/__init__.py,sha256=59yVEoHAZchbJLqqYBPsd_r7E2xWebWx_x-fNeozwj8,234
3
- pyerualjetwork-1.1.2.dist-info/METADATA,sha256=Bo67kieqYtfkxfUeDOQ_lMeTBU-Rhym_SFjT51G7l98,278
4
- pyerualjetwork-1.1.2.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
5
- pyerualjetwork-1.1.2.dist-info/top_level.txt,sha256=FP80qXxAtwGIzBS7B8QpXzoYD7L5aFSBVzlmcFBjq7k,5
6
- pyerualjetwork-1.1.2.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- DPNN