-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_autoencoder.py
693 lines (608 loc) · 24.7 KB
/
script_autoencoder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
# -*- coding: utf-8 -*-
"""
Note from CyprienGille : This code is an amalgamation of the work of several people, and needs a complete overhaul
for better factorization and readability. I will delete this comment when this is done.
Copyright I3S CNRS UCA
This code is an implementation of the statistical evaluation of the autoencoder described in the article :
Learning a confidence score and the latent space of a new Supervised Autoencoder for diagnosis and prognosis in clinical metabolomic studies.
When using this code , please cite
Barlaud, Michel and Guyard, Frederic
Learning sparse deep neural networks using efficient structured projections on convex constraints for green ai. ICPR 2020 Milan Italy (2020)
@INPROCEEDINGS{9412162,
author={Barlaud, Michel and Guyard, Frédéric},
booktitle={2020 25th International Conference on Pattern Recognition (ICPR)},
title={Learning sparse deep neural networks using efficient structured projections on convex constraints for green AI},
year={2021},
volume={},
number={},
pages={1566-1573},
doi={10.1109/ICPR48806.2021.9412162}}
and
David Chardin, Cyprien Gille, Thierry Pourcher and Michel Barlaud :
Learning a confidence score and the latent space of a new Supervised Autoencoder for diagnosis and prognosis in clinical metabolomic studies.
Parameters :
- Seed
- Database (variable file_name)
- Projection
- Constraint ETA
Results_stat
-Accuracy, F1 score (+other metrics)
-Predicted labels on test set with confidence scores
-Top features
"""
#%%
import os
import time
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns
import torch
from torch import nn
from sklearn import metrics
from sklearn.metrics import precision_recall_fscore_support
import functions.functions_torch as ft
import functions.functions_network_pytorch as fnp
#%%
if __name__ == "__main__":
######## Parameters ########
# Set seed
SEEDS = [4, 5, 6]
# Set device (GPU or CPU)
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
nfolds = 4 # Number of folds for the cross-validation process
N_EPOCHS = 30 # Number of epochs for the first descent
N_EPOCHS_MASKGRAD = 30 # Number of epochs for training masked gradient
LR = 0.0005 # Learning rate
BATCH_SIZE = 8 # Optimize the trade off between accuracy and computational time
LOSS_LAMBDA = 0.001 # Total loss = λ * loss_reconstruction + loss_classification
# unit scaling of the input data
doScale = True
# log transform of the input data
doLog = True
# loss function for reconstruction
criterion_reconstruction = nn.SmoothL1Loss(reduction="sum") # SmoothL1Loss
# Classification
# Weights for each class
# (see https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html#torch.nn.CrossEntropyLoss for more details)
class_weights = [1.0, 1.0]
# Loss function
criterion_classification = nn.CrossEntropyLoss(
reduction="sum", weight=torch.Tensor(class_weights).to(DEVICE)
)
## Dataset choice
# file_name = "LUNG.csv"
# file_name = "BRAIN_MID.csv"
# file_name = "GC_Breast_D_MB.csv"
file_name = "Th12F_meanFill.csv"
## Choose Architecture
# net_name = 'LeNet'
net_name = "netBio"
n_hidden = 96 # amount of neurons on netbio's hidden layer
# Do pca or t-SNE
Do_pca = True
Do_tSNE = True
run_model = "No_proj" # default model run
# Do projection at the middle layer or not
DO_PROJ_MIDDLE = False
# Do projection on the decoder part or not
DO_PROJ_DECODER = False
ETA = 100 # Controls feature selection (projection) (L1, L11, L21)
RHO = 0.6 # Controls feature selection for l1inf
GRADIENT_MASK = True # Whether to do a second descent
if GRADIENT_MASK:
run_model = "ProjectionLastEpoch"
## Choose projection function
if not GRADIENT_MASK:
TYPE_PROJ = "No_proj"
TYPE_PROJ_NAME = "No_proj"
else:
# TYPE_PROJ = ft.proj_l1ball # projection l1
TYPE_PROJ = ft.proj_l11ball # original projection l11 (col-wise zeros)
# TYPE_PROJ = ft.proj_l21ball # projection l21
# TYPE_PROJ = ft.proj_l1infball # projection l1,inf
TYPE_PROJ_NAME = TYPE_PROJ.__name__
AXIS = 1 # 1 for columns (features), 0 for rows (neurons)
TOL = 1e-3 # error margin for the L1inf algorithm and gradient masking
bW = 0.5 # Kernel size for distribution plots
DoTopGenes = True # Compute feature rankings
# Save Results or not
SAVE_FILE = True
######## Main routine ########
# Output Path
outputPath = (
"results_stat"
+ ((not DO_PROJ_DECODER) * "_halfproj")
+ "/"
+ file_name.split(".")[0]
+ "/"
)
if not os.path.exists(outputPath): # make the directory if it does not exist
os.makedirs(outputPath)
# Load data
X, Y, feature_names, label_name, patient_name = ft.ReadData(
file_name, doScale=doScale, doLog=doLog
)
feature_len = len(feature_names)
class_len = len(label_name)
print(f"Number of features: {feature_len}, Number of classes: {class_len}")
# matrices to store accuracies
accuracy_train = np.zeros((nfolds * len(SEEDS), class_len + 1))
accuracy_test = np.zeros((nfolds * len(SEEDS), class_len + 1))
# matrices to store metrics
data_train = np.zeros((nfolds * len(SEEDS), 7))
data_test = np.zeros((nfolds * len(SEEDS), 7))
correct_prediction = []
seed_idx = 0
for seed in SEEDS:
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
for fold_idx in range(nfolds):
train_dl, test_dl, train_len, test_len, Ytest = ft.CrossVal(
X, Y, patient_name, BATCH_SIZE, fold_idx, seed
)
print(
"Len of train set: {}, Len of test set:: {}".format(train_len, test_len)
)
print("----------- Start fold ", fold_idx, "----------------")
# Define the SEED to fix the initial parameters
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
# run AutoEncoder
if net_name == "LeNet":
net = ft.LeNet_300_100(n_inputs=feature_len, n_outputs=class_len).to(
DEVICE
) # LeNet
if net_name == "netBio":
net = ft.netBio(feature_len, class_len, n_hidden).to(DEVICE) # netBio
weights_entry, spasity_w_entry = fnp.weights_and_sparsity(net)
if GRADIENT_MASK:
run_model = "ProjectionLastEpoch"
if TYPE_PROJ == ft.proj_l1infball:
ETA = RHO
optimizer = torch.optim.Adam(net.parameters(), lr=LR)
lr_scheduler = torch.optim.lr_scheduler.StepLR(
optimizer, step_size=150, gamma=0.1
)
data_encoder, data_decoded, epoch_loss, best_test, net = ft.RunAutoEncoder(
net,
criterion_reconstruction,
criterion_classification,
train_dl,
train_len,
test_dl,
test_len,
optimizer,
outputPath,
TYPE_PROJ,
LOSS_LAMBDA,
lr_scheduler,
N_EPOCHS,
run_model,
DO_PROJ_MIDDLE,
DO_PROJ_DECODER,
ETA,
AXIS=AXIS,
TOL=TOL,
)
labelpredict = data_encoder[:, :-1].max(1)[1].cpu().numpy()
# Do masked gradient
if GRADIENT_MASK:
print("\n--------Running with masked gradient-----")
print("-----------------------")
prev_data = [param.data for param in list(net.parameters())]
# Get initial network and set zeros
# Recall the SEED to get the initial parameters
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
# run AutoEncoder
if net_name == "LeNet":
net = ft.LeNet_300_100(
n_inputs=feature_len, n_outputs=class_len
).to(
DEVICE
) # LeNet
if net_name == "netBio":
net = ft.netBio(feature_len, class_len, n_hidden).to(
DEVICE
) # netBio
optimizer = torch.optim.Adam(net.parameters(), lr=LR)
lr_scheduler = torch.optim.lr_scheduler.StepLR(
optimizer, 150, gamma=0.1
) # unused in the paper
net_parameters = list(net.parameters())
for index, param in enumerate(net_parameters):
is_middle = index == (len(net_parameters) / 2) - 1
is_decoder_layer = index >= len(net_parameters) / 2
if (
not DO_PROJ_MIDDLE
) and is_middle: # Do no gradient masking at middle layer
pass
elif is_decoder_layer and (
not DO_PROJ_DECODER
): # Do no gradient masking on the decoder layers
pass
elif index % 2 == 0:
param.data = torch.where(
prev_data[index].abs() < TOL,
torch.zeros_like(param.data),
param.data,
)
run_model = "MaskGrad"
(
data_encoder,
data_decoded,
epoch_loss,
best_test,
net,
) = ft.RunAutoEncoder(
net,
criterion_reconstruction,
criterion_classification,
train_dl,
train_len,
test_dl,
test_len,
optimizer,
outputPath,
TYPE_PROJ,
LOSS_LAMBDA,
lr_scheduler,
N_EPOCHS_MASKGRAD,
run_model,
DO_PROJ_MIDDLE,
DO_PROJ_DECODER,
ETA,
AXIS=AXIS,
)
print("\n--------Finised masked gradient-----")
print("-----------------------")
data_encoder = data_encoder.cpu().detach().numpy()
data_decoded = data_decoded.cpu().detach().numpy()
(
data_encoder_test,
data_decoded_test,
class_train,
class_test,
_,
correct_pred,
softmax,
Ytrue,
Ypred,
) = ft.runBestNet(
train_dl,
test_dl,
best_test,
outputPath,
fold_idx,
class_len,
net,
feature_names,
test_len,
)
if seed == SEEDS[-1]:
if fold_idx == 0:
Ytruef = Ytrue
Ypredf = Ypred
LP_test = data_encoder_test.detach().cpu().numpy()
else:
Ytruef = np.concatenate((Ytruef, Ytrue))
Ypredf = np.concatenate((Ypredf, Ypred))
LP_test = np.concatenate(
(LP_test, data_encoder_test.detach().cpu().numpy())
)
accuracy_train[seed_idx * 4 + fold_idx] = class_train
accuracy_test[seed_idx * 4 + fold_idx] = class_test
X_encoder = data_encoder[:, :-1]
labels_encoder = data_encoder[:, -1]
data_encoder_test = data_encoder_test.cpu().detach()
# SIL score
data_train[seed_idx * 4 + fold_idx, 0] = metrics.silhouette_score(
X_encoder, labels_encoder, metric="euclidean"
)
X_encodertest = data_encoder_test[:, :-1]
labels_encodertest = data_encoder_test[:, -1]
data_test[seed_idx * 4 + fold_idx, 0] = metrics.silhouette_score(
X_encodertest, labels_encodertest, metric="euclidean"
)
# ARI score
data_train[seed_idx * 4 + fold_idx, 1] = metrics.adjusted_rand_score(
labels_encoder, labelpredict
)
data_test[seed_idx * 4 + fold_idx, 1] = metrics.adjusted_rand_score(
Ytest, data_encoder_test[:, :-1].max(1)[1].detach().cpu().numpy()
)
# AMI Score
data_train[seed_idx * 4 + fold_idx, 2] = metrics.adjusted_mutual_info_score(
labels_encoder, labelpredict
)
data_test[seed_idx * 4 + fold_idx, 2] = metrics.adjusted_mutual_info_score(
Ytest, data_encoder_test[:, :-1].max(1)[1].detach().cpu().numpy()
)
# AUC Score
if class_len == 2:
data_train[seed_idx * 4 + fold_idx, 3] = metrics.roc_auc_score(
labels_encoder, labelpredict
)
data_test[seed_idx * 4 + fold_idx, 3] = metrics.roc_auc_score(
Ytest, data_encoder_test[:, :-1].max(1)[1].detach().cpu().numpy()
)
# F1 precision recall
data_train[seed_idx * 4 + fold_idx, 4:] = precision_recall_fscore_support(
labels_encoder, labelpredict, average="macro"
)[:-1]
data_test[seed_idx * 4 + fold_idx, 4:] = precision_recall_fscore_support(
Ytest, data_encoder_test[:, :-1].max(1)[1].numpy(), average="macro"
)[:-1]
# Correct labels storage
correct_prediction += correct_pred
# Get Top Genes of each class
# method = 'Shap' # (SHapley Additive exPlanation) needs a nb_samples
nb_samples = 300 # Randomly choose nb_samples to calculate their Shap Value, time vs nb_samples seems exponential
# method = 'Captum_ig' # Integrated Gradients
method = "Captum_dl" # Deeplift
# method = 'Captum_gs' # GradientShap
if DoTopGenes:
tps1 = time.perf_counter()
if fold_idx == 0: # first fold, never did topgenes yet
print("Running topGenes...")
df_topGenes = ft.topGenes(
X,
Y,
feature_names,
class_len,
feature_len,
method,
nb_samples,
DEVICE,
net,
)
df_topGenes.index = df_topGenes.iloc[:, 0]
print("topGenes finished")
tps2 = time.perf_counter()
else:
print("Running topGenes...")
df_topGenes = ft.topGenes(
X,
Y,
feature_names,
class_len,
feature_len,
method,
nb_samples,
DEVICE,
net,
)
print("topGenes finished")
df = pd.read_csv(
"{}{}_topGenes_{}_{}.csv".format(
outputPath, str(TYPE_PROJ_NAME), method, str(nb_samples)
),
sep=";",
header=0,
index_col=0,
)
df_topGenes.index = df_topGenes.iloc[:, 0]
df_topGenes = df.join(df_topGenes.iloc[:, 1], lsuffix="_",)
df_topGenes.to_csv(
"{}{}_topGenes_{}_{}.csv".format(
outputPath, str(TYPE_PROJ_NAME), method, str(nb_samples)
),
sep=";",
)
tps2 = time.perf_counter()
print("Execution time topGenes : ", tps2 - tps1)
if seed == SEEDS[0]:
df_softmax = softmax
df_softmax.index = df_softmax["Name"]
# softmax.to_csv('{}softmax.csv'.format(outputPath),sep=';',index=0)
else:
softmax.index = softmax["Name"]
df_softmax = df_softmax.join(softmax, rsuffix="_")
# Moyenne sur les SEED
if DoTopGenes:
df = pd.read_csv(
"{}{}_topGenes_{}_{}.csv".format(
outputPath, str(TYPE_PROJ_NAME), method, str(nb_samples)
),
sep=";",
header=0,
index_col=0,
)
df_val = df.values[1:, 1:].astype(float)
df_mean = df_val.mean(axis=1).reshape(-1, 1)
df_std = df_val.std(axis=1).reshape(-1, 1)
df = pd.DataFrame(
np.concatenate((df.values[1:, :], df_mean, df_std), axis=1),
columns=[
"Features",
"Fold 1",
"Fold 2",
"Fold 3",
"Fold 4",
"Mean",
"Std",
],
)
df_topGenes = df
df_topGenes = df_topGenes.sort_values(by="Mean", ascending=False)
df_topGenes = df_topGenes.reindex(
columns=[
"Features",
"Mean",
"Fold 1",
"Fold 2",
"Fold 3",
"Fold 4",
"Std",
]
)
df_topGenes.to_csv(
"{}{}_topGenes_{}_{}.csv".format(
outputPath, str(TYPE_PROJ_NAME), method, str(nb_samples)
),
sep=";",
index=0,
)
if seed == SEEDS[0]:
df_topGenes_mean = df_topGenes.iloc[:, 0:2]
df_topGenes_mean.index = df_topGenes.iloc[:, 0]
else:
df = pd.read_csv(
"{}{}_topGenes_Mean_{}_{}.csv".format(
outputPath, str(TYPE_PROJ_NAME), method, str(nb_samples)
),
sep=";",
header=0,
index_col=0,
)
df_topGenes.index = df_topGenes.iloc[:, 0]
df_topGenes_mean = df.join(df_topGenes.iloc[:, 1], lsuffix="_",)
df_topGenes_mean.to_csv(
"{}{}_topGenes_Mean_{}_{}.csv".format(
outputPath, str(TYPE_PROJ_NAME), method, str(nb_samples)
),
sep=";",
)
seed_idx += 1
# accuracies
df_accTrain, df_acctest = ft.packClassResult(
accuracy_train, accuracy_test, nfolds * len(SEEDS), label_name
)
print("\nAccuracy Train")
print(df_accTrain)
print("\nAccuracy Test")
print(df_acctest)
# metrics
df_metricsTrain, df_metricsTest = ft.packMetricsResult(
data_train, data_test, nfolds * len(SEEDS)
)
# separation of the metrics in different dataframes
clustering_metrics = ["Silhouette", "ARI", "AMI"]
classification_metrics = ["AUC", "Precision", "Recall", "F1 score"]
df_metricsTrain_clustering = df_metricsTrain[clustering_metrics]
df_metricsTrain_classif = df_metricsTrain[classification_metrics]
df_metricsTest_clustering = df_metricsTest[clustering_metrics]
df_metricsTest_classif = df_metricsTest[classification_metrics]
print("\nMetrics Train")
# print(df_metricsTrain_clustering)
print(df_metricsTrain_classif)
print("\nMetrics Test")
# print(df_metricsTest_clustering)
print(df_metricsTest_classif)
# Reconstruction by using the centers in latent space and datas after interpolation
center_mean, center_distance = ft.Reconstruction(0.2, data_encoder, net, class_len)
# Do pca,tSNE for encoder data
if Do_pca and Do_tSNE:
tit = "Latent Space"
ft.ShowPcaTsne(X, Y, data_encoder, center_distance, class_len, tit)
if DoTopGenes:
df = pd.read_csv(
"{}{}_topGenes_Mean_{}_{}.csv".format(
outputPath, str(TYPE_PROJ_NAME), method, str(nb_samples)
),
sep=";",
header=0,
index_col=0,
)
df_val = df.values[:, 1:].astype(float)
df_mean = df_val.mean(axis=1).reshape(-1, 1)
df_std = df_val.std(axis=1).reshape(-1, 1)
df_meanstd = df_std / df_mean
col_seed = ["Seed " + str(i) for i in SEEDS]
df = pd.DataFrame(
np.concatenate((df.values[:, :], df_mean, df_std, df_meanstd), axis=1),
columns=["Features"] + col_seed + ["Mean", "Std", "Mstd"],
)
df_topGenes = df
df_topGenes = df_topGenes.sort_values(by="Mean", ascending=False)
df_topGenes = df_topGenes.reindex(
columns=["Features", "Mean"] + col_seed + ["Std", "Mstd"]
)
df_topGenes.to_csv(
"{}{}_topGenes_Mean_{}_{}.csv".format(
outputPath, str(TYPE_PROJ_NAME), method, str(nb_samples)
),
sep=";",
index=0,
)
plt.figure()
plt.title("Kernel Density")
plt.plot([0.5, 0.5], [0, 3])
lab = 0
for col in softmax.iloc[:, 2:]:
distrib = softmax[col].where(softmax["Labels"] == lab).dropna()
if lab == 0:
sns.kdeplot(
1 - distrib,
bw_method=bW,
shade=True,
color="tab:blue",
label="Proba class 0",
)
# sns.kdeplot(1 - distrib, bw=0.1, fill=True, shade="True")
else:
sns.kdeplot(
distrib,
bw_method=bW,
shade=True,
color="tab:orange",
label="Proba class 1",
)
# sns.kdeplot(distrib, bw=0.1, fill=True, shade="True")
lab += 1
plt.legend(loc="upper left")
plt.xlabel("")
plt.ylabel("")
plt.show()
spasity_percentage_entry = {}
for keys in spasity_w_entry.keys():
spasity_percentage_entry[keys] = spasity_w_entry[keys] * 100
print("spasity % of all layers entry \n", spasity_percentage_entry)
print("-----------------------")
weights, spasity_w = fnp.weights_and_sparsity(net.encoder)
spasity_percentage = {}
for keys in spasity_w.keys():
spasity_percentage[keys] = spasity_w[keys] * 100
print("spasity % of all layers \n", spasity_percentage)
weights_decoder, spasity_w_decoder = fnp.weights_and_sparsity(net.decoder)
spasity_percentage_decoder = {}
for keys in spasity_w_decoder.keys():
spasity_percentage_decoder[keys] = spasity_w_decoder[keys] * 100
print("spasity % of all layers \n", spasity_percentage_decoder)
print("-----------------------")
mat_in = net.state_dict()["encoder.0.weight"]
mat_col_sparsity = ft.sparsity_col(mat_in, device=DEVICE)
print(" Column sparsity of input matrix: \n", mat_col_sparsity)
mat_in_sparsity = ft.sparsity_line(mat_in, device=DEVICE)
print("Line sparsity of input matrix: \n", mat_in_sparsity)
layer_list = [x for x in weights.values()]
layer_list_decoder = [x for x in weights_decoder.values()]
titile_list = [x for x in spasity_w.keys()]
ft.show_img(layer_list, layer_list_decoder, file_name)
# Loss figure
if os.path.exists(file_name.split(".")[0] + "_Loss_No_proj.npy") and os.path.exists(
file_name.split(".")[0] + "_Loss_MaskGrad.npy"
):
loss_no_proj = np.load(file_name.split(".")[0] + "_Loss_No_proj.npy")
loss_with_proj = np.load(file_name.split(".")[0] + "_Loss_MaskGrad.npy")
plt.figure()
plt.title(file_name.split(".")[0] + " Loss")
plt.xlabel("Epoch")
plt.ylabel("TotalLoss")
plt.plot(loss_no_proj, label="No projection")
plt.plot(loss_with_proj, label="With projection ")
plt.legend()
plt.show()
if SAVE_FILE:
df_acctest.to_csv(
"{}{}_acctest.csv".format(outputPath, str(TYPE_PROJ_NAME)), sep=";"
)
df_metricsTest_classif.to_csv(
"{}{}_auctest.csv".format(outputPath, str(TYPE_PROJ_NAME)), sep=";"
)
print("Save topGenes results to: ' {} ' ".format(outputPath))
# %%