pyerualjetwork 2.2.7__py3-none-any.whl → 2.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_bi/__init__.py +1 -1
- plan_bi/plan_bi.py +137 -25
- plan_di/__init__.py +1 -1
- plan_di/plan_di.py +140 -26
- {pyerualjetwork-2.2.7.dist-info → pyerualjetwork-2.2.9.dist-info}/METADATA +2 -2
- pyerualjetwork-2.2.9.dist-info/RECORD +8 -0
- pyerualjetwork-2.2.7.dist-info/RECORD +0 -8
- {pyerualjetwork-2.2.7.dist-info → pyerualjetwork-2.2.9.dist-info}/WHEEL +0 -0
- {pyerualjetwork-2.2.7.dist-info → pyerualjetwork-2.2.9.dist-info}/top_level.txt +0 -0
plan_bi/__init__.py
CHANGED
@@ -2,4 +2,4 @@
|
|
2
2
|
|
3
3
|
# Bu dosya, plan modülünün ana giriş noktasıdır.
|
4
4
|
|
5
|
-
from .plan_bi import auto_balancer, normalization, Softmax, Sigmoid, Relu, weight_identification, fex, fit, evaluate, save_model, load_model, predict_model_ssd, predict_model_ram, get_weights, get_df, get_preds, get_acc, get_pot, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate
|
5
|
+
from .plan_bi import auto_balancer, normalization, Softmax, Sigmoid, Relu, weight_identification, fex, fit, evaluate, save_model, load_model, predict_model_ssd, predict_model_ram, get_weights, get_df, get_preds, get_acc, get_pot, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate, manuel_balancer
|
plan_bi/plan_bi.py
CHANGED
@@ -52,7 +52,7 @@ def fit(
|
|
52
52
|
y_train = [tuple(sublist) for sublist in y_train]
|
53
53
|
|
54
54
|
neurons = [len(class_count),len(class_count)]
|
55
|
-
layers = ['fex'
|
55
|
+
layers = ['fex']
|
56
56
|
|
57
57
|
x_train[0] = np.array(x_train[0])
|
58
58
|
x_train[0] = x_train[0].ravel()
|
@@ -123,8 +123,17 @@ def fit(
|
|
123
123
|
print('Total training time(h): ',calculating_est/3600)
|
124
124
|
|
125
125
|
|
126
|
+
layers.append('cat')
|
127
|
+
trained_W.append(np.eye(len(class_count)))
|
126
128
|
|
129
|
+
for i in range(len(class_count)):
|
127
130
|
|
131
|
+
for j in range(len(layers)):
|
132
|
+
|
133
|
+
if layers[j] == 'fex':
|
134
|
+
|
135
|
+
trained_W[j][i,:] = normalization(trained_W[j][i,:])
|
136
|
+
|
128
137
|
return trained_W
|
129
138
|
|
130
139
|
# FUNCTIONS -----
|
@@ -155,8 +164,6 @@ def weight_identification(
|
|
155
164
|
ws = layer_count - 1
|
156
165
|
for w in range(ws):
|
157
166
|
W[w + 1] = np.ones((neurons[w + 1],neurons[w]))
|
158
|
-
W[layer_count] = np.ones((class_count,neurons[layer_count - 1]))
|
159
|
-
W[len(W) - 1] = np.eye(class_count)
|
160
167
|
|
161
168
|
return W
|
162
169
|
|
@@ -529,7 +536,7 @@ def save_model(model_name,
|
|
529
536
|
weights_type,
|
530
537
|
weights_format,
|
531
538
|
model_path,
|
532
|
-
|
539
|
+
scaler_params,
|
533
540
|
W
|
534
541
|
):
|
535
542
|
|
@@ -545,7 +552,7 @@ def save_model(model_name,
|
|
545
552
|
weights_type (str): Type of weights to save (options: 'txt', 'npy', 'mat').
|
546
553
|
WeightFormat (str): Format of the weights (options: 'd', 'f', 'raw').
|
547
554
|
model_path (str): Path where the model will be saved. For example: C:/Users/beydili/Desktop/denemePLAN/
|
548
|
-
|
555
|
+
scaler_params (int, float): standard scaler params list: mean,std. If not used standard scaler then be: None.
|
549
556
|
W: Weights list of the model.
|
550
557
|
|
551
558
|
Returns:
|
@@ -593,7 +600,7 @@ def save_model(model_name,
|
|
593
600
|
'WEIGHTS TYPE': weights_type,
|
594
601
|
'WEIGHTS FORMAT': weights_format,
|
595
602
|
'MODEL PATH': model_path,
|
596
|
-
'STANDARD SCALER':
|
603
|
+
'STANDARD SCALER': scaler_params
|
597
604
|
}
|
598
605
|
try:
|
599
606
|
|
@@ -743,11 +750,11 @@ def predict_model_ssd(Input, model_name, model_path):
|
|
743
750
|
"""
|
744
751
|
W, activation_potential, df = load_model(model_name,model_path)
|
745
752
|
|
746
|
-
|
753
|
+
scaler_params = str(df['STANDARD SCALER'].iloc[0])
|
747
754
|
|
748
|
-
if
|
755
|
+
if scaler_params != None:
|
749
756
|
|
750
|
-
Input = standard_scaler(Input, None)
|
757
|
+
Input = standard_scaler(scaler_params, Input, None)
|
751
758
|
|
752
759
|
layers = ['fex','cat']
|
753
760
|
|
@@ -774,7 +781,7 @@ def predict_model_ssd(Input, model_name, model_path):
|
|
774
781
|
return neural_layer
|
775
782
|
|
776
783
|
|
777
|
-
def predict_model_ram(Input, activation_potential,
|
784
|
+
def predict_model_ram(Input, activation_potential, scaler_params, W):
|
778
785
|
|
779
786
|
infopredict_model_ram = """
|
780
787
|
Function to make a prediction using a divided pruning learning artificial neural network (PLAN).
|
@@ -783,15 +790,15 @@ def predict_model_ram(Input, activation_potential, scaler, W):
|
|
783
790
|
Arguments:
|
784
791
|
Input (list or ndarray): Input data for the model (single vector or single matrix).
|
785
792
|
activation_potential (float): Activation potential.
|
786
|
-
|
793
|
+
scaler_params (int, float): standard scaler params list: mean,std. If not used standard scaler then be: None.
|
787
794
|
W (list of ndarrays): Weights of the model.
|
788
795
|
|
789
796
|
Returns:
|
790
797
|
ndarray: Output from the model.
|
791
798
|
"""
|
792
|
-
if
|
799
|
+
if scaler_params != None:
|
793
800
|
|
794
|
-
Input = standard_scaler(Input, None)
|
801
|
+
Input = standard_scaler(scaler_params, Input, None)
|
795
802
|
|
796
803
|
layers = ['fex','cat']
|
797
804
|
|
@@ -918,7 +925,7 @@ def synthetic_augmentation(x_train, y_train):
|
|
918
925
|
return np.array(x_balanced), np.array(y_balanced)
|
919
926
|
|
920
927
|
|
921
|
-
|
928
|
+
defdef standard_scaler(scaler_params=None, x_train, x_test):
|
922
929
|
info_standard_scaler = """
|
923
930
|
Standardizes training and test datasets. x_test may be None.
|
924
931
|
|
@@ -929,23 +936,31 @@ def standard_scaler(x_train, x_test):
|
|
929
936
|
Test data
|
930
937
|
|
931
938
|
Returns:
|
939
|
+
list:
|
940
|
+
Scaler parameters: mean and std
|
932
941
|
tuple
|
933
942
|
Standardized training and test datasets
|
934
943
|
"""
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
944
|
+
try:
|
945
|
+
|
946
|
+
if scaler_params == None:
|
947
|
+
mean = np.mean(x_train, axis=0)
|
948
|
+
std = np.std(x_train, axis=0)
|
949
|
+
scaler_params = [mean, std]
|
939
950
|
|
940
|
-
|
951
|
+
if x_test == None:
|
941
952
|
|
942
|
-
|
943
|
-
|
953
|
+
train_data_scaled = (x_train - mean) / std
|
954
|
+
return scaler_params, train_data_scaled
|
944
955
|
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
956
|
+
elif scaler_params == None:
|
957
|
+
train_data_scaled = (x_train - mean) / std
|
958
|
+
test_data_scaled = (x_test - mean) / std
|
959
|
+
return scaler_params, train_data_scaled, test_data_scaled
|
960
|
+
|
961
|
+
elif scaler_params != None:
|
962
|
+
test_data_scaled = (x_test - scaler_params[0]) / scaler_params[1]
|
963
|
+
return test_data_scaled
|
949
964
|
|
950
965
|
except:
|
951
966
|
print(
|
@@ -1325,6 +1340,103 @@ def plot_evaluate(y_test, y_preds, acc_list):
|
|
1325
1340
|
plt.tight_layout()
|
1326
1341
|
plt.show()
|
1327
1342
|
|
1343
|
+
|
1344
|
+
def manuel_balancer(x_train, y_train, target_samples_per_class):
|
1345
|
+
"""
|
1346
|
+
Generates synthetic examples to balance classes to the specified number of examples per class.
|
1347
|
+
|
1348
|
+
Arguments:
|
1349
|
+
x_train -- Input dataset (examples) - NumPy array format
|
1350
|
+
y_train -- Class labels (one-hot encoded) - NumPy array format
|
1351
|
+
target_samples_per_class -- Desired number of samples per class
|
1352
|
+
|
1353
|
+
Returns:
|
1354
|
+
x_balanced -- Balanced input dataset (NumPy array format)
|
1355
|
+
y_balanced -- Balanced class labels (one-hot encoded, NumPy array format)
|
1356
|
+
"""
|
1357
|
+
start_time = time.time()
|
1358
|
+
x_train = np.array(x_train)
|
1359
|
+
y_train = np.array(y_train)
|
1360
|
+
classes = np.arange(y_train.shape[1])
|
1361
|
+
class_count = len(classes)
|
1362
|
+
|
1363
|
+
x_balanced = []
|
1364
|
+
y_balanced = []
|
1365
|
+
|
1366
|
+
for class_label in range(class_count):
|
1367
|
+
class_indices = np.where(np.argmax(y_train, axis=1) == class_label)[0]
|
1368
|
+
num_samples = len(class_indices)
|
1369
|
+
|
1370
|
+
if num_samples > target_samples_per_class:
|
1371
|
+
|
1372
|
+
selected_indices = np.random.choice(class_indices, target_samples_per_class, replace=False)
|
1373
|
+
x_balanced.append(x_train[selected_indices])
|
1374
|
+
y_balanced.append(y_train[selected_indices])
|
1375
|
+
|
1376
|
+
else:
|
1377
|
+
|
1378
|
+
x_balanced.append(x_train[class_indices])
|
1379
|
+
y_balanced.append(y_train[class_indices])
|
1380
|
+
|
1381
|
+
if num_samples < target_samples_per_class:
|
1382
|
+
|
1383
|
+
samples_to_add = target_samples_per_class - num_samples
|
1384
|
+
additional_samples = np.zeros((samples_to_add, x_train.shape[1]))
|
1385
|
+
additional_labels = np.zeros((samples_to_add, y_train.shape[1]))
|
1386
|
+
|
1387
|
+
for i in range(samples_to_add):
|
1388
|
+
uni_start_time = time.time()
|
1389
|
+
|
1390
|
+
random_indices = np.random.choice(class_indices, 2, replace=False)
|
1391
|
+
sample1 = x_train[random_indices[0]]
|
1392
|
+
sample2 = x_train[random_indices[1]]
|
1393
|
+
|
1394
|
+
|
1395
|
+
synthetic_sample = sample1 + (sample2 - sample1) * np.random.rand()
|
1396
|
+
|
1397
|
+
additional_samples[i] = synthetic_sample
|
1398
|
+
additional_labels[i] = y_train[class_indices[0]]
|
1399
|
+
|
1400
|
+
uni_end_time = time.time()
|
1401
|
+
calculating_est = round(
|
1402
|
+
(uni_end_time - uni_start_time) * (samples_to_add - i), 3)
|
1403
|
+
|
1404
|
+
if calculating_est < 60:
|
1405
|
+
print('\rest......(sec):', calculating_est, '\n', end="")
|
1406
|
+
|
1407
|
+
elif calculating_est > 60 and calculating_est < 3600:
|
1408
|
+
print('\rest......(min):', calculating_est/60, '\n', end="")
|
1409
|
+
|
1410
|
+
elif calculating_est > 3600:
|
1411
|
+
print('\rest......(h):', calculating_est/3600, '\n', end="")
|
1412
|
+
|
1413
|
+
print('Augmenting: ', class_label, '/', class_count, '...', i, "/", samples_to_add, "\n", end="")
|
1414
|
+
|
1415
|
+
x_balanced.append(additional_samples)
|
1416
|
+
y_balanced.append(additional_labels)
|
1417
|
+
|
1418
|
+
|
1419
|
+
EndTime = time.time()
|
1420
|
+
|
1421
|
+
calculating_est = round(EndTime - start_time, 2)
|
1422
|
+
|
1423
|
+
print(Fore.GREEN + " \nBalancing Finished with 0 ERROR\n" + Style.RESET_ALL)
|
1424
|
+
|
1425
|
+
if calculating_est < 60:
|
1426
|
+
print('Total balancing time(sec): ', calculating_est)
|
1427
|
+
|
1428
|
+
elif calculating_est > 60 and calculating_est < 3600:
|
1429
|
+
print('Total balancing time(min): ', calculating_est/60)
|
1430
|
+
|
1431
|
+
elif calculating_est > 3600:
|
1432
|
+
print('Total balancing time(h): ', calculating_est/3600)
|
1433
|
+
|
1434
|
+
# Stack the balanced arrays
|
1435
|
+
x_balanced = np.vstack(x_balanced)
|
1436
|
+
y_balanced = np.vstack(y_balanced)
|
1437
|
+
|
1438
|
+
return x_balanced, y_balanced
|
1439
|
+
|
1328
1440
|
def get_weights():
|
1329
1441
|
|
1330
1442
|
return 0
|
plan_di/__init__.py
CHANGED
@@ -2,4 +2,4 @@
|
|
2
2
|
|
3
3
|
# Bu dosya, plan modülünün ana giriş noktasıdır.
|
4
4
|
|
5
|
-
from .plan_di import auto_balancer, normalization, Softmax, Sigmoid, Relu, weight_identification, fex, fit, evaluate, save_model, load_model, predict_model_ssd, predict_model_ram, get_weights, get_df, get_preds, get_acc, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate
|
5
|
+
from .plan_di import auto_balancer, normalization, Softmax, Sigmoid, Relu, weight_identification, fex, fit, evaluate, save_model, load_model, predict_model_ssd, predict_model_ram, get_weights, get_df, get_preds, get_acc, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate, manuel_balancer
|
plan_di/plan_di.py
CHANGED
@@ -51,7 +51,7 @@ def fit(
|
|
51
51
|
y_train = [tuple(sublist) for sublist in y_train]
|
52
52
|
|
53
53
|
neurons = [len(class_count), len(class_count)]
|
54
|
-
layers = ['fex'
|
54
|
+
layers = ['fex']
|
55
55
|
|
56
56
|
x_train[0] = np.array(x_train[0])
|
57
57
|
x_train[0] = x_train[0].ravel()
|
@@ -120,6 +120,18 @@ def fit(
|
|
120
120
|
elif calculating_est > 3600:
|
121
121
|
print('Total training time(h): ', calculating_est/3600)
|
122
122
|
|
123
|
+
layers.append('cat')
|
124
|
+
trained_W.append(np.eye(len(class_count)))
|
125
|
+
|
126
|
+
for i in range(len(class_count)):
|
127
|
+
|
128
|
+
for j in range(len(layers)):
|
129
|
+
|
130
|
+
if layers[j] == 'fex':
|
131
|
+
|
132
|
+
trained_W[j][i,:] = normalization(trained_W[j][i,:])
|
133
|
+
|
134
|
+
|
123
135
|
return trained_W
|
124
136
|
|
125
137
|
# FUNCTIONS -----
|
@@ -150,9 +162,7 @@ def weight_identification(
|
|
150
162
|
ws = layer_count - 1
|
151
163
|
for w in range(ws):
|
152
164
|
W[w + 1] = np.ones((neurons[w + 1], neurons[w]))
|
153
|
-
|
154
|
-
W[len(W) - 1] = np.eye(class_count)
|
155
|
-
|
165
|
+
|
156
166
|
return W
|
157
167
|
|
158
168
|
|
@@ -507,7 +517,7 @@ def save_model(model_name,
|
|
507
517
|
weights_type,
|
508
518
|
weights_format,
|
509
519
|
model_path,
|
510
|
-
|
520
|
+
scaler_params,
|
511
521
|
W
|
512
522
|
):
|
513
523
|
|
@@ -522,7 +532,7 @@ def save_model(model_name,
|
|
522
532
|
weights_type (str): Type of weights to save (options: 'txt', 'npy', 'mat').
|
523
533
|
WeightFormat (str): Format of the weights (options: 'd', 'f', 'raw').
|
524
534
|
model_path (str): Path where the model will be saved. For example: C:/Users/beydili/Desktop/denemePLAN/
|
525
|
-
|
535
|
+
scaler_params (int, float): standard scaler params list: mean,std. If not used standard scaler then be: None.
|
526
536
|
W: Weights of the model.
|
527
537
|
|
528
538
|
Returns:
|
@@ -572,7 +582,7 @@ def save_model(model_name,
|
|
572
582
|
'WEIGHTS TYPE': weights_type,
|
573
583
|
'WEIGHTS FORMAT': weights_format,
|
574
584
|
'MODEL PATH': model_path,
|
575
|
-
'STANDARD SCALER':
|
585
|
+
'STANDARD SCALER': scaler_params
|
576
586
|
}
|
577
587
|
try:
|
578
588
|
|
@@ -719,11 +729,11 @@ def predict_model_ssd(Input, model_name, model_path):
|
|
719
729
|
"""
|
720
730
|
W, df = load_model(model_name, model_path)
|
721
731
|
|
722
|
-
|
732
|
+
scaler_params = str(df['STANDARD SCALER'].iloc[0])
|
723
733
|
|
724
|
-
if
|
734
|
+
if scaler_params != None:
|
725
735
|
|
726
|
-
Input = standard_scaler(Input, None)
|
736
|
+
Input = standard_scaler(scaler_params, Input, None)
|
727
737
|
|
728
738
|
layers = ['fex', 'cat']
|
729
739
|
|
@@ -751,7 +761,7 @@ def predict_model_ssd(Input, model_name, model_path):
|
|
751
761
|
return neural_layer
|
752
762
|
|
753
763
|
|
754
|
-
def predict_model_ram(Input,
|
764
|
+
def predict_model_ram(Input, scaler_params, W):
|
755
765
|
|
756
766
|
infopredict_model_ram = """
|
757
767
|
Function to make a prediction using a divided pruning learning artificial neural network (PLAN).
|
@@ -759,16 +769,16 @@ def predict_model_ram(Input, scaler, W):
|
|
759
769
|
|
760
770
|
Arguments:
|
761
771
|
Input (list or ndarray): Input data for the model (single vector or single matrix).
|
762
|
-
|
772
|
+
scaler_params (int, float): standard scaler params list: mean,std. If not used standard scaler then be: None.
|
763
773
|
W (list of ndarrays): Weights of the model.
|
764
774
|
|
765
775
|
Returns:
|
766
776
|
ndarray: Output from the model.
|
767
777
|
"""
|
768
778
|
|
769
|
-
if
|
779
|
+
if scaler_params != None:
|
770
780
|
|
771
|
-
Input = standard_scaler(Input, None)
|
781
|
+
Input = standard_scaler(scaler_params, Input, None)
|
772
782
|
|
773
783
|
layers = ['fex', 'cat']
|
774
784
|
|
@@ -895,7 +905,7 @@ def synthetic_augmentation(x_train, y_train):
|
|
895
905
|
return np.array(x_balanced), np.array(y_balanced)
|
896
906
|
|
897
907
|
|
898
|
-
def standard_scaler(x_train, x_test):
|
908
|
+
def standard_scaler(scaler_params=None, x_train, x_test):
|
899
909
|
info_standard_scaler = """
|
900
910
|
Standardizes training and test datasets. x_test may be None.
|
901
911
|
|
@@ -906,23 +916,31 @@ def standard_scaler(x_train, x_test):
|
|
906
916
|
Test data
|
907
917
|
|
908
918
|
Returns:
|
919
|
+
list:
|
920
|
+
Scaler parameters: mean and std
|
909
921
|
tuple
|
910
922
|
Standardized training and test datasets
|
911
923
|
"""
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
924
|
+
try:
|
925
|
+
|
926
|
+
if scaler_params == None:
|
927
|
+
mean = np.mean(x_train, axis=0)
|
928
|
+
std = np.std(x_train, axis=0)
|
929
|
+
scaler_params = [mean, std]
|
916
930
|
|
917
|
-
|
931
|
+
if x_test == None:
|
918
932
|
|
919
|
-
|
920
|
-
|
933
|
+
train_data_scaled = (x_train - mean) / std
|
934
|
+
return scaler_params, train_data_scaled
|
921
935
|
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
936
|
+
elif scaler_params == None:
|
937
|
+
train_data_scaled = (x_train - mean) / std
|
938
|
+
test_data_scaled = (x_test - mean) / std
|
939
|
+
return scaler_params, train_data_scaled, test_data_scaled
|
940
|
+
|
941
|
+
elif scaler_params != None:
|
942
|
+
test_data_scaled = (x_test - scaler_params[0]) / scaler_params[1]
|
943
|
+
return test_data_scaled
|
926
944
|
|
927
945
|
except:
|
928
946
|
print(
|
@@ -1295,6 +1313,102 @@ def plot_evaluate(y_test, y_preds, acc_list):
|
|
1295
1313
|
plt.tight_layout()
|
1296
1314
|
plt.show()
|
1297
1315
|
|
1316
|
+
def manuel_balancer(x_train, y_train, target_samples_per_class):
|
1317
|
+
"""
|
1318
|
+
Generates synthetic examples to balance classes to the specified number of examples per class.
|
1319
|
+
|
1320
|
+
Arguments:
|
1321
|
+
x_train -- Input dataset (examples) - NumPy array format
|
1322
|
+
y_train -- Class labels (one-hot encoded) - NumPy array format
|
1323
|
+
target_samples_per_class -- Desired number of samples per class
|
1324
|
+
|
1325
|
+
Returns:
|
1326
|
+
x_balanced -- Balanced input dataset (NumPy array format)
|
1327
|
+
y_balanced -- Balanced class labels (one-hot encoded, NumPy array format)
|
1328
|
+
"""
|
1329
|
+
start_time = time.time()
|
1330
|
+
x_train = np.array(x_train)
|
1331
|
+
y_train = np.array(y_train)
|
1332
|
+
classes = np.arange(y_train.shape[1])
|
1333
|
+
class_count = len(classes)
|
1334
|
+
|
1335
|
+
x_balanced = []
|
1336
|
+
y_balanced = []
|
1337
|
+
|
1338
|
+
for class_label in range(class_count):
|
1339
|
+
class_indices = np.where(np.argmax(y_train, axis=1) == class_label)[0]
|
1340
|
+
num_samples = len(class_indices)
|
1341
|
+
|
1342
|
+
if num_samples > target_samples_per_class:
|
1343
|
+
|
1344
|
+
selected_indices = np.random.choice(class_indices, target_samples_per_class, replace=False)
|
1345
|
+
x_balanced.append(x_train[selected_indices])
|
1346
|
+
y_balanced.append(y_train[selected_indices])
|
1347
|
+
|
1348
|
+
else:
|
1349
|
+
|
1350
|
+
x_balanced.append(x_train[class_indices])
|
1351
|
+
y_balanced.append(y_train[class_indices])
|
1352
|
+
|
1353
|
+
if num_samples < target_samples_per_class:
|
1354
|
+
|
1355
|
+
samples_to_add = target_samples_per_class - num_samples
|
1356
|
+
additional_samples = np.zeros((samples_to_add, x_train.shape[1]))
|
1357
|
+
additional_labels = np.zeros((samples_to_add, y_train.shape[1]))
|
1358
|
+
|
1359
|
+
for i in range(samples_to_add):
|
1360
|
+
uni_start_time = time.time()
|
1361
|
+
|
1362
|
+
random_indices = np.random.choice(class_indices, 2, replace=False)
|
1363
|
+
sample1 = x_train[random_indices[0]]
|
1364
|
+
sample2 = x_train[random_indices[1]]
|
1365
|
+
|
1366
|
+
|
1367
|
+
synthetic_sample = sample1 + (sample2 - sample1) * np.random.rand()
|
1368
|
+
|
1369
|
+
additional_samples[i] = synthetic_sample
|
1370
|
+
additional_labels[i] = y_train[class_indices[0]]
|
1371
|
+
|
1372
|
+
uni_end_time = time.time()
|
1373
|
+
calculating_est = round(
|
1374
|
+
(uni_end_time - uni_start_time) * (samples_to_add - i), 3)
|
1375
|
+
|
1376
|
+
if calculating_est < 60:
|
1377
|
+
print('\rest......(sec):', calculating_est, '\n', end="")
|
1378
|
+
|
1379
|
+
elif calculating_est > 60 and calculating_est < 3600:
|
1380
|
+
print('\rest......(min):', calculating_est/60, '\n', end="")
|
1381
|
+
|
1382
|
+
elif calculating_est > 3600:
|
1383
|
+
print('\rest......(h):', calculating_est/3600, '\n', end="")
|
1384
|
+
|
1385
|
+
print('Augmenting: ', class_label, '/', class_count, '...', i, "/", samples_to_add, "\n", end="")
|
1386
|
+
|
1387
|
+
x_balanced.append(additional_samples)
|
1388
|
+
y_balanced.append(additional_labels)
|
1389
|
+
|
1390
|
+
|
1391
|
+
EndTime = time.time()
|
1392
|
+
|
1393
|
+
calculating_est = round(EndTime - start_time, 2)
|
1394
|
+
|
1395
|
+
print(Fore.GREEN + " \nBalancing Finished with 0 ERROR\n" + Style.RESET_ALL)
|
1396
|
+
|
1397
|
+
if calculating_est < 60:
|
1398
|
+
print('Total balancing time(sec): ', calculating_est)
|
1399
|
+
|
1400
|
+
elif calculating_est > 60 and calculating_est < 3600:
|
1401
|
+
print('Total balancing time(min): ', calculating_est/60)
|
1402
|
+
|
1403
|
+
elif calculating_est > 3600:
|
1404
|
+
print('Total balancing time(h): ', calculating_est/3600)
|
1405
|
+
|
1406
|
+
# Stack the balanced arrays
|
1407
|
+
x_balanced = np.vstack(x_balanced)
|
1408
|
+
y_balanced = np.vstack(y_balanced)
|
1409
|
+
|
1410
|
+
return x_balanced, y_balanced
|
1411
|
+
|
1298
1412
|
def get_weights():
|
1299
1413
|
|
1300
1414
|
return 0
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pyerualjetwork
|
3
|
-
Version: 2.2.
|
4
|
-
Summary:
|
3
|
+
Version: 2.2.9
|
4
|
+
Summary: Weights now noramlized, new function: manuel_balancer. And scaler_params added for scaled models.
|
5
5
|
Author: Hasan Can Beydili
|
6
6
|
Author-email: tchasancan@gmail.com
|
7
7
|
Keywords: model evaluation,classifcation,pruning learning artficial neural networks
|
@@ -0,0 +1,8 @@
|
|
1
|
+
plan_bi/__init__.py,sha256=m84PX8yNU6pVlQNyWOqamkQdx_-_aPFsfvtwEnC8U_w,492
|
2
|
+
plan_bi/plan_bi.py,sha256=ehSRrQ7_5YRKEVrHNazP8CPZSlJWVxB-lDZUTPO_Q7g,50053
|
3
|
+
plan_di/__init__.py,sha256=cp43HHfPlIYVGFULVoiEwjFE8paMHCAgYLSic355gqs,483
|
4
|
+
plan_di/plan_di.py,sha256=5IBktVVqKENjDm2gi8ykNOaWfxspoJuG_36FrB0m07k,47444
|
5
|
+
pyerualjetwork-2.2.9.dist-info/METADATA,sha256=w1H4NKan5q2vMU7TjOyDVGnMqWHKf3kDFYpQiPMZPf8,319
|
6
|
+
pyerualjetwork-2.2.9.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
7
|
+
pyerualjetwork-2.2.9.dist-info/top_level.txt,sha256=aaXSOcnD62fbXG1x7tw4nV50Qxx9g9zDNLK7OD4BdPE,16
|
8
|
+
pyerualjetwork-2.2.9.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
plan_bi/__init__.py,sha256=rzDe7yWvNlwDVE6xSw8Qk51itcxT6EDBj7iiOeycxMw,475
|
2
|
-
plan_bi/plan_bi.py,sha256=ZK2rwYVgYxHygwmgUvb8G1cQ8AHPRm6e2yVHgb9X5Eo,45416
|
3
|
-
plan_di/__init__.py,sha256=Omxc07PXPQZOrXBD3PJQT6sPdni6NMykyiQgKVL_IZ0,466
|
4
|
-
plan_di/plan_di.py,sha256=nWUc3D9yTDQ6V1TQAGH4Q9F4yKJIndKYGGQPqtysNOU,42786
|
5
|
-
pyerualjetwork-2.2.7.dist-info/METADATA,sha256=_XpAwKRGokLPyY5Z5wW3pXLUF9nKFgWDaw510HVKa6E,325
|
6
|
-
pyerualjetwork-2.2.7.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
7
|
-
pyerualjetwork-2.2.7.dist-info/top_level.txt,sha256=aaXSOcnD62fbXG1x7tw4nV50Qxx9g9zDNLK7OD4BdPE,16
|
8
|
-
pyerualjetwork-2.2.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|