Belle II Software light-2406-ragdoll
FastBDTExpert Class Reference

Expert for the FastBDT MVA method. More...

#include <FastBDT.h>

Inheritance diagram for FastBDTExpert:
Collaboration diagram for FastBDTExpert:

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 248 of file FastBDT.cc.

249 {
250
251 std::vector<float> probabilities(test_data.getNumberOfEvents());
252 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
253 test_data.loadEvent(iEvent);
255 probabilities[iEvent] = m_classifier.predict(test_data.m_input);
256 else
257 probabilities[iEvent] = m_expert_forest.Analyse(test_data.m_input);
258 }
259
260 return probabilities;
261
262 }
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 189 of file FastBDT.cc.

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