48 : fTolerence(tolerence),
53 fLogger( new
MsgLogger(
"LDA", (debug?kINFO:kDEBUG)) )
70 Log() << kDEBUG <<
"There are: " << inputSignalEvents.size() <<
" input signal events " <<
Endl;
71 Log() << kDEBUG <<
"There are: " << inputBackgroundEvents.size() <<
" input background events " <<
Endl;
75 UInt_t numSignalEvents = inputSignalEvents.size();
76 UInt_t numBackEvents = inputBackgroundEvents.size();
77 UInt_t numTotalEvents = numSignalEvents + numBackEvents;
83 std::vector<Float_t> m_muSignal (
fNumParams,0.0);
84 std::vector<Float_t> m_muBackground (
fNumParams,0.0);
86 for (
UInt_t eventNumber=0; eventNumber < numSignalEvents; ++eventNumber)
87 m_muSignal[param] += inputSignalEvents[eventNumber][param];
88 for (
UInt_t eventNumber=0; eventNumber < numBackEvents; ++eventNumber)
89 m_muBackground[param] += inputBackgroundEvents[eventNumber][param]/numBackEvents;
90 if (numSignalEvents > 0) m_muSignal[param] /= numSignalEvents;
91 if (numBackEvents > 0 ) m_muBackground[param] /= numBackEvents;
93 fMu[0] = m_muBackground;
97 Log() << kDEBUG <<
"the signal means" <<
Endl;
99 Log() << kDEBUG << m_muSignal[param] <<
Endl;
100 Log() << kDEBUG <<
"the background means" <<
Endl;
101 for (
UInt_t param=0; param < inputBackgroundEvents[0].size(); ++param)
102 Log() << kDEBUG << m_muBackground[param] <<
Endl;
109 TMatrixF sigmaSignal(fNumParams, fNumParams);
110 TMatrixF sigmaBack(fNumParams, fNumParams);
115 sigmaSignal[row][col] = 0;
116 sigmaBack[row][col] = 0;
117 (*fSigma)[row][col] = 0;
121 for (
UInt_t eventNumber=0; eventNumber < numSignalEvents; ++eventNumber) {
124 sigmaSignal[row][col] += (inputSignalEvents[eventNumber][row] - m_muSignal[row]) * (inputSignalEvents[eventNumber][col] - m_muSignal[col] );
129 for (
UInt_t eventNumber=0; eventNumber < numBackEvents; ++eventNumber) {
132 sigmaBack[row][col] += (inputBackgroundEvents[eventNumber][row] - m_muBackground[row]) * (inputBackgroundEvents[eventNumber][col] - m_muBackground[col] );
138 *
fSigma = sigmaBack + sigmaSignal;
139 *
fSigma *= 1.0/(numTotalEvents -
K);
142 Log() <<
"after filling sigmaSignal" <<
Endl;
144 Log() <<
"after filling sigmaBack" <<
Endl;
146 Log() <<
"after filling total Sigma" <<
Endl;
152 TMatrixF diag ( fNumParams, fNumParams );
153 TMatrixF uTrans( fNumParams, fNumParams );
154 TMatrixF vTrans( fNumParams, fNumParams );
158 diag(i,i) = solutionSVD.
GetSig()[i];
164 Log() <<
"the diagonal" <<
Endl;
168 decomposed = solutionSVD.
GetV();
170 decomposed *= solutionSVD.
GetU();
173 Log() <<
"the decomposition " <<
Endl;
182 Log() <<
"the SigmaInverse " <<
Endl;
193 Log() <<
"problem, i= "<< i <<
" j= " << j <<
Endl;
194 Log() <<
"Sigma(i,j)= "<< (*fSigma)(i,j) <<
" SigmaInverse(i,j)= " << (*
fSigmaInverse)(i,j) <<Endl;
200 if (problem)
Log() << kWARNING <<
"Problem with the inversion!" <<
Endl;
214 std::vector<Float_t> m_transPoseTimesSigmaInverse;
221 m_transPoseTimesSigmaInverse.push_back(m_temp);
226 exponent += m_transPoseTimesSigmaInverse[i]*(x[i] -
fMu[k][i]);
244 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.
constexpr Double_t TwoPi()
TMatrixT< Float_t > TMatrixF
std::map< Int_t, std::vector< Float_t > > fMu
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
virtual Double_t Determinant() const
Return the matrix determinant.
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 ...
static const uint32_t K[64]
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.
ostringstream derivative to redirect and format output
void Print(Option_t *name="") const
Print the matrix as a table of elements.
std::vector< std::vector< Float_t > > LDAEvents
Double_t Sqrt(Double_t x)