61 fLogger( new
MsgLogger(
Form(
"ResultsMultiClass%s",resultsName.Data()) , kINFO) ),
63 fAchievableEff(dsi->GetNClasses()),
64 fAchievablePur(dsi->GetNClasses()),
65 fBestCuts(dsi->GetNClasses(),
std::vector<
Double_t>(dsi->GetNClasses()))
96 TMatrixD mat(numClasses, numClasses);
99 for (
UInt_t iRow = 0; iRow < numClasses; ++iRow) {
100 for (
UInt_t iCol = 0; iCol < numClasses; ++iCol) {
104 mat(iRow, iCol) = std::numeric_limits<double>::quiet_NaN();
107 std::vector<Float_t> valueVector;
108 std::vector<Bool_t> classVector;
109 std::vector<Float_t> weightVector;
117 if (cls != iRow and cls != iCol) {
121 classVector.push_back(cls == iRow);
122 weightVector.push_back(weight);
123 valueVector.push_back(mvaValue);
126 ROCCurve roc(valueVector, classVector, weightVector);
149 Bool_t break_outer_loop =
false;
150 for (
UInt_t icls = 0; icls < cutvalues.size(); ++icls) {
152 auto cutvalue = cutvalues.at(icls);
153 if (cutvalue < 0. ? (-value < cutvalue) : (+value <= cutvalue)) {
154 break_outer_loop =
true;
159 if (break_outer_loop) {
164 positives[isEvCurrClass] += w;
167 const Float_t truePositive = positives[1];
168 const Float_t falsePositive = positives[0];
171 Float_t pur = truePositive / (truePositive + falsePositive);
174 Float_t toMinimize = std::numeric_limits<float>::max();
175 if (effTimesPur > std::numeric_limits<float>::min())
176 toMinimize = 1./(effTimesPur);
191 Log() << kINFO <<
"Calculating best set of cuts for class " 214 const TString opts(
"PopSize=100:Steps=30" );
217 std::vector<Double_t> result;
223 for( std::vector<Double_t>::iterator it = result.begin(); it<result.end(); it++ ){
253 for (
size_t iClass = 0; iClass < numClasses; ++iClass) {
255 std::vector<Float_t> mvaRes;
256 std::vector<Bool_t> mvaResTypes;
257 std::vector<Float_t> mvaResWeights;
262 mvaRes.reserve(rawMvaRes->size());
263 for (
auto item : *rawMvaRes) {
264 mvaRes.push_back(item[iClass]);
268 mvaResTypes.reserve(eventCollection.size());
269 mvaResWeights.reserve(eventCollection.size());
270 for (
auto ev : eventCollection) {
271 mvaResTypes.push_back(ev->GetClass() == iClass);
272 mvaResWeights.push_back(ev->GetWeight());
294 for (
size_t iClass = 0; iClass < numClasses; ++iClass) {
295 for (
size_t jClass = 0; jClass < numClasses; ++jClass) {
296 if (iClass == jClass) {
303 std::vector<Float_t> mvaRes;
304 std::vector<Bool_t> mvaResTypes;
305 std::vector<Float_t> mvaResWeights;
307 mvaRes.reserve(rawMvaRes->size());
308 mvaResTypes.reserve(eventCollection.size());
309 mvaResWeights.reserve(eventCollection.size());
311 for (
size_t iEvent = 0; iEvent < eventCollection.size(); ++iEvent) {
312 Event *ev = eventCollection[iEvent];
315 Float_t output_value = (*rawMvaRes)[iEvent][iClass];
316 mvaRes.push_back(output_value);
317 mvaResTypes.push_back(ev->
GetClass() == iClass);
318 mvaResWeights.push_back(ev->
GetWeight());
346 Log() << kINFO <<
"Creating multiclass response histograms..." <<
Endl;
352 std::vector<std::vector<TH1F*> > histos;
356 histos.push_back(std::vector<TH1F*>(0));
361 histos.at(iCls).push_back(
new TH1F(name,name,nbins,xmin,xmax));
376 Store(histos.at(iCls).at(jCls));
virtual const char * GetName() const
Returns name of object.
std::vector< std::vector< Float_t > > * GetValueVector()
Double_t GetEffSForEffB(Double_t effB, const UInt_t num_points=41)
Calculate the signal efficiency (sensitivity) for a given background efficiency (sensitivity).
MsgLogger & Endl(MsgLogger &ml)
std::vector< Float_t > fAchievablePur
Double_t Run(std::vector< Double_t > &pars)
Execute fitting.
virtual void SetName(const char *name)
Set the name of the TNamed.
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
const DataSetInfo * GetDataSetInfo() const
DataSet * GetDataSet() const
~ResultsMulticlass()
destructor
virtual void SetTitle(const char *title="")
Set graph title.
UInt_t GetNClasses() const
TMatrixD GetConfusionMatrix(Double_t effB)
Returns a confusion matrix where each class is pitted against each other.
std::vector< std::vector< Double_t > > fBestCuts
const std::vector< Event * > & GetEventCollection(Types::ETreeType type=Types::kMaxTreeType) const
static constexpr double mg
Class that contains all the data information.
MsgLogger & Log() const
message logger
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
std::vector< Float_t > fEventWeights
ResultsMulticlass(const DataSetInfo *dsi, TString resultsName)
constructor
std::vector< Float_t > fClassSumWeights
Class that contains all the data information.
ClassInfo * GetClassInfo(Int_t clNum) const
std::vector< std::vector< Float_t > > fMultiClassValues
void SetValue(std::vector< Float_t > &value, Int_t ievt)
The TMVA::Interval Class.
char * Form(const char *fmt,...)
Double_t EstimatorFunction(std::vector< Double_t > &)
void CreateMulticlassPerformanceHistos(TString prefix)
Create performance graphs for this classifier a multiclass setting.
void CreateMulticlassHistos(TString prefix, Int_t nbins, Int_t nbins_high)
this function fills the mva response histos for multiclass classification
std::vector< Float_t > fAchievableEff
std::vector< Double_t > GetBestMultiClassCuts(UInt_t targetClass)
calculate the best working point (optimal cut values) for the multiclass classifier ...
void SetCurrentType(Types::ETreeType type) const
ostringstream derivative to redirect and format output
TGraph * GetROCCurve(const UInt_t points=100)
Returns a new TGraph containing the ROC curve.
Class that is the base-class for a vector of result.
A Graph is a graphics object made of two arrays X and Y with npoints each.
Types::ETreeType GetTreeType() const
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
std::vector< UInt_t > fEventClasses
void Store(TObject *obj, const char *alias=0)
Interface for a fitter 'target'.
Fitter using a Genetic Algorithm.
const Event * GetEvent() const
const char * Data() const