ATLAS Offline Software
TJetNet.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /*
6  ROOT Interface to JETNET
7  Author: Vassil Verguilov
8  Created: 2005.02.22 14:07 EET
9  Revisited and extended by: Giacinto Piacquadio (Freiburg University)
10  (ATLAS - 18-02-2008)
11 */
12 
13 
14 
15 #ifndef PIXELCALIBALGS_TJETNET_H
16 #define PIXELCALIBALGS_TJETNET_H
17 
18 //______________________________________________________________________________
19 //
20 // TJetNet
21 //
22 // This class is a ROOT wrapper for jetnet library.
23 //
24 //______________________________________________________________________________
25 //
26 
27 //#define _DEBUG
28 
29 #include "TROOT.h"
30 #include "TObject.h"
31 #include "Riostream.h"
32 #include "TNeuralDataSet.h"
33 #include "TF1.h"
34 
35 class TTrainedNetwork;
36 
37 
38 //typedef ActivationFunction TActivationFunction;
39 
40 class TJetNet : public TObject
41 {
42  public:
43 
44  TJetNet( void );
45 
46  TJetNet( Int_t aTestCount, Int_t aTrainCount, const Int_t aLayersCnt, const Int_t* aLayers );
47 
48  virtual ~TJetNet( void );
49 
50  void Print( void );
51 
52  Int_t GetTrainSetCnt( void ) const { return m_TrainSetCnt; };
53  Int_t GetTestSetCnt( void ) const { return m_TestSetCnt; };
54  Int_t GetInputDim( void ) const { return m_pLayers[ 0 ]; };
55  Int_t GetHiddenLayerDim( void ) const { return mHiddenLayerDim; };
56  Int_t GetHiddenLayerSize(Int_t number) const { return m_pLayers[ number ]; };
57  Int_t GetOutputDim( void ) const { return m_pLayers[ m_LayerCount - 1 ]; };
58 
59  void SetInputTrainSet( Int_t aPatternInd, Int_t aInputInd, Double_t aValue );
60  void SetOutputTrainSet( Int_t aPatternInd, Int_t aOutputInd, Double_t aValue );
61  void SetInputTestSet( Int_t aPatternInd, Int_t aInputInd, Double_t aValue );
62  void SetOutputTestSet( Int_t aPatternInd, Int_t aOutputInd, Double_t aValue );
63 
64  void SetEventWeightTrainSet( Int_t aPatternInd, Double_t aValue );
65  void SetEventWeightTestSet( Int_t aPatternInd, Double_t aValue );
66 
67  Double_t GetInputTrainSet( Int_t aPatternInd, Int_t aInputInd );
68  Double_t GetOutputTrainSet( Int_t aPatternInd, Int_t aOutputInd );
69  Double_t GetInputTestSet( Int_t aPatternInd, Int_t aInputInd );
70  Double_t GetOutputTestSet( Int_t aPatternInd, Int_t aOutputInd );
71 
72  Double_t GetEventWeightTrainSet( Int_t aPatternInd );
73  Double_t GetEventWeightTestSet( Int_t aPatternInd );
74 
75  Double_t GetWeight( Int_t aLayerInd, Int_t aNodeInd, Int_t aConnectedNodeInd ) const;
76  Double_t GetThreshold( Int_t aLayerInd, Int_t aNodeInd) const;
77 
78  Int_t GetEpochs( void ) { return m_Epochs; };
79  void SetEpochs( const Int_t aEpochs ) { m_Epochs = aEpochs; m_CurrentEpoch = 0; };
80  void Init( void );
81 
82  Double_t Train( void );
83  Int_t Epoch( void );
84  Double_t Test( void );
85  Double_t TestBTAG( void );
86 
87  void Shuffle ( Bool_t aShuffleTrainSet = true, Bool_t aShuffleTestSet = true );
88 
89  void SaveDataAscii( TString aFileName = "jndata.dat" );
90  void SaveDataRoot( TString aFileName = "jndata.root" );
91 
92  void LoadDataAscii( TString aFileName = "jndata.dat" );
93  void LoadDataRoot( TString aFileName = "jndata.root" );
94 
95  void DumpToFile( TString aFileName = "fort.8" );
96  void ReadFromFile( TString aFileName = "fort.8" );
97 
98  Double_t GetOutput( Int_t aIndex = 0 );
99  void SetInputs( Int_t aIndex = 0, Double_t aValue = 0.0 );
100  void Evaluate( Int_t aPattern );
101  void Evaluate();
102 
103  void writeNetworkInfo(Int_t typeOfInfo = 0);
104 
105  Int_t GetLayerCount( void ){ return m_LayerCount; };
106  //Number of layers in NN
107  Int_t GetUnitCount( Int_t aLayer );
108  //Number of units in NN
109 
110  void SelectiveFields( Int_t aLayerA, Int_t aNodeA1, Int_t aNodeA2, Int_t aNodeB1, Int_t aNodeB2, Int_t aSwitch = 0 );
111 
112  void SetUpdatesPerEpoch( Int_t aValue );
113  void SetUpdatingProcedure( Int_t aValue );
114  void SetErrorMeasure( Int_t aValue );
115  void SetActivationFunction( Int_t aValue );
116  void SetActivationFunction( Int_t aValue, Int_t layerN );
117  void SetPatternsPerUpdate( Int_t aValue );
118  void SetLearningRate( Double_t aValue );
119  void SetMomentum( Double_t aValue );
120  void SetInitialWeightsWidth( Double_t aValue );
121  void SetLearningRateDecrease( Double_t aValue );
122  void SetPottsUnits(Int_t aValue);
123 
124 
125  Int_t GetUpdatesPerEpoch( void );
126  Int_t GetUpdatingProcedure( void );
127  Int_t GetErrorMeasure( void );
128  Int_t GetActivationFunction( void ) const;
129  Int_t GetActivationFunction( Int_t layerN) const;
130  Int_t GetPatternsPerUpdate( void );
131  Double_t GetLearningRate( void );
132  Double_t GetMomentum( void );
133  Double_t GetInitialWeightsWidth( void );
134  Double_t GetLearningRateDecrease( void );
135  Int_t GetPottsUnits();
136 
137  void LockInit( void ){ m_InitLocked = kTRUE; };
138  void UnlockInit( void ){ m_InitLocked = kFALSE; };
139  Int_t GetMSTJN( Int_t aIndex );
140  Double_t GetPARJN( Int_t aIndex );
141  void SetMSTJN( Int_t aIndex, Int_t aValue );
142  void SetPARJN( Int_t aIndex, Double_t aValue );
143 
144  void Normalize( void );
145  void Randomize( void );
146 
149 
152  afTanh = 2,
153  afExp = 3,
154  afLinear = 4,
155  afSigmoidEntropy = 5
156  };
157 
158  void NormalizeOutput(bool isTrue=true);
159 
160 private:
161 
162  void mSetWeight( Double_t weight,Int_t aLayerInd, Int_t aNodeInd, Int_t aConnectedNodeInd );
163  void mSetThreshold( Double_t threshold, Int_t aLayerInd, Int_t aNodeInd);
164 
165  Int_t CopyFile( TString aSrcFile, TString aDestFile );
166  void Reinitialize( void ); // Synchronizing the paramaters of the class object from JETNET parameters
167 
168 
169 
171 
172  Int_t m_LayerCount; // Number of Layers (including the input and output)
173  Int_t* m_pLayers;
174 
179 
180  Int_t m_TrainSetCnt, m_TestSetCnt; // Size of Train and Test set
181 
182  Int_t m_InputDim; // Number of the elements in intput layer
183  Int_t m_HiddenLayerDim; // Number of Hidden Layers
184  Int_t m_OutputDim; // Number of outputs
185  Int_t m_Epochs; // Epochs
186  Int_t m_CurrentEpoch; // Current epoch
187  Bool_t m_Debug; // Debug Flag
189  Bool_t m_InitLocked;
191 
192 
193  ClassDef( TJetNet, 1 )
194 };
195 
196 inline void TJetNet::SetOutputTestSet( Int_t aPatternInd, Int_t aOutputInd, Double_t aValue )
197 {
198  // Changes the value of the cell corresponding to unit aInputInd in pattern aPatternInd into OUTPUT TEST set
199  m_pOutputTestSet->SetData( aPatternInd, aOutputInd, aValue );
200 }
201 //______________________________________________________________________________
202 inline Double_t TJetNet::GetInputTrainSet( Int_t aPatternInd, Int_t aInputInd )
203 {
204  // Returns the value of the cell corresponding to unit aInputInd in pattern aPatternInd into INPUT TRAIN set
205  return m_pInputTrainSet->GetData( aPatternInd, aInputInd );
206 }
207 //______________________________________________________________________________
208 inline Double_t TJetNet::GetEventWeightTrainSet( Int_t aPatternInd )
209 {
210  return m_pInputTrainSet->GetEventWeight( aPatternInd);
211 }
212 //______________________________________________________________________________
213 inline Double_t TJetNet::GetEventWeightTestSet( Int_t aPatternInd )
214 {
215  return m_pInputTestSet->GetEventWeight( aPatternInd);
216 }
217 
218 #endif
219 
TNeuralDataSet
Definition: TNeuralDataSet.h:26
TJetNet::m_enActFunction
TActivationFunction m_enActFunction
Definition: TJetNet.h:170
TJetNet::m_CurrentEpoch
Int_t m_CurrentEpoch
Definition: TJetNet.h:186
TJetNet::afSigmoid
@ afSigmoid
Definition: TJetNet.h:151
TJetNet::GetTestSetCnt
Int_t GetTestSetCnt(void) const
Definition: TJetNet.h:53
TJetNet::Epoch
Int_t Epoch(void)
Definition: TJetNet.cxx:696
TJetNet::TJetNet
TJetNet(void)
TJetNet::LoadDataAscii
void LoadDataAscii(TString aFileName="jndata.dat")
Definition: TJetNet.cxx:815
TJetNet::GetErrorMeasure
Int_t GetErrorMeasure(void)
Definition: TJetNet.cxx:1156
TJetNet::TActivationFunction
TActivationFunction
Definition: TJetNet.h:150
TJetNet::LockInit
void LockInit(void)
Definition: TJetNet.h:137
TJetNet::GetLearningRate
Double_t GetLearningRate(void)
Definition: TJetNet.cxx:1177
TJetNet::SetPatternsPerUpdate
void SetPatternsPerUpdate(Int_t aValue)
Definition: TJetNet.cxx:1105
TJetNet::GetEventWeightTestSet
Double_t GetEventWeightTestSet(Int_t aPatternInd)
Definition: TJetNet.h:213
TJetNet::m_TrainSetCnt
Int_t m_TrainSetCnt
Definition: TJetNet.h:180
TJetNet::readBackTrainedNetwork
void readBackTrainedNetwork(const TTrainedNetwork *)
Definition: TJetNet.cxx:207
TJetNet::writeNetworkInfo
void writeNetworkInfo(Int_t typeOfInfo=0)
Definition: TJetNet.cxx:664
TNeuralDataSet::SetData
void SetData(const Int_t aPattern, const Int_t aIndex, Double_t aValue)
Definition: TNeuralDataSet.cxx:37
TJetNet::m_InputDim
Int_t m_InputDim
Definition: TJetNet.h:182
TJetNet::m_OutputDim
Int_t m_OutputDim
Definition: TJetNet.h:184
TJetNet::GetMomentum
Double_t GetMomentum(void)
Definition: TJetNet.cxx:1182
TJetNet::GetOutput
Double_t GetOutput(Int_t aIndex=0)
Definition: TJetNet.cxx:948
TJetNet::Init
void Init(void)
Definition: TJetNet.cxx:670
TJetNet::SaveDataAscii
void SaveDataAscii(TString aFileName="jndata.dat")
Definition: TJetNet.cxx:775
TJetNet::SetOutputTestSet
void SetOutputTestSet(Int_t aPatternInd, Int_t aOutputInd, Double_t aValue)
Definition: TJetNet.h:196
TJetNet::GetLearningRateDecrease
Double_t GetLearningRateDecrease(void)
Definition: TJetNet.cxx:1192
TJetNet::GetMSTJN
Int_t GetMSTJN(Int_t aIndex)
Definition: TJetNet.cxx:1202
TNeuralDataSet::GetData
Double_t GetData(const Int_t aPattern, const Int_t aIndex)
Definition: TNeuralDataSet.h:68
TJetNet::SetUpdatingProcedure
void SetUpdatingProcedure(Int_t aValue)
Definition: TJetNet.cxx:1078
TJetNet::m_TestSetCnt
Int_t m_TestSetCnt
Definition: TJetNet.h:180
TJetNet::m_pInputTrainSet
TNeuralDataSet * m_pInputTrainSet
Array which contains the number of units in each layer.
Definition: TJetNet.h:175
TJetNet::GetOutputTrainSet
Double_t GetOutputTrainSet(Int_t aPatternInd, Int_t aOutputInd)
Definition: TJetNet.cxx:746
TJetNet::GetUpdatesPerEpoch
Int_t GetUpdatesPerEpoch(void)
Definition: TJetNet.cxx:1146
TJetNet::SetEpochs
void SetEpochs(const Int_t aEpochs)
Definition: TJetNet.h:79
TJetNet::m_NormalizeOutput
Bool_t m_NormalizeOutput
Definition: TJetNet.h:190
TJetNet::m_InitLocked
Bool_t m_InitLocked
Definition: TJetNet.h:189
TJetNet::GetInputTrainSet
Double_t GetInputTrainSet(Int_t aPatternInd, Int_t aInputInd)
Definition: TJetNet.h:202
TJetNet::SetInputTestSet
void SetInputTestSet(Int_t aPatternInd, Int_t aInputInd, Double_t aValue)
Definition: TJetNet.cxx:740
TJetNet::SetEventWeightTrainSet
void SetEventWeightTrainSet(Int_t aPatternInd, Double_t aValue)
Definition: TJetNet.cxx:752
TJetNet::CopyFile
Int_t CopyFile(TString aSrcFile, TString aDestFile)
TJetNet::Evaluate
void Evaluate()
Definition: TJetNet.cxx:926
TJetNet::mSetThreshold
void mSetThreshold(Double_t threshold, Int_t aLayerInd, Int_t aNodeInd)
Definition: TJetNet.cxx:290
TJetNet::SetMomentum
void SetMomentum(Double_t aValue)
Definition: TJetNet.cxx:1118
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
TJetNet::Shuffle
void Shuffle(Bool_t aShuffleTrainSet=true, Bool_t aShuffleTestSet=true)
Definition: TJetNet.cxx:1222
TJetNet::m_Debug
Bool_t m_Debug
Definition: TJetNet.h:187
TJetNet::Reinitialize
void Reinitialize(void)
Definition: TJetNet.cxx:1020
TJetNet::LoadDataRoot
void LoadDataRoot(TString aFileName="jndata.root")
Definition: TJetNet.cxx:921
TJetNet::Normalize
void Normalize(void)
Definition: TJetNet.cxx:1048
TJetNet::SetMSTJN
void SetMSTJN(Int_t aIndex, Int_t aValue)
Definition: TJetNet.cxx:1212
TJetNet
Definition: TJetNet.h:41
TJetNet::m_pOutputTrainSet
TNeuralDataSet * m_pOutputTrainSet
Definition: TJetNet.h:176
TJetNet::SaveDataRoot
void SaveDataRoot(TString aFileName="jndata.root")
Definition: TJetNet.cxx:916
TJetNet::Print
void Print(void)
Definition: TJetNet.cxx:295
TJetNet::GetInputTestSet
Double_t GetInputTestSet(Int_t aPatternInd, Int_t aInputInd)
Definition: TJetNet.cxx:763
TJetNet::afTanh
@ afTanh
Definition: TJetNet.h:152
TJetNet::GetLayerCount
Int_t GetLayerCount(void)
Definition: TJetNet.h:105
TJetNet::TestBTAG
Double_t TestBTAG(void)
Definition: TJetNet.cxx:362
TJetNet::ReadFromFile
void ReadFromFile(TString aFileName="fort.8")
Definition: TJetNet.cxx:962
TJetNet::m_IsInitialized
Bool_t m_IsInitialized
Definition: TJetNet.h:188
TJetNet::GetWeight
Double_t GetWeight(Int_t aLayerInd, Int_t aNodeInd, Int_t aConnectedNodeInd) const
Definition: TJetNet.cxx:972
TJetNet::Randomize
void Randomize(void)
Definition: TJetNet.cxx:1055
TJetNet::m_pLayers
Int_t * m_pLayers
Definition: TJetNet.h:173
TJetNet::NormalizeOutput
void NormalizeOutput(bool isTrue=true)
Definition: TJetNet.cxx:1141
TJetNet::SetPARJN
void SetPARJN(Int_t aIndex, Double_t aValue)
Definition: TJetNet.cxx:1217
TJetNet::GetUnitCount
Int_t GetUnitCount(Int_t aLayer)
Definition: TJetNet.cxx:1064
TJetNet::m_pInputTestSet
TNeuralDataSet * m_pInputTestSet
Definition: TJetNet.h:177
TJetNet::SetOutputTrainSet
void SetOutputTrainSet(Int_t aPatternInd, Int_t aOutputInd, Double_t aValue)
Definition: TJetNet.cxx:734
TJetNet::SetInputTrainSet
void SetInputTrainSet(Int_t aPatternInd, Int_t aInputInd, Double_t aValue)
Definition: TJetNet.cxx:728
TJetNet::GetPatternsPerUpdate
Int_t GetPatternsPerUpdate(void)
Definition: TJetNet.cxx:1172
TJetNet::mSetWeight
void mSetWeight(Double_t weight, Int_t aLayerInd, Int_t aNodeInd, Int_t aConnectedNodeInd)
Definition: TJetNet.cxx:285
TTrainedNetwork
Definition: InnerDetector/InDetCalibAlgs/PixelCalibAlgs/NNClusteringCalibration_RunI/TTrainedNetwork.h:21
TJetNet::GetTrainSetCnt
Int_t GetTrainSetCnt(void) const
Definition: TJetNet.h:52
TJetNet::GetEpochs
Int_t GetEpochs(void)
Definition: TJetNet.h:78
TJetNet::m_Epochs
Int_t m_Epochs
Definition: TJetNet.h:185
TJetNet::GetActivationFunction
Int_t GetActivationFunction(void) const
Definition: TJetNet.cxx:1161
TJetNet::SetErrorMeasure
void SetErrorMeasure(Int_t aValue)
Definition: TJetNet.cxx:1085
TJetNet::SetLearningRate
void SetLearningRate(Double_t aValue)
Definition: TJetNet.cxx:1111
TJetNet::GetOutputDim
Int_t GetOutputDim(void) const
Definition: TJetNet.h:57
TJetNet::SetLearningRateDecrease
void SetLearningRateDecrease(Double_t aValue)
Definition: TJetNet.cxx:1130
python.selection.number
number
Definition: selection.py:20
TJetNet::afLinear
@ afLinear
Definition: TJetNet.h:154
TJetNet::m_HiddenLayerDim
Int_t m_HiddenLayerDim
Definition: TJetNet.h:183
TJetNet::GetThreshold
Double_t GetThreshold(Int_t aLayerInd, Int_t aNodeInd) const
Definition: TJetNet.cxx:979
threshold
Definition: chainparser.cxx:74
TJetNet::GetInitialWeightsWidth
Double_t GetInitialWeightsWidth(void)
Definition: TJetNet.cxx:1187
TJetNet::GetPottsUnits
Int_t GetPottsUnits()
Definition: TJetNet.cxx:1197
TJetNet::afSigmoidEntropy
@ afSigmoidEntropy
Definition: TJetNet.h:155
TJetNet::SetUpdatesPerEpoch
void SetUpdatesPerEpoch(Int_t aValue)
Definition: TJetNet.cxx:1071
TJetNet::SetInitialWeightsWidth
void SetInitialWeightsWidth(Double_t aValue)
Definition: TJetNet.cxx:1124
TJetNet::DumpToFile
void DumpToFile(TString aFileName="fort.8")
Definition: TJetNet.cxx:954
TJetNet::SetActivationFunction
void SetActivationFunction(Int_t aValue)
Definition: TJetNet.cxx:1091
TNeuralDataSet::GetEventWeight
Double_t GetEventWeight(const Int_t aPattern)
Definition: TNeuralDataSet.h:74
TJetNet::afExp
@ afExp
Definition: TJetNet.h:153
TJetNet::GetInputDim
Int_t GetInputDim(void) const
Definition: TJetNet.h:54
TJetNet::GetHiddenLayerSize
Int_t GetHiddenLayerSize(Int_t number) const
Definition: TJetNet.h:56
TJetNet::createTrainedNetwork
TTrainedNetwork * createTrainedNetwork() const
Definition: TJetNet.cxx:104
TJetNet::GetPARJN
Double_t GetPARJN(Int_t aIndex)
Definition: TJetNet.cxx:1207
TJetNet::GetOutputTestSet
Double_t GetOutputTestSet(Int_t aPatternInd, Int_t aOutputInd)
Definition: TJetNet.cxx:769
TJetNet::m_pOutputTestSet
TNeuralDataSet * m_pOutputTestSet
Definition: TJetNet.h:178
TJetNet::Test
Double_t Test(void)
Definition: TJetNet.cxx:320
TJetNet::SetPottsUnits
void SetPottsUnits(Int_t aValue)
Definition: TJetNet.cxx:1136
TJetNet::SetEventWeightTestSet
void SetEventWeightTestSet(Int_t aPatternInd, Double_t aValue)
Definition: TJetNet.cxx:758
TJetNet::~TJetNet
virtual ~TJetNet(void)
Definition: TJetNet.cxx:91
TJetNet::SelectiveFields
void SelectiveFields(Int_t aLayerA, Int_t aNodeA1, Int_t aNodeA2, Int_t aNodeB1, Int_t aNodeB2, Int_t aSwitch=0)
Definition: TJetNet.cxx:986
TJetNet::UnlockInit
void UnlockInit(void)
Definition: TJetNet.h:138
TJetNet::SetInputs
void SetInputs(Int_t aIndex=0, Double_t aValue=0.0)
Definition: TJetNet.cxx:942
TJetNet::GetEventWeightTrainSet
Double_t GetEventWeightTrainSet(Int_t aPatternInd)
Definition: TJetNet.h:208
TNeuralDataSet.h
TJetNet::Train
Double_t Train(void)
Definition: TJetNet.cxx:618
TJetNet::m_LayerCount
Int_t m_LayerCount
Definition: TJetNet.h:172
TJetNet::GetUpdatingProcedure
Int_t GetUpdatingProcedure(void)
Definition: TJetNet.cxx:1151
TJetNet::GetHiddenLayerDim
Int_t GetHiddenLayerDim(void) const
Definition: TJetNet.h:55