Belle II Software light-2406-ragdoll
FANNExpert Class Reference

Expert for the FANN MVA method. More...

#include <FANN.h>

Inheritance diagram for FANNExpert:
Collaboration diagram for FANNExpert:

Public Member Functions

virtual ~FANNExpert ()
 Destructor of FANN Expert.
 
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

FANNOptions m_specific_options
 Method specific options.
 
struct fann * m_ann = nullptr
 Pointer to FANN expert.
 

Detailed Description

Expert for the FANN MVA method.

Definition at line 109 of file FANN.h.

Constructor & Destructor Documentation

◆ ~FANNExpert()

~FANNExpert ( )
virtual

Destructor of FANN Expert.

Definition at line 312 of file FANN.cc.

313 {
314 if (m_ann) {
315 fann_destroy(m_ann);
316 }
317 }
struct fann * m_ann
Pointer to FANN expert.
Definition: FANN.h:132

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 333 of file FANN.cc.

334 {
335
336 std::vector<fann_type> input(test_data.getNumberOfFeatures());
337 std::vector<float> probabilities(test_data.getNumberOfEvents());
338 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
339 test_data.loadEvent(iEvent);
340 for (unsigned int iFeature = 0; iFeature < test_data.getNumberOfFeatures(); ++iFeature) {
341 input[iFeature] = test_data.m_input[iFeature];
342 }
343 if (m_specific_options.m_scale_features) fann_scale_input(m_ann, input.data());
344 probabilities[iEvent] = fann_run(m_ann, input.data())[0];
345 }
346 if (m_specific_options.m_scale_target) fann_descale_output(m_ann, probabilities.data());
347 return probabilities;
348 }
FANNOptions m_specific_options
Method specific options.
Definition: FANN.h:131
bool m_scale_features
Scale features before training.
Definition: FANN.h:77
bool m_scale_target
Scale target before training.
Definition: FANN.h:78

◆ 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 319 of file FANN.cc.

320 {
321
322 std::string custom_weightfile = weightfile.generateFileName();
323 weightfile.getFile("FANN_Weightfile", custom_weightfile);
324
325 if (m_ann) {
326 fann_destroy(m_ann);
327 }
328 m_ann = fann_create_from_file(custom_weightfile.c_str());
329
330 weightfile.getOptions(m_specific_options);
331 }

Member Data Documentation

◆ m_ann

struct fann* m_ann = nullptr
private

Pointer to FANN expert.

Definition at line 132 of file FANN.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

FANNOptions m_specific_options
private

Method specific options.

Definition at line 131 of file FANN.h.


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