Belle II Software light-2406-ragdoll
Prior Class Reference

Public Member Functions

def __init__ (self, z, y)
 
def get_signal_pdf (self, X)
 
def get_bckgrd_pdf (self, X)
 
def get_signal_cdf (self, X)
 
def get_bckgrd_cdf (self, X)
 
def get_prior (self, X)
 
def get_boost_weights (self, X)
 
def get_uncorrelation_weights (self, X, boost_prediction)
 

Public Attributes

 signal_bins
 signal cdf, pdf and binning
 
 bckgrd_bins
 background cdf, pdf and binning
 

Detailed Description

Calculates prior from signal and background pdfs of the fit variable

Definition at line 19 of file dplot.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  z,
  y 
)
Constructor of a new prior distribution
    @param z fit variable
    @param y target variable

Definition at line 24 of file dplot.py.

24 def __init__(self, z, y):
25 """
26 Constructor of a new prior distribution
27 @param z fit variable
28 @param y target variable
29 """
30
31 self.signal_cdf, self.signal_pdf, self.signal_bins = calculate_cdf_and_pdf(z[y == 1])
32
33 self.bckgrd_cdf, self.bckgrd_pdf, self.bckgrd_bins = calculate_cdf_and_pdf(z[y == 0])
34 # Avoid numerical instabilities
35 self.bckgrd_pdf[0] = self.bckgrd_pdf[-1] = 1
36

Member Function Documentation

◆ get_bckgrd_cdf()

def get_bckgrd_cdf (   self,
  X 
)
Calculate background cdf for given fit variable value
    @param X nd-array containing fit variable values

Definition at line 58 of file dplot.py.

58 def get_bckgrd_cdf(self, X):
59 """
60 Calculate background cdf for given fit variable value
61 @param X nd-array containing fit variable values
62 """
63 return self.bckgrd_cdf[np.digitize(X, bins=self.bckgrd_bins)]
64

◆ get_bckgrd_pdf()

def get_bckgrd_pdf (   self,
  X 
)
Calculate background pdf for given fit variable value
    @param X nd-array containing fit variable values

Definition at line 44 of file dplot.py.

44 def get_bckgrd_pdf(self, X):
45 """
46 Calculate background pdf for given fit variable value
47 @param X nd-array containing fit variable values
48 """
49 return self.bckgrd_pdf[np.digitize(X, bins=self.bckgrd_bins)]
50

◆ get_boost_weights()

def get_boost_weights (   self,
  X 
)
Calculate boost weights used in dplot boost training step
    @param X nd-array containing fit variable values

Definition at line 74 of file dplot.py.

74 def get_boost_weights(self, X):
75 """
76 Calculate boost weights used in dplot boost training step
77 @param X nd-array containing fit variable values
78 """
79 signal_weight = self.get_signal_cdf(X) / self.get_bckgrd_pdf(X)
80 signal_weight = np.where(np.isfinite(signal_weight), signal_weight, 0)
81 # NOT self.get_bckgrd_cdf() here, signal and background are handled asymmetrical!
82 bckgrd_weight = (1.0 - self.get_signal_cdf(X)) / self.get_bckgrd_pdf(X)
83 bckgrd_weight = np.where(np.isfinite(bckgrd_weight), bckgrd_weight, 0)
84 return np.r_[signal_weight, bckgrd_weight]
85

◆ get_prior()

def get_prior (   self,
  X 
)
Calculate prior signal probability for given fit variable value
    @param X nd-array containing fit variable values

Definition at line 65 of file dplot.py.

65 def get_prior(self, X):
66 """
67 Calculate prior signal probability for given fit variable value
68 @param X nd-array containing fit variable values
69 """
70 prior = self.get_signal_pdf(X) / (self.get_signal_pdf(X) + self.get_bckgrd_pdf(X))
71 prior = np.where(np.isfinite(prior), prior, 0.5)
72 return prior
73

◆ get_signal_cdf()

def get_signal_cdf (   self,
  X 
)
Calculate signal cdf for given fit variable value
    @param X nd-array containing fit variable values

Definition at line 51 of file dplot.py.

51 def get_signal_cdf(self, X):
52 """
53 Calculate signal cdf for given fit variable value
54 @param X nd-array containing fit variable values
55 """
56 return self.signal_cdf[np.digitize(X, bins=self.signal_bins)]
57

◆ get_signal_pdf()

def get_signal_pdf (   self,
  X 
)
Calculate signal pdf for given fit variable value
    @param X nd-array containing fit variable values

Definition at line 37 of file dplot.py.

37 def get_signal_pdf(self, X):
38 """
39 Calculate signal pdf for given fit variable value
40 @param X nd-array containing fit variable values
41 """
42 return self.signal_pdf[np.digitize(X, bins=self.signal_bins)]
43

◆ get_uncorrelation_weights()

def get_uncorrelation_weights (   self,
  X,
  boost_prediction 
)
Calculate uncorrelation weights used in dplot classifier training step
    @param X nd-array containing fit variable values
    @param boost_prediction output of the boost classifier

Definition at line 86 of file dplot.py.

86 def get_uncorrelation_weights(self, X, boost_prediction):
87 """
88 Calculate uncorrelation weights used in dplot classifier training step
89 @param X nd-array containing fit variable values
90 @param boost_prediction output of the boost classifier
91 """
92 reg_boost_prediction = boost_prediction * 0.99 + 0.005
93 weights = (self.get_signal_cdf(X) / reg_boost_prediction +
94 (1.0 - self.get_signal_cdf(X)) / (1.0 - reg_boost_prediction)) / 2
95 return weights
96
97

Member Data Documentation

◆ bckgrd_bins

bckgrd_bins

background cdf, pdf and binning

Definition at line 33 of file dplot.py.

◆ signal_bins

signal_bins

signal cdf, pdf and binning

Definition at line 31 of file dplot.py.


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