Belle II Software development
CutAtBackgroundRejectionClassifier Class Reference
Inheritance diagram for CutAtBackgroundRejectionClassifier:
CutClassifier

Public Member Functions

 __init__ (self, background_rejection=0.5, cut_direction=1)
 
 determine_cut_value (self, estimates, truths)
 
 cut_direction (self)
 
 cut_value (self)
 
 clone (self)
 
 fit (self, estimates, truths)
 
 predict (self, estimates)
 
 describe (self, estimates, truths)
 

Public Attributes

 background_rejection = background_rejection
 cachec copy of the background-rejection threshold
 
 cut_direction_ = cut_direction
 cached copy of the cut direction (< or >)
 
 cut_value_ = cut_value
 cached copy of the cut threshold
 

Detailed Description

Apply cut on the background rejection

Definition at line 564 of file classification.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
background_rejection = 0.5,
cut_direction = 1 )
Constructor

Definition at line 567 of file classification.py.

567 def __init__(self, background_rejection=0.5, cut_direction=1):
568 """Constructor"""
569 super().__init__(cut_direction=cut_direction, cut_value=np.nan)
570 ## cachec copy of the background-rejection threshold
571 self.background_rejection = background_rejection
572

Member Function Documentation

◆ clone()

clone ( self)
inherited
Return a clone of this object

Definition at line 517 of file classification.py.

517 def clone(self):
518 """Return a clone of this object"""
519 return copy.copy(self)
520

◆ cut_direction()

cut_direction ( self)
inherited
Get the value of the cut direction

Definition at line 508 of file classification.py.

508 def cut_direction(self):
509 """Get the value of the cut direction"""
510 return self.cut_direction_
511

◆ cut_value()

cut_value ( self)
inherited
Get the value of the cut threshold

Definition at line 513 of file classification.py.

513 def cut_value(self):
514 """Get the value of the cut threshold"""
515 return self.cut_value_
516

◆ describe()

describe ( self,
estimates,
truths )
inherited
Describe the cut selection and its efficiency, purity and background rejection

Definition at line 542 of file classification.py.

542 def describe(self, estimates, truths):
543 """Describe the cut selection and its efficiency, purity and background rejection"""
544 if self.cut_direction_ < 0:
545 print("Cut accepts >= ", self.cut_value_, 'with')
546 else:
547 print("Cut accepts <= ", self.cut_value_, 'with')
548
549 binary_estimates = self.predict(estimates)
550
551 efficiency = scores.efficiency(truths, binary_estimates)
552 purity = scores.purity(truths, binary_estimates)
553 background_rejection = scores.background_rejection(truths, binary_estimates)
554
555 print("efficiency", efficiency)
556 print("purity", purity)
557 print("background_rejection", background_rejection)
558
559

◆ determine_cut_value()

determine_cut_value ( self,
estimates,
truths )
Find the cut value that satisfies the desired background-rejection level

Reimplemented from CutClassifier.

Definition at line 573 of file classification.py.

573 def determine_cut_value(self, estimates, truths):
574 """Find the cut value that satisfies the desired background-rejection level"""
575 n_data = len(estimates)
576 n_signals = scores.signal_amount(truths, estimates)
577 n_bkgs = n_data - n_signals
578
579 sorting_indices = np.argsort(estimates)
580 if self.cut_direction_ < 0: # reject low
581 # Keep a reference to keep the content alive
582 original_sorting_indices = sorting_indices # noqa
583 sorting_indices = sorting_indices[::-1]
584
585 sorted_truths = truths[sorting_indices]
586 sorted_estimates = estimates[sorting_indices]
587
588 sorted_n_accepted_signals = np.cumsum(sorted_truths, dtype=float)
589 # sorted_efficiencies = sorted_n_accepted_signals / n_signals
590
591 sorted_n_rejected_signals = n_signals - sorted_n_accepted_signals
592 sorted_n_rejects = np.arange(len(estimates) + 1, 1, -1)
593 sorted_n_rejected_bkgs = sorted_n_rejects - sorted_n_rejected_signals
594 sorted_bkg_rejections = sorted_n_rejected_bkgs / n_bkgs
595
596 cut_index, = np.searchsorted(sorted_bkg_rejections[::-1], (self.background_rejection,), side='right')
597
598 cut_value = sorted_estimates[-cut_index - 1]
599 return cut_value

◆ fit()

fit ( self,
estimates,
truths )
inherited
Fit to determine the cut threshold

Definition at line 525 of file classification.py.

525 def fit(self, estimates, truths):
526 """Fit to determine the cut threshold"""
527 self.cut_value_ = self.determine_cut_value(estimates, truths)
528 return self
529

◆ predict()

predict ( self,
estimates )
inherited
Select estimates that satisfy the cut

Definition at line 530 of file classification.py.

530 def predict(self, estimates):
531 """Select estimates that satisfy the cut"""
532 if self.cut_value_ is None:
533 raise ValueError("Cut value not set. Forgot to fit?")
534
535 if self.cut_direction_ < 0:
536 binary_estimates = estimates >= self.cut_value_
537 else:
538 binary_estimates = estimates <= self.cut_value_
539
540 return binary_estimates
541

Member Data Documentation

◆ background_rejection

background_rejection = background_rejection

cachec copy of the background-rejection threshold

Definition at line 571 of file classification.py.

◆ cut_direction_

cut_direction_ = cut_direction
inherited

cached copy of the cut direction (< or >)

Definition at line 503 of file classification.py.

◆ cut_value_

cut_value_ = cut_value
inherited

cached copy of the cut threshold

Definition at line 505 of file classification.py.


The documentation for this class was generated from the following file: