19 My dense neural network
25 param: number_of_features number of input variables
31 torch.nn.Linear(number_of_features, 128),
33 torch.nn.Linear(128, 128),
35 torch.nn.Linear(128, 1),
47def get_model(number_of_features, number_of_spectators, number_of_events, training_fraction, parameters):
49 Returns default torch model
55 state.optimizer = torch.optim.SGD(state.model.parameters(), parameters.get(
'learning_rate', 1e-2))
58 state.loss_fn = torch.nn.BCELoss
66if __name__ ==
"__main__":
67 from basf2
import conditions
73 conditions.testing_payloads = [
74 'localdb/database.txt'
77 general_options = basf2_mva.GeneralOptions()
78 general_options.m_datafiles = basf2_mva.vector(
"train.root")
79 general_options.m_identifier =
"Simple"
80 general_options.m_treename =
"tree"
81 variables = [
'M',
'p',
'pt',
'pz',
82 'daughter(0, p)',
'daughter(0, pz)',
'daughter(0, pt)',
83 'daughter(1, p)',
'daughter(1, pz)',
'daughter(1, pt)',
84 'daughter(2, p)',
'daughter(2, pz)',
'daughter(2, pt)',
85 'chiProb',
'dr',
'dz',
86 'daughter(0, dr)',
'daughter(1, dr)',
87 'daughter(0, dz)',
'daughter(1, dz)',
88 'daughter(0, chiProb)',
'daughter(1, chiProb)',
'daughter(2, chiProb)',
89 'daughter(0, kaonID)',
'daughter(0, pionID)',
90 'daughterInvM(0, 1)',
'daughterInvM(0, 2)',
'daughterInvM(1, 2)']
91 general_options.m_variables = basf2_mva.vector(*variables)
92 general_options.m_target_variable =
"isSignal"
94 specific_options = basf2_mva.PythonOptions()
95 specific_options.m_framework =
"torch"
96 specific_options.m_steering_file =
'mva/examples/torch/simple.py'
98 specific_options.m_nIterations = 64
99 specific_options.m_mini_batch_size = 256
100 specific_options.m_config = json.dumps({
'learning_rate': 1e-2})
101 specific_options.m_training_fraction = 0.8
102 specific_options.m_normalise =
False
104 training_start = time.time()
105 basf2_mva.teacher(general_options, specific_options)
106 training_stop = time.time()
107 training_time = training_stop - training_start
110 inference_start = time.time()
111 test_data = [
"test.root"]
112 p, t = method.apply_expert(basf2_mva.vector(*test_data), general_options.m_treename)
113 inference_stop = time.time()
114 inference_time = inference_stop - inference_start
116 print(
"Torch", training_time, inference_time, auc)
def calculate_auc_efficiency_vs_background_retention(p, t, w=None)
network
a dense model with one hidden layer
def __init__(self, number_of_features)