43 auto tupleSort = [](std::tuple<Float_t, Float_t, Bool_t> _a, std::tuple<Float_t, Float_t, Bool_t> _b) {
44 return std::get<0>(_a) < std::get<0>(_b);
57 const std::vector<Float_t> &mvaWeights)
60 assert(mvaValues.size() == mvaTargets.size());
61 assert(mvaValues.size() == mvaWeights.size());
63 for (
UInt_t i = 0; i < mvaValues.size(); i++) {
64 fMva.emplace_back(mvaValues[i], mvaWeights[i], mvaTargets[i]);
76 assert(mvaValues.size() == mvaTargets.size());
78 for (
UInt_t i = 0; i < mvaValues.size(); i++) {
79 fMva.emplace_back(mvaValues[i], 1, mvaTargets[i]);
91 for (
UInt_t i = 0; i < mvaSignal.size(); i++) {
92 fMva.emplace_back(mvaSignal[i], 1,
kTRUE);
95 for (
UInt_t i = 0; i < mvaBackground.size(); i++) {
96 fMva.emplace_back(mvaBackground[i], 1,
kFALSE);
106 const std::vector<Float_t> &mvaSignalWeights,
const std::vector<Float_t> &mvaBackgroundWeights)
109 assert(mvaSignal.size() == mvaSignalWeights.size());
110 assert(mvaBackground.size() == mvaBackgroundWeights.size());
112 for (
UInt_t i = 0; i < mvaSignal.size(); i++) {
113 fMva.emplace_back(mvaSignal[i], mvaSignalWeights[i],
kTRUE);
116 for (
UInt_t i = 0; i < mvaBackground.size(); i++) {
117 fMva.emplace_back(mvaBackground[i], mvaBackgroundWeights[i],
kFALSE);
143 if (num_points <= 2) {
147 std::vector<Double_t> specificity_vector;
148 std::vector<Double_t> true_negatives;
149 specificity_vector.reserve(
fMva.size());
150 true_negatives.reserve(
fMva.size());
153 for (
auto &ev :
fMva) {
155 auto weight = std::get<1>(ev);
156 auto isSignal = std::get<2>(ev);
158 true_negatives_sum += weight * (not isSignal);
159 true_negatives.push_back(true_negatives_sum);
162 specificity_vector.push_back(0.0);
163 Double_t total_background = true_negatives_sum;
164 for (
auto &tn : true_negatives) {
166 (total_background <= std::numeric_limits<Double_t>::min()) ? (0.0) : (tn / total_background);
167 specificity_vector.push_back(specificity);
169 specificity_vector.push_back(1.0);
171 return specificity_vector;
179 if (num_points <= 2) {
183 std::vector<Double_t> sensitivity_vector;
184 std::vector<Double_t> true_positives;
185 sensitivity_vector.reserve(
fMva.size());
186 true_positives.reserve(
fMva.size());
189 for (
auto it =
fMva.rbegin(); it !=
fMva.rend(); ++it) {
191 auto weight = std::get<1>(*it);
192 auto isSignal = std::get<2>(*it);
194 true_positives_sum += weight * (isSignal);
195 true_positives.push_back(true_positives_sum);
197 std::reverse(true_positives.begin(), true_positives.end());
199 sensitivity_vector.push_back(1.0);
200 Double_t total_signal = true_positives_sum;
201 for (
auto &tp : true_positives) {
202 Double_t sensitivity = (total_signal <= std::numeric_limits<Double_t>::min()) ? (0.0) : (tp / total_signal);
203 sensitivity_vector.push_back(sensitivity);
205 sensitivity_vector.push_back(0.0);
207 return sensitivity_vector;
222 assert(0.0 <= effB and effB <= 1.0);
228 auto complement = [](
Double_t x) {
return 1 -
x; };
229 std::transform(effB_vec.begin(), effB_vec.end(), effB_vec.begin(), complement);
232 std::reverse(effS_vec.begin(), effS_vec.end());
233 std::reverse(effB_vec.begin(), effB_vec.end());
239 return rocSpline.Eval(effB);
257 for (
UInt_t i = 0; i < sensitivity.size() - 1; i++) {
259 Double_t currFnr = 1 - sensitivity[i];
260 Double_t nextFnr = 1 - sensitivity[i + 1];
262 integral += 0.5 * (nextFnr - currFnr) * (specificity[i] + specificity[i + 1]);
286 fGraph =
new TGraph(sensitivity.size(), &sensitivity[0], &specificity[0]);
Double_t GetEffSForEffB(Double_t effB, const UInt_t num_points=41)
Calculate the signal efficiency (sensitivity) for a given background efficiency (sensitivity).
Double_t GetROCIntegral(const UInt_t points=41)
Calculates the ROC integral (AUC)
std::vector< Double_t > ComputeSpecificity(const UInt_t num_points)
void mvas(TString dataset, TString fin="TMVA.root", HistType htype=kMVAType, Bool_t useTMVAStyle=kTRUE)
ROCCurve(const std::vector< std::tuple< Float_t, Float_t, Bool_t >> &mvas)
Linear interpolation of TGraph.
ostringstream derivative to redirect and format output
MsgLogger & Log() const
message logger
std::vector< Double_t > ComputeSensitivity(const UInt_t num_points)
Abstract ClassifierFactory template that handles arbitrary types.
TGraph * GetROCCurve(const UInt_t points=100)
Returns a new TGraph containing the ROC curve.
A Graph is a graphics object made of two arrays X and Y with npoints each.
std::vector< std::tuple< Float_t, Float_t, Bool_t > > fMva