Wraps the data of a single event into a Dataset.
More...
#include <Dataset.h>
|
| SingleDataset (const GeneralOptions &general_options, const std::vector< float > &input, float target=1.0, const std::vector< float > &spectators=std::vector< float >()) |
| Constructs a new SingleDataset.
|
|
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 which is always one.
|
|
virtual void | loadEvent (unsigned int) override |
| Does nothing in the case of a single dataset, because the only event is already loaded.
|
|
virtual std::vector< float > | getFeature (unsigned int iFeature) override |
| Returns all values (in this case only one) of one feature in a std::vector<float>
|
|
virtual std::vector< float > | getSpectator (unsigned int iSpectator) override |
| Returns all values (in this case only one) of one spectator in a std::vector<float>
|
|
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.
|
|
virtual std::vector< float > | getWeights () |
| Returns all weights.
|
|
virtual std::vector< float > | getTargets () |
| Returns all targets.
|
|
virtual std::vector< bool > | getSignals () |
| Returns all is Signals.
|
|
|
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.
|
|
Wraps the data of a single event into a Dataset.
Mostly useful if one wants to apply an Expert to a single feature vector
Definition at line 135 of file Dataset.h.
◆ SingleDataset()
SingleDataset |
( |
const GeneralOptions & | general_options, |
|
|
const std::vector< float > & | input, |
|
|
float | target = 1.0, |
|
|
const std::vector< float > & | spectators = std::vector<float>() ) |
Constructs a new SingleDataset.
- Parameters
-
general_options | which defines e.g. number of variables |
input | feature values of the single event |
spectators | spectator values of the single event |
target | target value of the single event (defaults to 1, because often this is not known if one wants to apply an expert) |
Definition at line 135 of file Dataset.cc.
136 : Dataset(general_options)
137 {
138 m_input = input;
139 m_spectators = spectators;
140 m_target = target;
141 m_weight = 1.0;
142 m_isSignal = std::lround(target) == m_general_options.m_signal_class;
143 }
◆ getFeature()
virtual std::vector< float > getFeature |
( |
unsigned int | iFeature | ) |
|
|
inlineoverridevirtual |
Returns all values (in this case only one) of one feature in a std::vector<float>
- Parameters
-
iFeature | the position of the feature to return |
Reimplemented from Dataset.
Definition at line 172 of file Dataset.h.
172{ return std::vector<float> {m_input[iFeature]}; }
◆ getFeatureIndex()
unsigned int getFeatureIndex |
( |
const std::string & | feature | ) |
|
|
virtualinherited |
Return index of feature with the given name.
- Parameters
-
feature | name 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 }
◆ getNumberOfEvents()
virtual unsigned int getNumberOfEvents |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns the number of events in this dataset which is always one.
Implements Dataset.
Definition at line 161 of file Dataset.h.
◆ getNumberOfFeatures()
virtual unsigned int getNumberOfFeatures |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns the number of features in this dataset.
Implements Dataset.
Definition at line 151 of file Dataset.h.
151{ return m_input.size(); }
◆ getNumberOfSpectators()
virtual unsigned int getNumberOfSpectators |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns the number of features in this dataset.
Implements Dataset.
Definition at line 156 of file Dataset.h.
156{ return m_spectators.size(); }
◆ 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 }
◆ getSignals()
std::vector< bool > getSignals |
( |
| ) |
|
|
virtualinherited |
Returns all is Signals.
Reimplemented in ReweightingDataset.
Definition at line 122 of file Dataset.cc.
123 {
124
125 std::vector<bool> result(getNumberOfEvents());
126 for (unsigned int iEvent = 0; iEvent < getNumberOfEvents(); ++iEvent) {
127 loadEvent(iEvent);
128 result[iEvent] = m_isSignal;
129 }
130 return result;
131
132 }
◆ getSpectator()
virtual std::vector< float > getSpectator |
( |
unsigned int | iSpectator | ) |
|
|
inlineoverridevirtual |
Returns all values (in this case only one) of one spectator in a std::vector<float>
- Parameters
-
iSpectator | the position of the spectator to return |
Reimplemented from Dataset.
Definition at line 178 of file Dataset.h.
178{ return std::vector<float> {m_spectators[iSpectator]}; }
◆ getSpectatorIndex()
unsigned int getSpectatorIndex |
( |
const std::string & | spectator | ) |
|
|
virtualinherited |
Return index of spectator with the given name.
- Parameters
-
spectator | name 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 }
◆ getTargets()
std::vector< float > getTargets |
( |
| ) |
|
|
virtualinherited |
Returns all targets.
Reimplemented in RegressionDataSet, and ReweightingDataset.
Definition at line 110 of file Dataset.cc.
111 {
112
113 std::vector<float> result(getNumberOfEvents());
114 for (unsigned int iEvent = 0; iEvent < getNumberOfEvents(); ++iEvent) {
115 loadEvent(iEvent);
116 result[iEvent] = m_target;
117 }
118 return result;
119
120 }
◆ getWeights()
std::vector< float > getWeights |
( |
| ) |
|
|
virtualinherited |
Returns all weights.
Reimplemented in RegressionDataSet, ReweightingDataset, and ROOTDataset.
Definition at line 98 of file Dataset.cc.
99 {
100
101 std::vector<float> result(getNumberOfEvents());
102 for (unsigned int iEvent = 0; iEvent < getNumberOfEvents(); ++iEvent) {
103 loadEvent(iEvent);
104 result[iEvent] = m_weight;
105 }
106 return result;
107
108 }
◆ loadEvent()
virtual void loadEvent |
( |
unsigned int | | ) |
|
|
inlineoverridevirtual |
Does nothing in the case of a single dataset, because the only event is already loaded.
Implements Dataset.
Definition at line 166 of file Dataset.h.
◆ m_general_options
◆ 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
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
Contains the target value of the currently loaded event.
Definition at line 126 of file Dataset.h.
◆ m_weight
Contains the weight of the currently loaded event.
Definition at line 125 of file Dataset.h.
The documentation for this class was generated from the following files: