Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TrainingHistory.cxx
Go to the documentation of this file.
1 /**********************************************************************************
2  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
3  * Package: TMVA *
4  * Class : TrainingHistory *
5  * Web : http://tmva.sourceforge.net *
6  * *
7  * Description: *
8  * Implementation (see header for description) *
9  * *
10  * Author: *
11  * Joseph McKenna <Joseph.McKenna@cern.ch> - Aarhus, Denmark *
12  * *
13  * Copyright (c) 2019: *
14  * Aarhus, Denmark *
15  * *
16  * Redistribution and use in source and binary forms, with or without *
17  * modification, are permitted according to the terms listed in LICENSE *
18  * (http://tmva.sourceforge.net/LICENSE) *
19  **********************************************************************************/
20 
21 /*! \class TMVA::TrainingHistory
22 \ingroup TMVA
23 
24 Tracking data from training. Eg, From deep learning record loss for each Epoch
25 
26 */
27 
28 
29 #include "TMVA/TrainingHistory.h"
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// constructor
33 
34 TMVA::TrainingHistory::TrainingHistory()
35 {
36 }
37 
38 TMVA::TrainingHistory::~TrainingHistory()
39 {
40  for (auto p : fHistoryData) {
41  delete p;
42  }
43 }
44 
45 void TMVA::TrainingHistory::AddValue(TString Property,Int_t stage, Double_t value)
46 {
47  if (!fHistoryMap.count(Property))
48  {
49  fHistoryMap[Property]=fHistoryData.size();
50  IterationRecord* data=new IterationRecord();
51  fHistoryData.push_back(data);
52  }
53  int iHistory=fHistoryMap.at(Property);
54  //std::cout<<"HISTORY!"<<"Adding value ("<<Property<<"):"<<stage<<"\t"<<value<<std::endl;
55  fHistoryData.at(iHistory)->push_back({stage,value});
56 }
57 
58 void TMVA::TrainingHistory::SaveHistory(TString Name)
59 {
60  //if (fHistoryData.empty()) return;
61  for ( const auto &element : fHistoryMap ) {
62  TString property = element.first;
63  Int_t iHistory = element.second;
64  Int_t nBins=fHistoryData.at(iHistory)->size();
65  Double_t xMin=fHistoryData.at(iHistory)->front().first;
66  Double_t xMax=fHistoryData.at(iHistory)->back().first;
67  Double_t BinSize=(xMax-xMin)/(Double_t)(nBins-1);
68  TH1D* h=new TH1D("TrainingHistory_"+Name+"_"+property,"TrainingHistory_"+Name+"_"+property,nBins,xMin-0.5*BinSize,xMax+0.5*BinSize);
69  for (int i=0; i<nBins; i++) {
70  h->AddBinContent(i+1,fHistoryData.at(iHistory)->at(i).second);
71  }
72  h->Print();
73  if (h!=0) {
74  h->Write();
75  delete h;
76  }
77 
78  }
79 }