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:
581
582 original_sorting_indices = sorting_indices
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
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