9 #include <mva/methods/Trivial.h>
10 #include <mva/interface/Interface.h>
11 #include <framework/utilities/FileSystem.h>
12 #include <framework/utilities/TestHelpers.h>
14 #include <gtest/gtest.h>
20 TEST(TrivialTest, TrivialOptions)
25 EXPECT_EQ(specific_options.m_output, 0.5);
27 specific_options.m_output = 0.1;
29 boost::property_tree::ptree pt;
30 specific_options.save(pt);
31 EXPECT_FLOAT_EQ(pt.get<
double>(
"Trivial_output"), 0.1);
34 specific_options2.
load(pt);
36 EXPECT_EQ(specific_options2.
m_output, 0.1);
38 EXPECT_EQ(specific_options.getMethod(), std::string(
"Trivial"));
41 auto description = specific_options.getDescription();
42 EXPECT_EQ(description.options().size(), 1);
46 pt.put(
"Trivial_version", 100);
48 EXPECT_B2ERROR(specific_options2.
load(pt));
52 EXPECT_THROW(specific_options2.
load(pt), std::runtime_error);
57 explicit TestDataset(
const std::vector<float>& data) : MVA::Dataset(MVA::GeneralOptions()), m_data(data)
65 [[nodiscard]]
unsigned int getNumberOfFeatures()
const override {
return 1; }
66 [[nodiscard]]
unsigned int getNumberOfSpectators()
const override {
return 0; }
67 [[nodiscard]]
unsigned int getNumberOfEvents()
const override {
return m_data.size(); }
68 void loadEvent(
unsigned int iEvent)
override { m_input[0] = m_data[iEvent]; m_target = iEvent % 2; m_isSignal = m_target == 1; };
69 float getSignalFraction()
override {
return 0.1; };
70 std::vector<float> getFeature(
unsigned int)
override {
return m_data; }
72 std::vector<float> m_data;
77 TEST(TrivialTest, TrivialInterface)
83 TestDataset dataset({1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 2.0, 3.0});
85 auto teacher = interface.
getTeacher(general_options, specific_options);
86 auto weightfile = teacher->train(dataset);
89 expert->load(weightfile);
90 auto probabilities = expert->apply(dataset);
91 EXPECT_EQ(probabilities.size(), dataset.getNumberOfEvents());
92 for (
unsigned int i = 0; i < dataset.getNumberOfEvents(); ++i)
93 EXPECT_FLOAT_EQ(probabilities[i], 0.5);
Abstract base class of all Datasets given to the MVA interface The current event can always be access...
General options which are shared by all MVA trainings.
Template class to easily construct a interface for an MVA library using a library-specific Options,...
virtual std::unique_ptr< Teacher > getTeacher(const GeneralOptions &general_options, const SpecificOptions &specific_options) const override
Get Teacher of this MVA library.
virtual std::unique_ptr< MVA::Expert > getExpert() const override
Get Exoert of this MVA library.
Options for the Trivial MVA method.
double m_output
Output of the trivial method.
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism to load Options from a xml tree.
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.