32 #ifndef ROOT_TDecompSVD 42 #ifndef ROOT_TMVA_Types 45 #ifndef ROOT_TMVA_MsgLogger 53 : fTolerence(tolerence),
75 Log() <<
kDEBUG <<
"There are: " << inputSignalEvents.size() <<
" input signal events " <<
Endl;
76 Log() <<
kDEBUG <<
"There are: " << inputBackgroundEvents.size() <<
" input background events " <<
Endl;
80 UInt_t numSignalEvents = inputSignalEvents.size();
81 UInt_t numBackEvents = inputBackgroundEvents.size();
82 UInt_t numTotalEvents = numSignalEvents + numBackEvents;
88 std::vector<Float_t> m_muSignal (
fNumParams,0.0);
89 std::vector<Float_t> m_muBackground (
fNumParams,0.0);
91 for (
UInt_t eventNumber=0; eventNumber < numSignalEvents; ++eventNumber)
92 m_muSignal[param] += inputSignalEvents[eventNumber][param];
93 for (
UInt_t eventNumber=0; eventNumber < numBackEvents; ++eventNumber)
94 m_muBackground[param] += inputBackgroundEvents[eventNumber][param]/numBackEvents;
95 if (numSignalEvents > 0) m_muSignal[param] /= numSignalEvents;
96 if (numBackEvents > 0 ) m_muBackground[param] /= numBackEvents;
98 fMu[0] = m_muBackground;
106 for (
UInt_t param=0; param < inputBackgroundEvents[0].size(); ++param)
114 TMatrixF sigmaSignal(fNumParams, fNumParams);
115 TMatrixF sigmaBack(fNumParams, fNumParams);
120 sigmaSignal[row][col] = 0;
121 sigmaBack[row][col] = 0;
122 (*fSigma)[row][col] = 0;
126 for (
UInt_t eventNumber=0; eventNumber < numSignalEvents; ++eventNumber) {
129 sigmaSignal[row][col] += (inputSignalEvents[eventNumber][row] - m_muSignal[row]) * (inputSignalEvents[eventNumber][col] - m_muSignal[col] );
134 for (
UInt_t eventNumber=0; eventNumber < numBackEvents; ++eventNumber) {
137 sigmaBack[row][col] += (inputBackgroundEvents[eventNumber][row] - m_muBackground[row]) * (inputBackgroundEvents[eventNumber][col] - m_muBackground[col] );
143 *
fSigma = sigmaBack + sigmaSignal;
144 *
fSigma *= 1.0/(numTotalEvents -
K);
147 Log() <<
"after filling sigmaSignal" <<
Endl;
149 Log() <<
"after filling sigmaBack" <<
Endl;
151 Log() <<
"after filling total Sigma" <<
Endl;
157 TMatrixF diag ( fNumParams, fNumParams );
158 TMatrixF uTrans( fNumParams, fNumParams );
159 TMatrixF vTrans( fNumParams, fNumParams );
163 diag(i,i) = solutionSVD.
GetSig()[i];
169 Log() <<
"the diagonal" <<
Endl;
173 decomposed = solutionSVD.
GetV();
175 decomposed *= solutionSVD.
GetU();
178 Log() <<
"the decomposition " <<
Endl;
187 Log() <<
"the SigmaInverse " <<
Endl;
198 Log() <<
"problem, i= "<< i <<
" j= " << j <<
Endl;
199 Log() <<
"Sigma(i,j)= "<< (*fSigma)(i,j) <<
" SigmaInverse(i,j)= " << (*
fSigmaInverse)(i,j) <<Endl;
205 if (problem)
Log() <<
kWARNING <<
"Problem with the inversion!" <<
Endl;
219 std::vector<Float_t> m_transPoseTimesSigmaInverse;
226 m_transPoseTimesSigmaInverse.push_back(m_temp);
231 exponent += m_transPoseTimesSigmaInverse[i]*(x[i] -
fMu[k][i]);
249 return m_numerator/m_denominator;
LDA(Float_t tolerence=1.0e-5, Bool_t debug=false)
constructor
Float_t FSub(const std::vector< Float_t > &x, Int_t k)
Probability value using Gaussian approximation.
const TVectorD & GetSig()
MsgLogger & Endl(MsgLogger &ml)
TMatrixT< Element > & Transpose(const TMatrixT< Element > &source)
Transpose matrix source.
TMatrixT< Float_t > TMatrixF
std::map< Int_t, std::vector< Float_t > > fMu
Single Value Decomposition class.
Float_t GetProb(const std::vector< Float_t > &x, Int_t k)
Signal probability with Gaussian approximation.
std::map< Int_t, Float_t > fEventFraction
TMatrixT< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant.
virtual Bool_t Decompose()
SVD decomposition of matrix If the decomposition succeeds, bit kDecomposed is set ...
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
void Print(Option_t *name="") const
Print the matrix as a table of elements.
Float_t GetLogLikelihood(const std::vector< Float_t > &x, Int_t k)
Log likelihood function with Gaussian approximation.
void Initialize(const LDAEvents &inputSignal, const LDAEvents &inputBackground)
Create LDA matrix using local events found by knn method.
std::vector< std::vector< Float_t > > LDAEvents
virtual Double_t Determinant() const
Return the matrix determinant.
Double_t Sqrt(Double_t x)