Belle II Software light-2406-ragdoll
ReweightingDataset Class Reference

Dataset for Reweighting Wraps a dataset and provides each data-point with a new weight. More...

#include <DataDriven.h>

Inheritance diagram for ReweightingDataset:
Collaboration diagram for ReweightingDataset:

Public Member Functions

 ReweightingDataset (const GeneralOptions &general_options, Dataset &dataset, const std::vector< float > &weights)
 Constructs a new ReweightingDataset.
 
virtual unsigned int getNumberOfFeatures () const override
 Returns the number of features in this dataset.
 
virtual unsigned int getNumberOfSpectators () const override
 Returns the number of features in this dataset.
 
virtual unsigned int getNumberOfEvents () const override
 Returns the number of events in this dataset.
 
virtual std::vector< float > getFeature (unsigned int iFeature) override
 Returns all values of one feature in a std::vector<float>
 
virtual std::vector< float > getSpectator (unsigned int iSpectator) override
 Returns all values of one spectator in a std::vector<float>
 
virtual std::vector< float > getWeights () override
 Returns all weights.
 
virtual std::vector< float > getTargets () override
 Returns all targets.
 
virtual std::vector< bool > getSignals () override
 Returns all is Signals.
 
virtual void loadEvent (unsigned int event) override
 Load the event number iEvent.
 
virtual float getSignalFraction ()
 Returns the signal fraction of the whole sample.
 
virtual unsigned int getFeatureIndex (const std::string &feature)
 Return index of feature with the given name.
 
virtual unsigned int getSpectatorIndex (const std::string &spectator)
 Return index of spectator with the given name.
 

Public Attributes

GeneralOptions m_general_options
 GeneralOptions passed to this dataset.
 
std::vector< float > m_input
 Contains all feature values of the currently loaded event.
 
std::vector< float > m_spectators
 Contains all spectators values of the currently loaded event.
 
float m_weight
 Contains the weight of the currently loaded event.
 
float m_target
 Contains the target value of the currently loaded event.
 
bool m_isSignal
 Defines if the currently loaded event is signal or background.
 

Private Attributes

Datasetm_dataset
 Wrapped dataset.
 
std::vector< float > m_weights
 sPlot weights
 

Detailed Description

Dataset for Reweighting Wraps a dataset and provides each data-point with a new weight.

Definition at line 29 of file DataDriven.h.

Constructor & Destructor Documentation

◆ ReweightingDataset()

ReweightingDataset ( const GeneralOptions general_options,
Dataset dataset,
const std::vector< float > &  weights 
)

Constructs a new ReweightingDataset.

Parameters
general_optionsshared options defining the dataset (variables, ...)
datasetcontaining the data-points
weightsreweighting weights

Definition at line 25 of file DataDriven.cc.

26 : Dataset(general_options), m_dataset(dataset), m_weights(weights) { }
Dataset(const GeneralOptions &general_options)
Constructs a new dataset given the general options.
Definition: Dataset.cc:26
std::vector< float > m_weights
sPlot weights
Definition: DataDriven.h:97
Dataset & m_dataset
Wrapped dataset.
Definition: DataDriven.h:96

Member Function Documentation

◆ getFeature()

virtual std::vector< float > getFeature ( unsigned int  iFeature)
inlineoverridevirtual

Returns all values of one feature in a std::vector<float>

Parameters
iFeaturethe position of the feature to return

Reimplemented from Dataset.

Definition at line 59 of file DataDriven.h.

59{ return m_dataset.getFeature(iFeature); }
virtual std::vector< float > getFeature(unsigned int iFeature)
Returns all values of one feature in a std::vector<float>
Definition: Dataset.cc:74

◆ getFeatureIndex()

unsigned int getFeatureIndex ( const std::string &  feature)
virtualinherited

Return index of feature with the given name.

Parameters
featurename of the feature

Definition at line 50 of file Dataset.cc.

51 {
52
53 auto it = std::find(m_general_options.m_variables.begin(), m_general_options.m_variables.end(), feature);
54 if (it == m_general_options.m_variables.end()) {
55 B2ERROR("Unknown feature named " << feature);
56 return 0;
57 }
58 return std::distance(m_general_options.m_variables.begin(), it);
59
60 }
GeneralOptions m_general_options
GeneralOptions passed to this dataset.
Definition: Dataset.h:122
std::vector< std::string > m_variables
Vector of all variables (branch names) used in the training.
Definition: Options.h:86

◆ getNumberOfEvents()

virtual unsigned int getNumberOfEvents ( ) const
inlineoverridevirtual

Returns the number of events in this dataset.

Implements Dataset.

Definition at line 53 of file DataDriven.h.

53{ return m_dataset.getNumberOfEvents(); };
virtual unsigned int getNumberOfEvents() const =0
Returns the number of events in this dataset.

◆ getNumberOfFeatures()

virtual unsigned int getNumberOfFeatures ( ) const
inlineoverridevirtual

Returns the number of features in this dataset.

Implements Dataset.

Definition at line 43 of file DataDriven.h.

virtual unsigned int getNumberOfFeatures() const =0
Returns the number of features in this dataset.

◆ getNumberOfSpectators()

virtual unsigned int getNumberOfSpectators ( ) const
inlineoverridevirtual

Returns the number of features in this dataset.

Implements Dataset.

Definition at line 48 of file DataDriven.h.

virtual unsigned int getNumberOfSpectators() const =0
Returns the number of spectators in this dataset.

◆ getSignalFraction()

float getSignalFraction ( )
virtualinherited

Returns the signal fraction of the whole sample.

Reimplemented in SPlotDataset.

Definition at line 35 of file Dataset.cc.

36 {
37
38 double signal_weight_sum = 0;
39 double weight_sum = 0;
40 for (unsigned int i = 0; i < getNumberOfEvents(); ++i) {
41 loadEvent(i);
42 weight_sum += m_weight;
43 if (m_isSignal)
44 signal_weight_sum += m_weight;
45 }
46 return signal_weight_sum / weight_sum;
47
48 }
virtual void loadEvent(unsigned int iEvent)=0
Load the event number iEvent.
bool m_isSignal
Defines if the currently loaded event is signal or background.
Definition: Dataset.h:127
float m_weight
Contains the weight of the currently loaded event.
Definition: Dataset.h:125

◆ getSignals()

virtual std::vector< bool > getSignals ( )
inlineoverridevirtual

Returns all is Signals.

Reimplemented from Dataset.

Definition at line 87 of file DataDriven.h.

87{ return m_dataset.getSignals(); }
virtual std::vector< bool > getSignals()
Returns all is Signals.
Definition: Dataset.cc:122

◆ getSpectator()

virtual std::vector< float > getSpectator ( unsigned int  iSpectator)
inlineoverridevirtual

Returns all values of one spectator in a std::vector<float>

Parameters
iSpectatorthe position of the feature to return

Reimplemented from Dataset.

Definition at line 65 of file DataDriven.h.

65{ return m_dataset.getSpectator(iSpectator); }
virtual std::vector< float > getSpectator(unsigned int iSpectator)
Returns all values of one spectator in a std::vector<float>
Definition: Dataset.cc:86

◆ getSpectatorIndex()

unsigned int getSpectatorIndex ( const std::string &  spectator)
virtualinherited

Return index of spectator with the given name.

Parameters
spectatorname of the spectator

Definition at line 62 of file Dataset.cc.

63 {
64
65 auto it = std::find(m_general_options.m_spectators.begin(), m_general_options.m_spectators.end(), spectator);
66 if (it == m_general_options.m_spectators.end()) {
67 B2ERROR("Unknown spectator named " << spectator);
68 return 0;
69 }
70 return std::distance(m_general_options.m_spectators.begin(), it);
71
72 }
std::vector< std::string > m_spectators
Vector of all spectators (branch names) used in the training.
Definition: Options.h:87

◆ getTargets()

virtual std::vector< float > getTargets ( )
inlineoverridevirtual

Returns all targets.

Reimplemented from Dataset.

Definition at line 82 of file DataDriven.h.

82{ return m_dataset.getTargets(); }
virtual std::vector< float > getTargets()
Returns all targets.
Definition: Dataset.cc:110

◆ getWeights()

virtual std::vector< float > getWeights ( )
inlineoverridevirtual

Returns all weights.

Reimplemented from Dataset.

Definition at line 70 of file DataDriven.h.

71 {
72 auto weights = m_dataset.getWeights();
73 for (unsigned int iEvent = 0; iEvent < weights.size(); ++iEvent) {
74 weights[iEvent] *= m_weights[iEvent];
75 }
76 return weights;
77 }
virtual std::vector< float > getWeights()
Returns all weights.
Definition: Dataset.cc:98

◆ loadEvent()

void loadEvent ( unsigned int  event)
overridevirtual

Load the event number iEvent.

Parameters
eventevent number to load

Implements Dataset.

Definition at line 28 of file DataDriven.cc.

29 {
30 m_dataset.loadEvent(event);
36 }
std::vector< float > m_spectators
Contains all spectators values of the currently loaded event.
Definition: Dataset.h:124
std::vector< float > m_input
Contains all feature values of the currently loaded event.
Definition: Dataset.h:123
float m_target
Contains the target value of the currently loaded event.
Definition: Dataset.h:126

Member Data Documentation

◆ m_dataset

Dataset& m_dataset
private

Wrapped dataset.

Definition at line 96 of file DataDriven.h.

◆ m_general_options

GeneralOptions m_general_options
inherited

GeneralOptions passed to this dataset.

Definition at line 122 of file Dataset.h.

◆ m_input

std::vector<float> m_input
inherited

Contains all feature values of the currently loaded event.

Definition at line 123 of file Dataset.h.

◆ m_isSignal

bool m_isSignal
inherited

Defines if the currently loaded event is signal or background.

Definition at line 127 of file Dataset.h.

◆ m_spectators

std::vector<float> m_spectators
inherited

Contains all spectators values of the currently loaded event.

Definition at line 124 of file Dataset.h.

◆ m_target

float m_target
inherited

Contains the target value of the currently loaded event.

Definition at line 126 of file Dataset.h.

◆ m_weight

float m_weight
inherited

Contains the weight of the currently loaded event.

Definition at line 125 of file Dataset.h.

◆ m_weights

std::vector<float> m_weights
private

sPlot weights

Definition at line 97 of file DataDriven.h.


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