Belle II Software  release-05-01-25
test_FANN.cc
1 /* BASF2 (Belle Analysis Framework 2) *
2  * Copyright(C) 2017 - Belle II Collaboration *
3  * *
4  * Author: The Belle II Collaboration *
5  * Contributors: Thomas Keck *
6  * *
7  * This software is provided "as is" without any warranty. *
8  **************************************************************************/
9 
10 #include <mva/methods/FANN.h>
11 #include <mva/interface/Interface.h>
12 #include <framework/utilities/FileSystem.h>
13 
14 #include <gtest/gtest.h>
15 
16 using namespace Belle2;
17 
18 namespace {
19 
20  TEST(FANNTest, WeightfilesAreReadCorrectly)
21  {
23 
24  MVA::GeneralOptions general_options;
25  general_options.m_variables = {"M", "p", "pt"};
26  MVA::MultiDataset dataset(general_options, {{1.835127, 1.179507, 1.164944},
27  {1.873689, 1.881940, 1.843310},
28  {1.863657, 1.774831, 1.753773},
29  {1.858293, 1.605311, 0.631336},
30  {1.837129, 1.575739, 1.490166},
31  {1.811395, 1.524029, 0.565220}
32  },
33  {}, {0.0, 1.0, 0.0, 1.0, 0.0, 1.0});
34 
35  auto expert = interface.getExpert();
36 
37  auto weightfile = MVA::Weightfile::loadFromFile(FileSystem::findFile("mva/methods/tests/FANN.xml"));
38  expert->load(weightfile);
39  auto probabilities = expert->apply(dataset);
40  EXPECT_NEAR(probabilities[0], 0.047535836696624756, 0.0001);
41  EXPECT_NEAR(probabilities[1], 0.7130427360534668, 0.0001);
42  EXPECT_NEAR(probabilities[2], 0.7729528546333313, 0.0001);
43  EXPECT_NEAR(probabilities[3], 0.16526281833648682, 0.0001);
44  EXPECT_NEAR(probabilities[4], 0.0091879460960626602, 0.0001);
45  EXPECT_NEAR(probabilities[5], -0.21771839261054993, 0.0001);
46  }
47 
48 }
Belle2::MVA::MultiDataset
Wraps the data of a multiple event into a Dataset.
Definition: Dataset.h:187
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MVA::Weightfile::loadFromFile
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
Definition: Weightfile.cc:215
Belle2::MVA::GeneralOptions
General options which are shared by all MVA trainings.
Definition: Options.h:64
Belle2::TEST
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Definition: utilityFunctions.cc:18
Belle2::FileSystem::findFile
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:147
Belle2::MVA::Interface::getExpert
virtual std::unique_ptr< MVA::Expert > getExpert() const override
Get Exoert of this MVA library.
Definition: Interface.h:128
Belle2::MVA::Interface
Template class to easily construct a interface for an MVA library using a library-specific Options,...
Definition: Interface.h:101