Belle II Software development
FastBDTExpert Class Reference

Expert for the FastBDT MVA method. More...

#include <FastBDT.h>

Inheritance diagram for FastBDTExpert:
Expert

Public Member Functions

virtual void load (Weightfile &weightfile) override
 Load the expert from a Weightfile.
 
virtual std::vector< float > apply (Dataset &test_data) const override
 Apply this expert onto a dataset.
 
virtual std::vector< std::vector< float > > applyMulticlass (Dataset &test_data) const
 Apply this m_expert onto a dataset.
 

Protected Attributes

GeneralOptions m_general_options
 General options loaded from the weightfile.
 

Private Attributes

FastBDTOptions m_specific_options
 Method specific options.
 
bool m_use_simplified_interface = false
 Use the simplified FastBDT interface of version 4.
 
FastBDT::Classifier m_classifier
 Simplified FastBDT interface: classifier combines preprocessing and forest.
 
FastBDT::Forest< float > m_expert_forest
 Forest Expert -> used in case of no purity transformation.
 

Detailed Description

Expert for the FastBDT MVA method.

Definition at line 104 of file FastBDT.h.

Member Function Documentation

◆ apply()

std::vector< float > apply ( Dataset test_data) const
overridevirtual

Apply this expert onto a dataset.

Parameters
test_datadataset

Implements Expert.

Definition at line 251 of file FastBDT.cc.

252 {
253
254 std::vector<float> probabilities(test_data.getNumberOfEvents());
255 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
256 test_data.loadEvent(iEvent);
258 probabilities[iEvent] = m_classifier.predict(test_data.m_input);
259 else
260 probabilities[iEvent] = m_expert_forest.Analyse(test_data.m_input);
261 }
262
263 return probabilities;
264
265 }
FastBDT::Forest< float > m_expert_forest
Forest Expert -> used in case of no purity transformation.
Definition: FastBDT.h:123
FastBDT::Classifier m_classifier
Simplified FastBDT interface: classifier combines preprocessing and forest.
Definition: FastBDT.h:122
bool m_use_simplified_interface
Use the simplified FastBDT interface of version 4.
Definition: FastBDT.h:121

◆ applyMulticlass()

virtual std::vector< std::vector< float > > applyMulticlass ( Dataset test_data) const
inlinevirtualinherited

Apply this m_expert onto a dataset.

Multiclass mode. Not pure virtual, since not all derived classes to re-implement this.

Parameters
test_datadataset.
Returns
vector of size N=test_data.getNumberOfEvents() with N=m_classes.size() scores for each event in the dataset.

Reimplemented in PythonExpert, TMVAExpertMulticlass, and TrivialExpert.

Definition at line 56 of file Expert.h.

57 {
58
59 B2ERROR("Attempted to call applyMulticlass() of the abstract base class MVA::Expert. All methods that support multiclass classification should override this definition.");
60 (void) test_data;
61
62 return std::vector<std::vector<float>>();
63 };

◆ load()

void load ( Weightfile weightfile)
overridevirtual

Load the expert from a Weightfile.

Parameters
weightfilecontaining all information necessary to build the expert

Implements Expert.

Definition at line 192 of file FastBDT.cc.

193 {
194
195 std::string custom_weightfile = weightfile.generateFileName();
196 weightfile.getFile("FastBDT_Weightfile", custom_weightfile);
197 std::fstream file(custom_weightfile, std::ios_base::in);
198
199 int version = weightfile.getElement<int>("FastBDT_version", 0);
200 B2DEBUG(100, "FastBDT Weightfile Version " << version);
201 if (version < 2) {
202 std::stringstream s;
203 {
204 std::string t;
205 std::fstream file2(custom_weightfile, std::ios_base::in);
206 getline(file2, t);
207 s << t;
208 }
209 int dummy;
210 // Try to read to integers, if this is successful we have a old weightfile with a Feature Binning before the Tree.
211 if (!(s >> dummy >> dummy)) {
212 B2DEBUG(100, "FastBDT: I read a new weightfile of FastBDT using the new FastBDT version 3. Everything fine!");
213 // New format since version 3
214 m_expert_forest = FastBDT::readForestFromStream<float>(file);
215 } else {
216 B2INFO("FastBDT: I read an old weightfile of FastBDT using the new FastBDT version 3."
217 "I will convert your FastBDT on-the-fly to the new version."
218 "Retrain the classifier to get rid of this message");
219 // Old format before version 3
220 // We read in first the feature binnings and than rewrite the tree
221 std::vector<FastBDT::FeatureBinning<float>> feature_binnings;
222 file >> feature_binnings;
223 double F0;
224 file >> F0;
225 double shrinkage;
226 file >> shrinkage;
227 // This parameter was not available in the old version
228 bool transform2probability = true;
229 FastBDT::Forest<unsigned int> temp_forest(shrinkage, F0, transform2probability);
230 unsigned int size;
231 file >> size;
232 for (unsigned int i = 0; i < size; ++i) {
233 temp_forest.AddTree(FastBDT::readTreeFromStream<unsigned int>(file));
234 }
235
236 FastBDT::Forest<float> cleaned_forest(temp_forest.GetShrinkage(), temp_forest.GetF0(), temp_forest.GetTransform2Probability());
237 for (auto& tree : temp_forest.GetForest()) {
238 cleaned_forest.AddTree(FastBDT::removeFeatureBinningTransformationFromTree(tree, feature_binnings));
239 }
240 m_expert_forest = cleaned_forest;
241 }
242 } else {
244 m_classifier = FastBDT::Classifier(file);
245 }
246 file.close();
247
248 weightfile.getOptions(m_specific_options);
249 }
FastBDTOptions m_specific_options
Method specific options.
Definition: FastBDT.h:120

Member Data Documentation

◆ m_classifier

FastBDT::Classifier m_classifier
private

Simplified FastBDT interface: classifier combines preprocessing and forest.

Definition at line 122 of file FastBDT.h.

◆ m_expert_forest

FastBDT::Forest<float> m_expert_forest
private

Forest Expert -> used in case of no purity transformation.

Definition at line 123 of file FastBDT.h.

◆ m_general_options

GeneralOptions m_general_options
protectedinherited

General options loaded from the weightfile.

Definition at line 70 of file Expert.h.

◆ m_specific_options

FastBDTOptions m_specific_options
private

Method specific options.

Definition at line 120 of file FastBDT.h.

◆ m_use_simplified_interface

bool m_use_simplified_interface = false
private

Use the simplified FastBDT interface of version 4.

Definition at line 121 of file FastBDT.h.


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