Belle II Software  release-05-01-25
grlneurotrainer.py
1 #!/user/bin/env python
2 
3 import basf2
4 from ROOT import Belle2
5 import os
6 import glob
7 
8 """
9 Example script showing how to train neural networks
10 to be used with the CDCTriggerNeuroModule.
11 
12 This script uses realistic values for the amount of training data
13 and the number of runs, so it will run a long time.
14 """
15 
16 # ------------ #
17 # user options #
18 # ------------ #
19 
20 # set random seed
21 basf2.set_random_seed(1)
22 
23 # paths for the trained networks, the training data and the log files
24 mlpdir = Belle2.FileSystem.findFile('trg/grl/data')
25 traindir = Belle2.FileSystem.findFile('trg/grl/data')
26 logdir = Belle2.FileSystem.findFile('trg/grl/data')
27 # filenames for the trained networks, the training data and the log files
28 mlpname = 'GRLNeuro.root'
29 trainname = 'GRLNeuroTraindata.root'
30 logname = 'GRLNeuroLog' # file extensions are appended automatically
31 
32 # number of threads to be used for parallel training
33 nthreads = 1
34 
35 
36 # ------------------------- #
37 # create path up to trigger #
38 # ------------------------- #
39 
40 main = basf2.create_path()
41 
42 main.add_module('Progress')
43 main.add_module('RootInput')
44 
45 # ---------------- #
46 # add the training #
47 # ---------------- #
48 
49 main.add_module('GRLNeuroTrainer',
50  # output
51  filename=os.path.join(mlpdir, mlpname),
52  trainFilename=os.path.join(traindir, trainname),
53 
54  # network structure
55  # nMLP=20, # total number of sectors
56  # multiplyHidden=False, # set the number of hidden nodes directly
57  # nHidden=[[10]], # 1 hidden layer with 81 nodes for all sectors
58  # i_cdc_sector=[0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3],
59  # i_ecl_sector=[0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4],
60  nMLP=8, # total number of sectors
61  multiplyHidden=False, # set the number of hidden nodes directly
62  nHidden=[[100]], # 1 hidden layer with 81 nodes for all sectors
63  n_cdc_sector=1,
64  n_ecl_sector=8,
65  i_cdc_sector=[0*2+36*3, 0*2+36*3, 0*2+36*3, 0*2+36*3, 0*2+36*3, 0*2+36*3, 0*2+36*3, 0*2+36*3],
66  i_ecl_sector=[0*3, 1*3, 2*3, 3*3, 4*3, 5*3, 6*3, 7*3],
67 
68  wMax=63., # limit weights to [-63, 63]
69  # training parameters
70  # multiplyNTrain=True, # set training data relative to degrees of freedom
71  # nTrainMax=10., # training data (10x degrees of freedom)
72  # nTrainMin=10., # don't train if there is less than 10x DoF training data
73  multiplyNTrain=False, # set training data relative to degrees of freedom
74  nTrainMax=2000, # training data (10x degrees of freedom)
75  nTrainMin=2000, # don't train if there is less than 10x DoF training data
76  nValid=1000, # number of validation samples (to avoid overtraining)
77  nTest=1000, # number of test samples (to select best of several runs)
78  # repeatTrain=10, # train each sector 10x with different initial weights
79  repeatTrain=1, # train each sector 10x with different initial weights
80  checkInterval=500, # stop training if validation error does not improve for 500 epochs
81  # maxEpochs=10000, # stop training after 10000 epochs
82  maxEpochs=1000, # stop training after 10000 epochs
83  nThreads=nthreads, # number of parallel threads
84  # log level
85  logLevel=basf2.LogLevel.DEBUG, # show some debug output
86  debugLevel=50)
87 
88 # show only the message of the debug output
89 # basf2.logging.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
90 
91 
92 # Process events
93 basf2.process(main)
94 
95 # Print call statistics
96 print(basf2.statistics)
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
Belle2::FileSystem::findFile
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:147