ATLAS Offline Software
TNeuralDataSet.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TNeuralDataSet.h"
6 #include "TRandom3.h"
7 
9 //______________________________________________________________________________
10 TNeuralDataSet::TNeuralDataSet( Int_t aNumberOfPatterns, Int_t aNumberOfUnits )
11 {
12  // Default constructor
13  mpData = new TMatrixD( aNumberOfPatterns, aNumberOfUnits );
14  mpWeights = new TVectorD( aNumberOfPatterns);
15  for (int i=0;i<mpWeights->GetNrows();i++){
16  (*mpWeights)[i]=1.;
17  }
18 
19  mpNormFactors = new TVectorD( aNumberOfUnits );
20  mpShiftFactors = new TVectorD( aNumberOfUnits);
21 }
22 //______________________________________________________________________________
24 {
25  // Default destructor
26  delete mpData;
27  delete mpWeights;
28  delete mpNormFactors;
29  delete mpShiftFactors;
30 }
31 //______________________________________________________________________________
32 void TNeuralDataSet::SetEventWeight( const Int_t aPattern, Double_t aValue )
33 {
34  mpWeights->operator() ( aPattern ) = aValue;
35 }
36 //______________________________________________________________________________
37 void TNeuralDataSet::SetData( const Int_t aPattern, const Int_t aIndex, Double_t aValue )
38 {
39  // Changes the value of cell in the set specified by Pattern number and Unit index
40  mpData->operator() ( aPattern, aIndex ) = aValue;
41 }
42 //______________________________________________________________________________
44 {
45  // Normalizes data
46  Double_t fMin;
47  Double_t fMax;
48  Double_t tmp;
49 
50  for( UInt_t aUnitIndex = 0; aUnitIndex < this->GetUnitsCount(); aUnitIndex++ )
51  {
52  fMax = 0.0;
53  fMin = 0.0;
54  for( UInt_t aPatternIndex = 0; aPatternIndex < this->GetPatternsCount(); aPatternIndex++ )
55  {
56  tmp = this->GetData( aPatternIndex, aUnitIndex );
57  fMin = ( tmp < fMin )? tmp : fMin;
58  fMax = ( tmp > fMax )? tmp : fMax;
59  }
60 
61  for( UInt_t aPatternIndex = 0; aPatternIndex < this->GetPatternsCount(); aPatternIndex++ )
62  {
63  tmp = this->GetData( aPatternIndex, aUnitIndex );
64  tmp = (tmp - fMin)/(fMax-fMin);
65  this->SetData( aPatternIndex, aUnitIndex, tmp );
66  }
67 
68  mpNormFactors->operator() (aUnitIndex) = 1./(fMax-fMin);
69  mpShiftFactors->operator() (aUnitIndex) = -fMin/(fMax-fMin);
70 
71  }
72 }
73 //______________________________________________________________________________
75 {
76  // Randomizes the data
77  TRandom3 r3;
78  for( Int_t i = 0; i < this->GetPatternsCount(); i ++ )
79  for( Int_t j = 0; j < this->GetUnitsCount(); j ++ )
80  {
81  this->SetData( i, j, r3.Gaus(0, 5) );
82  }
83 }
84 //______________________________________________________________________________
85 void TNeuralDataSet::Shuffle( Int_t aSeed )
86 {
87  // Shuffles data
88  TRandom3 Random( aSeed );
89  Int_t j;
90  Double_t tmp;
91  Int_t a = this->GetPatternsCount() - 1;
92  for ( Int_t i = 0; i < this->GetPatternsCount(); i++ )
93  {
94  j = ( Int_t ) ( Random.Rndm() * a );
95  for( Int_t p = 0; p < this->GetUnitsCount(); p++ )
96  {
97  tmp = this->GetData( i, p );
98  this->SetData( i, p, this->GetData( j, p ) );
99  this->SetData( j, p, tmp );
100  }
101  tmp = this->GetEventWeight(i);
102  this->SetEventWeight(i,this->GetEventWeight(j));
103  this->SetEventWeight(j,tmp);
104  }
105 }
106 
107 //EOF
TNeuralDataSet
Definition: TNeuralDataSet.h:26
TNeuralDataSet::mpShiftFactors
TVectorD * mpShiftFactors
Definition: TNeuralDataSet.h:62
TNeuralDataSet::Randomize
void Randomize(void)
Definition: TNeuralDataSet.cxx:74
TNeuralDataSet::SetData
void SetData(const Int_t aPattern, const Int_t aIndex, Double_t aValue)
Definition: TNeuralDataSet.cxx:37
TNeuralDataSet::TNeuralDataSet
TNeuralDataSet(Int_t aNumberOfPatterns=0, Int_t aNumberOfUnits=0)
TNeuralDataSet::GetData
Double_t GetData(const Int_t aPattern, const Int_t aIndex)
Definition: TNeuralDataSet.h:68
TNeuralDataSet::Shuffle
void Shuffle(Int_t aSeed=0)
Definition: TNeuralDataSet.cxx:85
TNeuralDataSet::GetPatternsCount
Int_t GetPatternsCount(void)
Definition: TNeuralDataSet.h:34
TNeuralDataSet::~TNeuralDataSet
virtual ~TNeuralDataSet(void)
Definition: TNeuralDataSet.cxx:23
ClassImp
ClassImp(TNeuralDataSet) TNeuralDataSet
Definition: TNeuralDataSet.cxx:8
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Random
Definition: TrigAnalysis/TrigInDetAnalysisUser/Resplot/src/Random.h:26
lumiFormat.i
int i
Definition: lumiFormat.py:85
met::Random
@ Random
Definition: IMETSignificance.h:27
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
TNeuralDataSet::SetEventWeight
void SetEventWeight(const Int_t aPattern, Double_t aValue)
Definition: TNeuralDataSet.cxx:32
a
TList * a
Definition: liststreamerinfos.cxx:10
TNeuralDataSet::GetEventWeight
Double_t GetEventWeight(const Int_t aPattern)
Definition: TNeuralDataSet.h:74
TNeuralDataSet::mpNormFactors
TVectorD * mpNormFactors
Definition: TNeuralDataSet.h:61
TNeuralDataSet::Normalize
void Normalize(void)
Definition: TNeuralDataSet.cxx:43
TNeuralDataSet.h
TNeuralDataSet::mpData
TMatrixD * mpData
Definition: TNeuralDataSet.h:55
TNeuralDataSet::GetUnitsCount
Int_t GetUnitsCount(void)
Definition: TNeuralDataSet.h:36
TNeuralDataSet::mpWeights
TVectorD * mpWeights
Definition: TNeuralDataSet.h:58