-
Notifications
You must be signed in to change notification settings - Fork 1
/
final_eval_osamp.py
152 lines (98 loc) · 3.79 KB
/
final_eval_osamp.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
#!/usr/bin/env python
# coding: utf-8
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import torch
import os
from numba import cuda
import argparse
from helpers.synthesis_plots import *
# Initialize parser
parser = argparse.ArgumentParser()
# Adding optional argument
parser.add_argument("-n", "--num_signal_to_inject", help = "num signal to inject")
parser.add_argument("-c", "--cuda_slot", help = "which gpu")
parser.add_argument("-o", "--oversampled_num", help = "factor to oversample by")
# Read arguments from command line
args = parser.parse_args()
"""
"""
"""
COMPUTING PARAMETERS
"""
"""
"""
os.environ["CUDA_VISIBLE_DEVICES"]= args.cuda_slot
device = cuda.get_current_device()
device.reset()
# set the number of threads that pytorch will use
torch.set_num_threads(2)
# set gpu device
device = torch.device( "cuda" if torch.cuda.is_available() else "cpu")
print( "Using device: " + str( device ), flush=True)
"""
"""
"""
RUN PARAMETERS
"""
"""
"""
seed = 1
n_features = 5
eval_oversampled = True
eval_nonsampled = False
index_start = 16
index_stop = 20
epochs_NN = 100
batch_size_NN = 128
lr_NN = 0.001
patience_NN = 10
results_dir = f"/clusterfs/ml4hep/rrmastandrea/oversampling_results_8_2_32_10/nsig_inj{args.num_signal_to_inject}_seed{seed}/"
os.makedirs(results_dir, exist_ok=True)
scaled_data_dir = "/global/home/users/rrmastandrea/oversamp_studies_8_2_32_10/"
"""
"""
"""
STS DATA
"""
"""
"""
STS_bkg_dataset = np.load(f"{scaled_data_dir}/STS_bkg.npy")
STS_sig_dataset = np.load(f"{scaled_data_dir}/STS_sig.npy")
dat_samples_train = np.load(f"{scaled_data_dir}/nsig_injected_{args.num_signal_to_inject}/data.npy")
"""
"""
"""
EVAL
"""
"""
"""
# load in the data samples
feta_samples_osamp = np.load(f"{scaled_data_dir}/nsig_injected_{args.num_signal_to_inject}/feta_o{args.oversampled_num}.npy")
#feta_samples_osamp= np.load(f"{scaled_data_dir}/nsig_injected_{args.num_signal_to_inject}/feta.npy")
feta_samples_nonsamp = np.load(f"{scaled_data_dir}/nsig_injected_{args.num_signal_to_inject}/feta.npy")
blank_weights_osamp = np.ones((feta_samples_osamp.shape[0], 1))
blank_weights_nonsamp = np.ones((feta_samples_nonsamp.shape[0], 1))
blank_weights_data = np.ones((dat_samples_train.shape[0], 1))
for seed_NN in range(index_start, index_stop, 1):
if eval_oversampled:
print(f"Evaluating feta oversampled x{args.oversampled_num} (seed {seed_NN + 1} of {index_stop})...")
roc = discriminate_datasets_weighted(results_dir, f"feta_o{args.oversampled_num}_{seed_NN}", feta_samples_osamp[:,:-1], dat_samples_train[:,:-1], blank_weights_osamp, blank_weights_data, STS_bkg_dataset[:,:-1], STS_sig_dataset[:,:-1], n_features, epochs_NN, batch_size_NN, lr_NN, patience_NN, device, visualize = True, seed = seed_NN)
results_file = f"{results_dir}/feta_o{args.oversampled_num}_{seed_NN}.txt"
with open(results_file, "w") as results:
results.write(f"Discrim. power for STS bkg from STS sig in band SR: {roc}\n")
results.write(3*"\n")
print()
print(5*"*")
print()
if eval_nonsampled:
print(f"Evaluating feta notoversampled (seed {seed_NN + 1} of {index_stop})...")
roc = discriminate_datasets_weighted(results_dir, f"feta_{seed_NN}", feta_samples_nonsamp[:,:-1], dat_samples_train[:,:-1], blank_weights_nonsamp, blank_weights_data, STS_bkg_dataset[:,:-1], STS_sig_dataset[:,:-1], n_features, epochs_NN, batch_size_NN, lr_NN, patience_NN, device, visualize = True, seed = seed_NN)
results_file = f"{results_dir}/feta_{seed_NN}.txt"
with open(results_file, "w") as results:
results.write(f"Discrim. power for STS bkg from STS sig in band SR: {roc}\n")
results.write(3*"\n")
print()
print(5*"*")
print()