10#include <mva/interface/Dataset.h>
11#include <mva/interface/Expert.h>
12#include <mva/interface/Options.h>
13#include <mva/interface/Teacher.h>
14#include <mva/interface/Weightfile.h>
16#include <framework/logging/Logger.h>
18#include <boost/property_tree/ptree_fwd.hpp>
19#include <boost/program_options.hpp>
33 template<
class BaseClassifierOptions>
37 void load(
const boost::property_tree::ptree& pt)
override;
40 void save(boost::property_tree::ptree& pt)
const override;
92 void loadEvent(
unsigned int iEvent)
override;
95 std::vector<float>
getFeature(
unsigned int iFeature)
override;
98 std::vector<float>
getSpectator(
unsigned int iSpectator)
override;
138 template<
class BaseClassifierTeacher,
class RegressionClassifierOptions>
143 const RegressionClassifierOptions& specific_options);
178 template<
class BaseClassifierExpert,
class RegressionClassifierOptions>
196template<
class BaseClassifierOptions>
202template<
class BaseClassifierOptions>
208template<
class BaseClassifierOptions>
214template<
class BaseClassifierOptions>
220template<
class BaseClassifierOptions>
226template<
class BaseClassifierOptions>
232template<
class BaseClassifierOptions>
237 description.add_options()
239 "Number of bins to split the target variable into");
244template<
class BaseClassifierTeacher,
class RegressionClassifierOptions>
252 for (
unsigned int binNumber = 1; binNumber <
m_specific_options.getMaximalBinNumber(); binNumber++) {
259 weightfile.
addFile(
"BaseClassifier_WeightFile_" + std::to_string(binNumber), file);
264template<
class BaseClassifierTeacher,
class RegressionClassifierOptions>
267 const RegressionClassifierOptions& specific_options) :
273template<
class BaseClassifierExpert,
class RegressionClassifierOptions>
276 RegressionClassifierOptions specific_options;
280 for (
unsigned int binNumber = 1; binNumber < specific_options.getMaximalBinNumber(); binNumber++) {
282 weightfile.
getFile(
"BaseClassifier_WeightFile_" + std::to_string(binNumber), file);
289template<
class BaseClassifierExpert,
class RegressionClassifierOptions>
293 std::vector<float> sum;
297 sum = expert.apply(test_data);
301 const auto& expertResult = expert.apply(test_data);
302 if (sum.size() != expertResult.size()) {
303 B2FATAL(
"There is one expert in the list that returned not the same number of results than the others!");
306 for (
unsigned int index = 0; index < sum.size(); index++) {
307 sum[index] += expertResult[index];
311 for (
unsigned int index = 0; index < sum.size(); index++) {
Abstract base class of all Datasets given to the MVA interface The current event can always be access...
Dataset(const GeneralOptions &general_options)
Constructs a new dataset given the general options.
Expert()=default
Default constructor.
General options which are shared by all MVA trainings.
Dataset needed during the training of a regression method.
std::vector< float > getTargets() override
Return the targets from the real dataset.
unsigned int getNumberOfEvents() const override
Return the number of events from the real dataset.
std::vector< float > getSpectator(unsigned int iSpectator) override
Return a specific spectator from the real dataset.
unsigned int getNumberOfSpectators() const override
Return the number of spectators from the real dataset.
unsigned int getNumberOfFeatures() const override
Return the number of features from the real dataset.
std::vector< float > getFeature(unsigned int iFeature) override
Return a specific feature from the real dataset.
std::vector< float > getWeights() override
Return the weights from the real dataset.
void loadEvent(unsigned int iEvent) override
Load an event. Sets all internal variables and sets the isSignal variable dependent on the cut value.
Dataset * m_childDataSet
The real data set (our child)
double m_cutValue
The cut value.
RegressionDataSet(const GeneralOptions &general_options, Dataset *dataSet, double cutValue)
Create a new regression data set out of the general options, a pointer to the real dataset and the cu...
Generic expert for the regression applications.
std::vector< float > apply(Dataset &test_data) const override
Apply the loaded experts by averaging over the single expert decisions.
std::vector< FastBDTExpert > m_baseClassifierExperts
void load(Weightfile &weightfile) override
Load the expert from the weightfile by loading each stored single classifier one ofter the other.
Generic options of the Regression MVA methods hosting the number of bins (and the base classifier opt...
BaseClassifierOptions m_baseClassifierOptions
Options of the base classifier.
const BaseClassifierOptions & getBaseClassifierOptions() const
Return options of the base classifier (const version)
unsigned int getMaximalBinNumber() const
Return the number of bins to use.
BaseClassifierOptions & getBaseClassifierOptions()
Return options of the base classifier (non-const version)
unsigned int m_numberOfBins
How many bins to use.
po::options_description getDescription() override
Get the descriptions for these options.
void load(const boost::property_tree::ptree &pt) override
Load the options from a boost property tree. Only loads the maximal bin number.
void setMaximalBinNumber(unsigned int maximalBinNumber)
Set the number of bins to use.
void save(boost::property_tree::ptree &pt) const override
Save the options from a boost property tree. Only saves the maximal bin number.
FastBDTTeacher m_baseClassifierTeacher
RegressionFastBDTOptions m_specific_options
RegressionTeacher(const GeneralOptions &general_options, const RegressionClassifierOptions &specific_options)
Create a new teacher out of the general and the regression method specific options.
Weightfile train(Dataset &training_data) const override
Call the train function.
Specific Options, all method Options have to inherit from this class.
virtual std::string getMethod() const =0
Returns method name, used in the interface to register the method.
GeneralOptions m_general_options
GeneralOptions containing all shared options.
Teacher(const GeneralOptions &general_options)
Constructs a new teacher using the GeneralOptions for this training.
The Weightfile class serializes all information about a training into an xml tree.
void addFile(const std::string &identifier, const std::string &custom_weightfile)
Add a file (mostly a weightfile from a MVA library) to our Weightfile.
static Weightfile loadFromXMLFile(const std::string &filename)
Static function which loads a Weightfile from a XML file.
static void saveToXMLFile(Weightfile &weightfile, const std::string &filename)
Static function which saves a Weightfile to a XML file.
void addOptions(const Options &options)
Add an Option object to the xml tree.
void getOptions(Options &options) const
Fills an Option object from the xml tree.
std::string generateFileName(const std::string &suffix="")
Returns a temporary filename with the given suffix.
void getFile(const std::string &identifier, const std::string &custom_weightfile)
Creates a file from our weightfile (mostly this will be a weightfile of an MVA library)
Abstract base class for different kinds of events.