pyerualjetwork 2.0.4__py3-none-any.whl → 2.0.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.
@@ -1,5 +1,5 @@
1
1
  """
2
- Created on Thu May 30 22:12:49 2024
2
+ Created on Thu Jun 12 00:00:00 2024
3
3
 
4
4
  @author: hasan can beydili
5
5
  """
@@ -16,7 +16,6 @@ import seaborn as sns
16
16
  def fit(
17
17
  x_train: List[Union[int, float]],
18
18
  y_train: List[Union[int, float, str]], # At least two.. and one hot encoded
19
- action_potential: Union[float],
20
19
  ) -> str:
21
20
 
22
21
  infoPLAN = """
@@ -25,18 +24,13 @@ def fit(
25
24
  Args:
26
25
  x_train (list[num]): List of input data.
27
26
  y_train (list[num]): List of y_train. (one hot encoded)
28
- action_potential (float): Input ACTION potential
27
+ activation_potential (float): Input activation potential
29
28
 
30
29
  Returns:
31
- list([num]): (Weight matrices list, train_predictions list, Trainacc).
30
+ list([num]): (Weight matrices list, train_predictions list, Train_acc).
32
31
  error handled ?: Process status ('e')
33
32
  """
34
33
 
35
- if action_potential < 0 or action_potential > 1:
36
-
37
- print(Fore.RED + "ERROR101: ACTION potential value must be in range 0-1. from: fit",infoPLAN)
38
- return 'e'
39
-
40
34
  if len(x_train) != len(y_train):
41
35
  print(Fore.RED + "ERROR301: x_train list and y_train list must be same length. from: fit",infoPLAN)
42
36
  return 'e'
@@ -93,13 +87,15 @@ def fit(
93
87
  for Lindex, Layer in enumerate(layers):
94
88
 
95
89
 
96
- neural_layer = normalization(neural_layer)
90
+ # neural_layer = normalization(neural_layer)
97
91
 
98
92
 
99
93
  if Layer == 'fex':
100
- neural_layer,W[Lindex] = fex(neural_layer, W[Lindex], action_potential, Piece[Windex], 1)
94
+ y = np.argmax(y_train[index])
95
+
96
+ neural_layer,W[Lindex] = fex(neural_layer, W[Lindex], y , 1)
101
97
  elif Layer == 'cat':
102
- neural_layer,W[Lindex] = cat(neural_layer, W[Lindex], action_potential, 1, Piece[Windex])
98
+ neural_layer,W[Lindex] = cat(neural_layer, W[Lindex], 1, Piece[Windex])
103
99
 
104
100
  RealOutput = np.argmax(y_train[index])
105
101
  PredictedOutput = np.argmax(neural_layer)
@@ -319,8 +315,7 @@ def synaptic_dividing(
319
315
  def fex(
320
316
  Input, # list[num]: Input data.
321
317
  w, # list[list[num]]: Weight matrix of the neural network.,
322
- action_potential, # num: Threshold value for comparison.
323
- piece, # ???
318
+ Class, # Which class is, if training. num
324
319
  is_training # num: 1 or 0
325
320
  ) -> tuple:
326
321
  """
@@ -329,16 +324,16 @@ def fex(
329
324
  Args:
330
325
  Input (list[num]): Input data.
331
326
  w (list[list[num]]): Weight matrix of the neural network.
332
- ACTION_threshold (str): Sign for threshold comparison ('<', '>', '==', '!=').
333
- action_potential (num): Threshold value for comparison.
327
+ ACTIVATION_threshold (str): Sign for threshold comparison ('<', '>', '==', '!=').
328
+ activation_potential (num): Threshold value for comparison.
334
329
 
335
330
  Returns:
336
331
  tuple: A tuple (vector) containing the neural layer result and the updated weight matrix.
337
332
  """
338
-
339
-
340
- PruneIndex = np.where(Input < action_potential)
341
- w = synaptic_pruning(w, PruneIndex, 'col', 0, 0, piece, is_training)
333
+
334
+ if is_training == 1:
335
+
336
+ w[Class,:] = Input
342
337
 
343
338
  neural_layer = np.dot(w, Input)
344
339
 
@@ -347,7 +342,6 @@ def fex(
347
342
  def cat(
348
343
  Input, # list[num]: Input data.
349
344
  w, # list[list[num]]: Weight matrix of the neural network.
350
- action_potential, # num: Threshold value for comparison.
351
345
  isTrain,
352
346
  piece # int: Flag indicating if the function is called during training (1 for training, 0 otherwise).
353
347
  ) -> tuple:
@@ -357,8 +351,8 @@ def cat(
357
351
  Args:
358
352
  Input (list[num]): Input data.
359
353
  w (list[list[num]]): Weight matrix of the neural network.
360
- ACTION_threshold (str): Sign for threshold comparison ('<', '>', '==', '!=').
361
- action_potential (num): Threshold value for comparison.
354
+ ACTIVATION_threshold (str): Sign for threshold comparison ('<', '>', '==', '!=').
355
+ activation_potential (num): Threshold value for comparison.
362
356
  isTrain (int): Flag indicating if the function is called during training (1 for training, 0 otherwise).
363
357
 
364
358
  Returns:
@@ -453,7 +447,6 @@ def Relu(
453
447
  def evaluate(
454
448
  x_test, # list[list[num]]: Test input data.
455
449
  y_test, # list[num]: Test labels.
456
- action_potential, # list[num]: List of ACTION POTENTIALS for each layer.
457
450
  visualize, # visualize Testing procces or not visualize ('y' or 'n')
458
451
  W # list[list[num]]: Weight matrix of the neural network.
459
452
  ) -> tuple:
@@ -463,7 +456,7 @@ def evaluate(
463
456
  Args:
464
457
  x_test (list[list[num]]): Test input data.
465
458
  y_test (list[num]): Test labels.
466
- action_potential (float): Input ACTION potential
459
+ activation_potential (float): Input activation potential
467
460
  visualize (str): Visualize test progress ? ('y' or 'n')
468
461
  W (list[list[num]]): Weight matrix of the neural network.
469
462
 
@@ -492,12 +485,12 @@ def evaluate(
492
485
 
493
486
  for index, Layer in enumerate(layers):
494
487
 
495
- neural_layer = normalization(neural_layer)
488
+ # neural_layer = normalization(neural_layer)
496
489
 
497
490
  if layers[index] == 'fex':
498
- neural_layer = fex(neural_layer, W[index], action_potential, 0, 0)[0]
491
+ neural_layer = fex(neural_layer, W[index], 0, 0)[0]
499
492
  if layers[index] == 'cat':
500
- neural_layer = cat(neural_layer, W[index], action_potential, 0, 0)[0]
493
+ neural_layer = cat(neural_layer, W[index], 0, 0)[0]
501
494
 
502
495
  for i, w in enumerate(Wc):
503
496
  W[i] = np.copy(w)
@@ -572,7 +565,7 @@ def evaluate(
572
565
 
573
566
  except:
574
567
 
575
- print(Fore.RED + "ERROR: Testing model parameters like 'action_potential' must be same as trained model. Check parameters. Are you sure weights are loaded ? from: evaluate" + infoTestModel + Style.RESET_ALL)
568
+ print(Fore.RED + "ERROR: Testing model parameters like 'activation_potential' must be same as trained model. Check parameters. Are you sure weights are loaded ? from: evaluate" + infoTestModel + Style.RESET_ALL)
576
569
  return 'e'
577
570
 
578
571
 
@@ -582,7 +575,6 @@ def evaluate(
582
575
  def save_model(model_name,
583
576
  model_type,
584
577
  class_count,
585
- action_potential,
586
578
  test_acc,
587
579
  weights_type,
588
580
  weights_format,
@@ -591,13 +583,13 @@ def save_model(model_name,
591
583
  ):
592
584
 
593
585
  infosave_model = """
594
- Function to save a deep learning model.
586
+ Function to save a pruning learning model.
595
587
 
596
588
  Arguments:
597
589
  model_name (str): Name of the model.
598
590
  model_type (str): Type of the model.(options: PLAN)
599
591
  class_count (int): Number of classes.
600
- action_potential (list): List containing ACTION POTENTIALS.
592
+ activation_potential (float): Activation potential.
601
593
  test_acc (float): Test accuracy of the model.
602
594
  weights_type (str): Type of weights to save (options: 'txt', 'npy', 'mat').
603
595
  WeightFormat (str): Format of the weights (options: 'd', 'f', 'raw').
@@ -641,7 +633,6 @@ def save_model(model_name,
641
633
  'LAYERS': layers,
642
634
  'LAYER COUNT': len(layers),
643
635
  'CLASS COUNT': class_count,
644
- 'ACTION POTENTIAL': action_potential,
645
636
  'NEURON COUNT': NeuronCount,
646
637
  'SYNAPSE COUNT': SynapseCount,
647
638
  'TEST ACCURACY': test_acc,
@@ -738,7 +729,7 @@ def load_model(model_name,
738
729
  model_path,
739
730
  ):
740
731
  infoload_model = """
741
- Function to load a deep learning model.
732
+ Function to load a pruning learning model.
742
733
 
743
734
  Arguments:
744
735
  model_name (str): Name of the model.
@@ -746,7 +737,7 @@ def load_model(model_name,
746
737
  log_type (str): Type of log to load (options: 'csv', 'txt', 'hdf5').
747
738
 
748
739
  Returns:
749
- lists: W(list[num]), action_potential, df (DataFrame of the model)
740
+ lists: W(list[num]), activation_potential, df (DataFrame of the model)
750
741
  """
751
742
  pass
752
743
 
@@ -766,7 +757,6 @@ def load_model(model_name,
766
757
  layers = df['LAYERS'].tolist()
767
758
  layer_count = int(df['LAYER COUNT'].iloc[0])
768
759
  class_count = int(df['CLASS COUNT'].iloc[0])
769
- action_potential = int(df['ACTION POTENTIAL'].iloc[0])
770
760
  NeuronCount = int(df['NEURON COUNT'].iloc[0])
771
761
  SynapseCount = int(df['SYNAPSE COUNT'].iloc[0])
772
762
  test_acc = int(df['TEST ACCURACY'].iloc[0])
@@ -788,13 +778,13 @@ def load_model(model_name,
788
778
  W[i] = sio.loadmat(model_path + model_name + str(i+1) + 'w.mat')
789
779
  else:
790
780
  raise ValueError(Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy' or 'mat' from: load_model." + infoload_model + Style.RESET_ALL)
791
- print(Fore.GREEN + "Model loaded succesfully" + Style.RESET_ALL)
792
- return W,action_potential,df
781
+ print(Fore.GREEN + "Model loaded succesfully" + Style.RESET_ALL)
782
+ return W,df
793
783
 
794
784
  def predict_model_ssd(Input,model_name,model_path):
795
785
 
796
786
  infopredict_model_ssd = """
797
- Function to make a prediction using a divided pruning deep learning neural network (PLAN).
787
+ Function to make a prediction using a divided pruning learning artificial neural network (PLAN).
798
788
 
799
789
  Arguments:
800
790
  Input (list or ndarray): Input data for the model (single vector or single matrix).
@@ -803,7 +793,7 @@ def predict_model_ssd(Input,model_name,model_path):
803
793
  Returns:
804
794
  ndarray: Output from the model.
805
795
  """
806
- W,action_potential = load_model(model_name,model_path)[0:2]
796
+ W = load_model(model_name,model_path)[0]
807
797
 
808
798
  layers = ['fex','cat']
809
799
 
@@ -816,12 +806,12 @@ def predict_model_ssd(Input,model_name,model_path):
816
806
  neural_layer = neural_layer.ravel()
817
807
  for index, Layer in enumerate(layers):
818
808
 
819
- neural_layer = normalization(neural_layer)
809
+ # neural_layer = normalization(neural_layer)
820
810
 
821
811
  if layers[index] == 'fex':
822
- neural_layer = fex(neural_layer, W[index], action_potential,0, 0)[0]
812
+ neural_layer = fex(neural_layer, W[index],0, 0)[0]
823
813
  if layers[index] == 'cat':
824
- neural_layer = cat(neural_layer, W[index], action_potential, 0, 0)[0]
814
+ neural_layer = cat(neural_layer, W[index], 0, 0)[0]
825
815
  except:
826
816
  print(Fore.RED + "ERROR: The input was probably entered incorrectly. from: predict_model_ssd" + infopredict_model_ssd + Style.RESET_ALL)
827
817
  return 'e'
@@ -830,15 +820,15 @@ def predict_model_ssd(Input,model_name,model_path):
830
820
  return neural_layer
831
821
 
832
822
 
833
- def predict_model_ram(Input,action_potential,W):
823
+ def predict_model_ram(Input,W):
834
824
 
835
825
  infopredict_model_ram = """
836
- Function to make a prediction using a pruning learning artificial neural network (PLAN)
826
+ Function to make a prediction using a divided pruning learning artificial neural network (PLAN).
837
827
  from weights and parameters stored in memory.
838
828
 
839
829
  Arguments:
840
830
  Input (list or ndarray): Input data for the model (single vector or single matrix).
841
- action_potential (list): ACTION POTENTIAL.
831
+ activation_potential (float): Activation potential.
842
832
  W (list of ndarrays): Weights of the model.
843
833
 
844
834
  Returns:
@@ -856,12 +846,12 @@ def predict_model_ram(Input,action_potential,W):
856
846
  neural_layer = neural_layer.ravel()
857
847
  for index, Layer in enumerate(layers):
858
848
 
859
- neural_layer = normalization(neural_layer)
849
+ # neural_layer = normalization(neural_layer)
860
850
 
861
851
  if layers[index] == 'fex':
862
- neural_layer = fex(neural_layer, W[index], action_potential,0, 0)[0]
852
+ neural_layer = fex(neural_layer, W[index],0, 0)[0]
863
853
  if layers[index] == 'cat':
864
- neural_layer = cat(neural_layer, W[index], action_potential, 0, 0)[0]
854
+ neural_layer = cat(neural_layer, W[index], 0, 0)[0]
865
855
 
866
856
  except:
867
857
  print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: predict_model_ram." + infopredict_model_ram + Style.RESET_ALL)
@@ -941,21 +931,47 @@ def synthetic_augmentation(x, y, class_count):
941
931
 
942
932
  if num_samples < max_class_count:
943
933
  while num_samples < max_class_count:
944
- # Select two random examples
934
+
945
935
  random_indices = np.random.choice(class_indices, 2, replace=False)
946
936
  sample1 = x[random_indices[0]]
947
937
  sample2 = x[random_indices[1]]
948
938
 
949
- # Generate a new synthetic example between the two selected examples
950
939
  synthetic_sample = sample1 + (np.array(sample2) - np.array(sample1)) * np.random.rand()
951
940
 
952
941
  x_balanced.append(synthetic_sample.tolist())
953
- y_balanced.append(y[class_indices[0]]) # The new example has the same class label
942
+ y_balanced.append(y[class_indices[0]])
954
943
 
955
944
  num_samples += 1
956
945
 
957
946
  return np.array(x_balanced), np.array(y_balanced)
958
947
 
948
+ def standard_scaler(x_train, x_test):
949
+ info_standard_scaler = """
950
+ Standardizes training and test datasets.
951
+
952
+ Args:
953
+ train_data: numpy.ndarray
954
+ Training data (n_samples, n_features)
955
+ test_data: numpy.ndarray
956
+ Test data (n_samples, n_features)
957
+
958
+ Returns:
959
+ tuple
960
+ Standardized training and test datasets
961
+ """
962
+ try:
963
+ mean = np.mean(x_train, axis=0)
964
+ std = np.std(x_train, axis=0)
965
+
966
+
967
+ train_data_scaled = (x_train - mean) / std
968
+ test_data_scaled = (x_test - mean) / std
969
+
970
+ except:
971
+ print(Fore.RED + "ERROR: x_train and x_test must be numpy array from standard_scaler" + info_standard_scaler)
972
+
973
+ return train_data_scaled, test_data_scaled
974
+
959
975
 
960
976
  def get_weights():
961
977
 
@@ -963,7 +979,7 @@ def get_weights():
963
979
 
964
980
  def get_df():
965
981
 
966
- return 2
982
+ return 1
967
983
 
968
984
  def get_preds():
969
985
 
@@ -975,4 +991,4 @@ def get_acc():
975
991
 
976
992
  def get_pot():
977
993
 
978
- return 1
994
+ return 1
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyerualjetwork
3
+ Version: 2.0.6
4
+ Summary: Advanced python deep learning library. New features: BINARY INJECTION (OLD) NOW ADDED NEW DIRECT FEATURE INJECTION. AND 'standard_scaler' func. Important Note: If there are any data smaller than 0 among the input data of the entry model, import plan_bi; otherwise, import plan_di. (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,7 @@
1
+ plan/__init__.py,sha256=x2SEXi2t_-OBAzOgX2v6sywjUp8Y9chprfl8KvgrU38,701
2
+ plan/plan_bi.py,sha256=RL2Yu2NN3KoXU5OEnijkSEXabo2fsJt-ZpCvV_WiHFI,33909
3
+ plan/plan_di.py,sha256=SMD9eSMnL69HFfDAaiabmNOuH8iesA1gkKVfkrz2fIA,32876
4
+ pyerualjetwork-2.0.6.dist-info/METADATA,sha256=ros5qHE_hOSma-KaWuJp2hUGqTfjasOI2VuJrFbOi_E,588
5
+ pyerualjetwork-2.0.6.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
6
+ pyerualjetwork-2.0.6.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
7
+ pyerualjetwork-2.0.6.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: pyerualjetwork
3
- Version: 2.0.4
4
- Summary: Advanced python deep learning library. New features: More simple and practical, all functions and variables are snake_case. (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=TYPKx35TBM7X814H-RQmVK9DduX5GX0JdTW7_-b2ZUc,377
2
- plan/plan.py,sha256=-41P4Rj5_-PrYWYXcaavYHlu8AninycX3FJRs33JrQQ,33028
3
- pyerualjetwork-2.0.4.dist-info/METADATA,sha256=GVCzZR_GTYxGb4TYWyFj4ff4dusUzBmtwt4ceGnyI-w,431
4
- pyerualjetwork-2.0.4.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
- pyerualjetwork-2.0.4.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
- pyerualjetwork-2.0.4.dist-info/RECORD,,