ATLAS Offline Software
Loading...
Searching...
No Matches
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//______________________________________________________________________________
10TNeuralDataSet::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//______________________________________________________________________________
32void TNeuralDataSet::SetEventWeight( const Int_t aPattern, Double_t aValue )
33{
34 mpWeights->operator() ( aPattern ) = aValue;
35}
36//______________________________________________________________________________
37void 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//______________________________________________________________________________
85void 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
static Double_t a
ClassImp(TNeuralDataSet) TNeuralDataSet
void SetEventWeight(const Int_t aPattern, Double_t aValue)
TVectorD * mpShiftFactors
Int_t GetUnitsCount(void)
TMatrixD * mpData
void SetData(const Int_t aPattern, const Int_t aIndex, Double_t aValue)
TVectorD * mpWeights
TVectorD * mpNormFactors
Double_t GetData(const Int_t aPattern, const Int_t aIndex)
Int_t GetPatternsCount(void)
void Normalize(void)
void Shuffle(Int_t aSeed=0)
void Randomize(void)
Double_t GetEventWeight(const Int_t aPattern)
virtual ~TNeuralDataSet(void)
TNeuralDataSet(Int_t aNumberOfPatterns=0, Int_t aNumberOfUnits=0)