132 std::vector<TMVA::SVEvent*>::iterator idIter;
136 if((*idIter)->GetAlpha()>0)
137 fErrorC_J += (*idIter)->GetAlpha()*(*idIter)->GetTypeFlag()*fKVals[k];
149 else if ((jevt->
GetIdx() == -1)&&(fErrorC_J >
fB_low)) {
166 if (converged)
return kFALSE;
182 if (ievt == jevt)
return kFALSE;
183 std::vector<TMVA::SVEvent*>::iterator idIter;
190 Float_t newAlpha_I, newAlpha_J;
204 s =
Int_t( type_I * type_J );
212 if (type_I == type_J) {
246 if ( gamma >= (c_i - c_j) )
253 if ( (c_i - c_j) >= gamma)
260 if (l == h)
return kFALSE;
261 Float_t kernel_II, kernel_IJ, kernel_JJ;
267 eta = 2*kernel_IJ - kernel_II - kernel_JJ;
269 newAlpha_J = alpha_J + (type_J*( errorC_J - errorC_I ))/eta;
270 if (newAlpha_J < l) newAlpha_J =
l;
271 else if (newAlpha_J > h) newAlpha_J =
h;
278 Float_t c_J = type_J*( errorC_I - errorC_J ) - eta * alpha_J;
279 lobj = c_I * l * l + c_J *
l;
280 hobj = c_I * h * h + c_J *
h;
282 if (lobj > hobj + epsilon) newAlpha_J =
l;
283 else if (lobj < hobj - epsilon) newAlpha_J =
h;
284 else newAlpha_J = alpha_J;
287 if (
TMath::Abs( newAlpha_J - alpha_J ) < ( epsilon * ( newAlpha_J + alpha_J+
epsilon ))){
291 newAlpha_I = alpha_I - s*( newAlpha_J - alpha_J );
293 if (newAlpha_I < 0) {
294 newAlpha_J += s* newAlpha_I;
297 else if (newAlpha_I > c_i) {
298 Float_t temp = newAlpha_I - c_i;
299 newAlpha_J += s * temp;
303 Float_t dL_I = type_I * ( newAlpha_I - alpha_I );
304 Float_t dL_J = type_J * ( newAlpha_J - alpha_J );
309 if((*idIter)->GetIdx()==0){
313 (*idIter)->UpdateErrorCache(dL_I * ii + dL_J * jj);
323 ievt->
SetErrorCache(errorC_I + dL_I*kernel_II + dL_J*kernel_IJ);
324 jevt->
SetErrorCache(errorC_J + dL_I*kernel_IJ + dL_J*kernel_JJ);
332 if((*idIter)->GetIdx()==0){
333 if((*idIter)->GetErrorCache()>
fB_low){
334 fB_low = (*idIter)->GetErrorCache();
337 if( (*idIter)->GetErrorCache()<
fB_up){
338 fB_up =(*idIter)->GetErrorCache();
383 Int_t numChanged = 0;
384 Int_t examineAll = 1;
387 Int_t deltaChanges = 0;
390 std::vector<TMVA::SVEvent*>::iterator idIter;
392 while ((numChanged > 0) || (examineAll > 0)) {
404 if ((*idIter)->IsInI0()) {
415 if (examineAll == 1) examineAll = 0;
416 else if (numChanged == 0 || numChanged < 10 || deltaChanges > 3 ) examineAll = 1;
418 if (numChanged == numChangedOld) deltaChanges++;
419 else deltaChanges = 0;
420 numChangedOld = numChanged;
423 if (numit >= nMaxIter) {
425 <<
"Max number of iterations exceeded. " 426 <<
"Training may not be completed. Try use less Cost parameter" <<
Endl;
442 else if( event->
GetAlpha() ==
event->GetCweight() )
448 else if( event->
GetAlpha() ==
event->GetCweight() )
457 std::vector<TMVA::SVEvent*>::iterator idIter;
460 if((*idIter)->GetAlpha() !=0) counter++;
467 std::vector<TMVA::SVEvent*>::iterator idIter;
469 fSupVec =
new std::vector<TMVA::SVEvent*>(0);
472 if((*idIter)->GetDeltaAlpha() !=0){
483 if (ievt == jevt)
return kFALSE;
484 std::vector<TMVA::SVEvent*>::iterator idIter;
492 const Float_t eta = -2*kernel_IJ + kernel_II + kernel_JJ;
498 Bool_t caseA, caseB, caseC, caseD, terminated;
499 caseA = caseB = caseC = caseD = terminated =
kFALSE;
500 Float_t b_alpha_i, b_alpha_j, b_alpha_i_p, b_alpha_j_p;
516 Float_t tmp_alpha_i, tmp_alpha_j;
517 tmp_alpha_i = tmp_alpha_j = 0.;
520 if((caseA ==
kFALSE) && (b_alpha_i > 0 || (b_alpha_i_p == 0 && deltafi > 0)) && (b_alpha_j > 0 || (b_alpha_j_p == 0 && deltafi < 0)))
527 tmp_alpha_j = b_alpha_j - (deltafi/eta);
530 tmp_alpha_i = b_alpha_i - (tmp_alpha_j - b_alpha_j);
534 b_alpha_j = tmp_alpha_j;
535 b_alpha_i = tmp_alpha_i;
544 else if((caseB==
kFALSE) && (b_alpha_i>0 || (b_alpha_i_p==0 && deltafi >2*
epsilon )) && (b_alpha_j_p>0 || (b_alpha_j==0 && deltafi>2*
epsilon)))
548 high =
TMath::Min( b_cost_i , b_cost_j + gamma);
552 tmp_alpha_j = b_alpha_j_p - ((deltafi-2*
epsilon)/eta);
555 tmp_alpha_i = b_alpha_i - (tmp_alpha_j - b_alpha_j_p);
559 b_alpha_j_p = tmp_alpha_j;
560 b_alpha_i = tmp_alpha_i;
568 else if((caseC==
kFALSE) && (b_alpha_i_p>0 || (b_alpha_i==0 && deltafi < -2*
epsilon )) && (b_alpha_j>0 || (b_alpha_j_p==0 && deltafi< -2*
epsilon)))
575 tmp_alpha_j = b_alpha_j - ((deltafi+2*
epsilon)/eta);
578 tmp_alpha_i = b_alpha_i_p - (tmp_alpha_j - b_alpha_j);
582 b_alpha_j = tmp_alpha_j;
583 b_alpha_i_p = tmp_alpha_i;
591 else if((caseD ==
kFALSE) &&
592 (b_alpha_i_p>0 || (b_alpha_i==0 && deltafi <0 )) &&
593 (b_alpha_j_p>0 || (b_alpha_j==0 && deltafi >0 )))
600 tmp_alpha_j = b_alpha_j_p + (deltafi/eta);
603 tmp_alpha_i = b_alpha_i_p - (tmp_alpha_j - b_alpha_j_p);
606 b_alpha_j_p = tmp_alpha_j;
607 b_alpha_i_p = tmp_alpha_i;
636 if((*idIter)->GetIdx()==0){
640 (*idIter)->UpdateErrorCache(diff_alpha_i * k_ii + diff_alpha_j * k_jj);
658 if((!(*idIter)->IsInI3()) && ((*idIter)->GetErrorCache()>
fB_low)){
659 fB_low = (*idIter)->GetErrorCache();
663 if((!(*idIter)->IsInI2()) && ((*idIter)->GetErrorCache()<
fB_up)){
664 fB_up =(*idIter)->GetErrorCache();
686 std::vector<TMVA::SVEvent*>::iterator idIter;
690 fErrorC_J -= (*idIter)->GetDeltaAlpha()*fKVals[k];
698 if(fErrorC_J + feps <
fB_up ){
699 fB_up = fErrorC_J + feps;
702 else if(fErrorC_J -feps >
fB_low) {
703 fB_low = fErrorC_J - feps;
706 }
else if((jevt->
IsInI2()) && (fErrorC_J + feps >
fB_low)){
707 fB_low = fErrorC_J + feps;
709 }
else if((jevt->
IsInI3()) && (fErrorC_J - feps <
fB_up)){
710 fB_up = fErrorC_J - feps;
727 if(
fB_low - fErrorC_J+feps > fErrorC_J-feps -
fB_up){
744 if(
fB_low - fErrorC_J-feps > fErrorC_J+feps -
fB_up){
761 if(
fB_low - fErrorC_J+feps > fErrorC_J-feps -
fB_up){
783 if(converged)
return kFALSE;
Random number generator class based on M.
MsgLogger & Endl(MsgLogger &ml)
Float_t * GetLine(UInt_t)
returns a row of the kernel matrix
void SetAlpha(Float_t alpha)
~SVWorkingSet()
destructor
SVWorkingSet()
constructor
std::vector< TMVA::SVEvent * > * fSupVec
void SetIndex(TMVA::SVEvent *)
void Train(UInt_t nIter=1000)
train the SVM
Short_t Min(Short_t a, Short_t b)
Bool_t TakeStep(SVEvent *, SVEvent *)
Float_t GetCweight() const
void SetErrorCache(Float_t err_cache)
Float_t * GetLine() const
Float_t GetElement(UInt_t i, UInt_t j)
returns an element of the kernel matrix
SVKernelFunction * fKFunction
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
Float_t GetAlpha_p() const
Bool_t ExamineExampleReg(SVEvent *)
Float_t GetErrorCache() const
Int_t GetTypeFlag() const
Float_t GetDeltaAlpha() const
Bool_t ExamineExample(SVEvent *)
Bool_t TakeStepReg(SVEvent *, SVEvent *)
std::vector< TMVA::SVEvent * > * GetSupportVectors()
Float_t GetTarget() const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
SVKernelMatrix * fKMatrix
Bool_t IsDiffSignificant(Float_t, Float_t, Float_t)
Short_t Max(Short_t a, Short_t b)
void SetAlpha_p(Float_t alpha)
std::vector< TMVA::SVEvent * > * fInputData
UInt_t * fIPyCurrentIter
message logger