Belle II Software  light-2212-foldex
Method Class Reference
Inheritance diagram for Method:
Collaboration diagram for Method:

Public Member Functions

def __init__ (self, identifier)
 
def train_teacher (self, datafiles, treename, general_options=None, specific_options=None)
 
def apply_expert (self, datafiles, treename)
 

Public Attributes

 identifier
 Identifier of the method.
 
 weightfile
 Weightfile of the method.
 
 general_options
 General options of the method.
 
 specific_options
 Specific options of the method.
 
 importances
 Dictionary of the variable importances calculated by the method.
 
 variables
 List of variables sorted by their importance.
 
 root_variables
 List of the variable importances calculated by the method, but with the root compatible variable names.
 
 root_importances
 Dictionary of the variables sorted by their importance but with root compatoble variable names.
 
 description
 Description of the method as a xml string returned by basf2_mva.info.
 
 spectators
 List of spectators.
 
 root_spectators
 List of spectators with root compatible names.
 

Detailed Description

Wrapper class providing an interface to the method stored under the given identifier.
It loads the Options, can apply the expert and train new ones using the current as a prototype.
This class is used by the basf_mva_evaluation tools

Definition at line 128 of file basf2_mva_util.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  identifier 
)
Load a method stored under the given identifier
@param identifier identifying the method

Definition at line 135 of file basf2_mva_util.py.

135  def __init__(self, identifier):
136  """
137  Load a method stored under the given identifier
138  @param identifier identifying the method
139  """
140  # Always avoid the top-level 'import ROOT'.
141  import ROOT # noqa
142  # Initialize all the available interfaces
143  ROOT.Belle2.MVA.AbstractInterface.initSupportedInterfaces()
144 
145  self.identifier = identifier
146 
147  self.weightfile = ROOT.Belle2.MVA.Weightfile.load(self.identifier)
148 
149  self.general_options = basf2_mva.GeneralOptions()
150  self.general_options.load(self.weightfile.getXMLTree())
151 
152  # This piece of code should be correct but leads to random segmentation faults
153  # inside python, llvm or pyroot, therefore we use the more dirty code below
154  # Ideas why this is happening:
155  # 1. Ownership of the unique_ptr returned by getOptions()
156  # 2. Some kind of object slicing, although pyroot identifies the correct type
157  # 3. Bug in pyroot
158  # interfaces = ROOT.Belle2.MVA.AbstractInterface.getSupportedInterfaces()
159  # self.interface = interfaces[self.general_options.m_method]
160  # self.specific_options = self.interface.getOptions()
161 
162 
163  self.specific_options = None
164  if self.general_options.m_method == "FastBDT":
165  self.specific_options = basf2_mva.FastBDTOptions()
166  elif self.general_options.m_method == "TMVAClassification":
167  self.specific_options = basf2_mva.TMVAOptionsClassification()
168  elif self.general_options.m_method == "TMVARegression":
169  self.specific_options = basf2_mva.TMVAOptionsRegression()
170  elif self.general_options.m_method == "FANN":
171  self.specific_options = basf2_mva.FANNOptions()
172  elif self.general_options.m_method == "Python":
173  self.specific_options = basf2_mva.PythonOptions()
174  elif self.general_options.m_method == "PDF":
175  self.specific_options = basf2_mva.PDFOptions()
176  elif self.general_options.m_method == "Combination":
177  self.specific_options = basf2_mva.CombinationOptions()
178  elif self.general_options.m_method == "Reweighter":
179  self.specific_options = basf2_mva.ReweighterOptions()
180  elif self.general_options.m_method == "Trivial":
181  self.specific_options = basf2_mva.TrivialOptions()
182  else:
183  raise RuntimeError("Unknown method " + self.general_options.m_method)
184 
185  self.specific_options.load(self.weightfile.getXMLTree())
186 
187  variables = [str(v) for v in self.general_options.m_variables]
188  importances = self.weightfile.getFeatureImportance()
189 
190 
191  self.importances = {k: importances[k] for k in variables}
192 
193  self.variables = list(sorted(variables, key=lambda v: self.importances.get(v, 0.0)))
194 
195  self.root_variables = [ROOT.Belle2.MakeROOTCompatible.makeROOTCompatible(v) for v in self.variables]
196 
197  self.root_importances = {k: importances[k] for k in self.root_variables}
198 
199  self.description = str(basf2_mva.info(self.identifier))
200 
201  self.spectators = [str(v) for v in self.general_options.m_spectators]
202 
203  self.root_spectators = [ROOT.Belle2.MakeROOTCompatible.makeROOTCompatible(v) for v in self.spectators]
204 

Member Function Documentation

◆ apply_expert()

def apply_expert (   self,
  datafiles,
  treename 
)
Apply the expert of the method to data and return the calculated probability and the target
@param datafiles the datafiles
@param treename the name of the tree containing the data

Definition at line 235 of file basf2_mva_util.py.

◆ train_teacher()

def train_teacher (   self,
  datafiles,
  treename,
  general_options = None,
  specific_options = None 
)
Train a new method using this method as a prototype
@param datafiles the training datafiles
@param treename the name of the tree containing the training data
@param general_options general options given to basf2_mva.teacher
  (if None the options of this method are used)
@param specific_options specific options given to basf2_mva.teacher
  (if None the options of this method are used)

Definition at line 205 of file basf2_mva_util.py.


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