17 from b2test_utils
import skip_test
19 variables = [
'M',
'p',
'pt',
'pz',
20 'daughter(0, p)',
'daughter(0, pz)',
'daughter(0, pt)',
21 'daughter(1, p)',
'daughter(1, pz)',
'daughter(1, pt)',
22 'daughter(2, p)',
'daughter(2, pz)',
'daughter(2, pt)',
23 'chiProb',
'dr',
'dz',
24 'daughter(0, dr)',
'daughter(1, dr)',
25 'daughter(0, dz)',
'daughter(1, dz)',
26 'daughter(0, chiProb)',
'daughter(1, chiProb)',
'daughter(2, chiProb)',
27 'daughter(0, kaonID)',
'daughter(0, pionID)',
28 'daughterInvM(0, 1)',
'daughterInvM(0, 2)',
'daughterInvM(1, 2)']
38 return np.require(p, dtype=np.float32, requirements=[
'A',
'W',
'C',
'O'])
41 def begin_fit(state, Xtest, Stest, ytest, wtest):
43 Test begin_fit function
45 print(Xtest.mean(axis=0))
46 print(Xtest.std(axis=0))
50 def partial_fit(state, X, S, y, w, epoch, batch):
52 Test partial_fit function
59 print(
"Executed python script")
61 if __name__ ==
"__main__":
64 if not (os.path.isfile(
'train.root')
and os.path.isfile(
'test.root')):
65 skip_test(
'Necessary files "train.root" and "test.root" not available.')
67 general_options = basf2_mva.GeneralOptions()
68 general_options.m_datafiles = basf2_mva.vector(
"train.root")
69 general_options.m_treename =
"tree"
70 general_options.m_variables = basf2_mva.vector(*variables)
71 general_options.m_target_variable =
"isSignal"
72 general_options.m_identifier =
"Python.xml"
74 specific_options = basf2_mva.PythonOptions()
75 specific_options.m_training_fraction = 0.9
76 specific_options.m_nIterations = 1
77 specific_options.m_mini_batch_size = 0
78 specific_options.m_framework =
'test'
79 specific_options.m_steering_file =
'mva/tests/python_normalization.py'
80 specific_options.m_normalize =
False
83 with tempfile.TemporaryDirectory()
as tempdir:
84 os.symlink(os.path.abspath(
'train.root'), tempdir +
'/' + os.path.basename(
'train.root'))
87 basf2_mva.teacher(general_options, specific_options)
88 basf2_mva.expert(basf2_mva.vector(
"Python.xml"),
89 basf2_mva.vector(
'train.root'),
'tree',
'expert.root')
90 specific_options.m_normalize =
True
91 basf2_mva.teacher(general_options, specific_options)
92 basf2_mva.expert(basf2_mva.vector(
"Python.xml"),
93 basf2_mva.vector(
'train.root'),
'tree',
'expert.root')