Belle II Software  release-08-01-10
Priors Class Reference

Public Member Functions

def __init__ (self, list particlelist, str Model, str prescaling=None)
 
def calculate_priors (self, np.array momentum, np.array cosTheta)
 
np.array get_priors (self, int pdg=None)
 
np.array get_posterior (self, int pid, int pdg=None)
 

Public Attributes

 model
 The torch model for prior calculation.
 
 scale
 Temperature scaling object for calibration.
 
 require_scale
 True if the scaling object exist. More...
 
 plist
 Sorted particle PDG list.
 
 prior
 Numpy array containing PID prior probability data.
 

Detailed Description

Class to calculate PID prior probabilities and posteriors.

Attributes:
    model(PriorModel): The trained model to be used for evaluation.
    plist(np.array): List of particle PDGs for which the model was trained.
    require_scale(bool): True if a scaling file is provided or else False.
    scale(TemperatureScaling) (optional): Calibration object constructed for temperature scaling.

Definition at line 72 of file evalPriors.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
list  particlelist,
str  Model,
str   prescaling = None 
)
Initialize the Priors class.

Parameters:
    particlelist(list(int)): List of PDG values for which the model was trained.
    Model(str): Path to a previously trained model which will be used to calculate priors.
    prescaling(str) (optional): Path to the scaling file created while training the model.

Definition at line 83 of file evalPriors.py.

83  def __init__(self, particlelist: list, Model: str, prescaling: str = None):
84  """
85  Initialize the Priors class.
86 
87  Parameters:
88  particlelist(list(int)): List of PDG values for which the model was trained.
89  Model(str): Path to a previously trained model which will be used to calculate priors.
90  prescaling(str) (optional): Path to the scaling file created while training the model.
91  """
92  model = PriorModel(len(particlelist))
93  model.load_state_dict(torch.load(Model))
94  model.eval()
95  if torch.cuda.is_available():
96  model = model.to("cuda")
97 
98  self.model = model
99  if prescaling is not None:
100  scale = scaling(prescaling)
101 
102  self.scale = scale
103 
104  self.require_scale = True
105  else:
106 
107  self.require_scale = False
108 
109  self.plist = np.sort(particlelist)
110 

Member Function Documentation

◆ calculate_priors()

def calculate_priors (   self,
np.array  momentum,
np.array  cosTheta 
)
Calculates priors for given momentum and cos(theta).

Parameters:
    momentum(np.array): A numpy array containing the momentum of particles.
    cosTheta(np.array): A numpy array containing the cosTheta information of particles.

Returns:
    None.

Definition at line 111 of file evalPriors.py.

◆ get_posterior()

np.array get_posterior (   self,
int  pid,
int   pdg = None 
)
Get PID posterior probabilities.

Parameters:
    pid(np.array): The PID values for the particles used during training process arranged in ascending order of PDG values.
    pdg(int) (optional): PDG value of particle for which posterior is required.

Returns:
    A 1D array of posterior probabilities in case PDG value is provided else returns a 2D array containing
    the posteriors for all particles.

Definition at line 152 of file evalPriors.py.

◆ get_priors()

np.array get_priors (   self,
int   pdg = None 
)
Gives the calculated PID priors.

Parameters:
    pdg(int) (optional): The PDG value of the particles for which prior probabilities are needed.

Returns:
    A 1D array conatining prior probabilities for required particle in case PDG value is specified;
    else it will return a 2D array for all particles that were used during training.

Definition at line 135 of file evalPriors.py.

Member Data Documentation

◆ require_scale

require_scale

True if the scaling object exist.

False if the scaling object doesn't exist.

Definition at line 104 of file evalPriors.py.


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