51 static Int_t icanvas = -1;
52 Int_t ixc = 100 + (icanvas)*40;
53 Int_t iyc = 0 + (icanvas+1)*20;
56 TString canvastitle =
Form(
"Neural Network Layout for: %s",
d->GetName());
58 ixc, 0 + (icanvas+1)*20, 1000, 650 );
60 TIter next =
d->GetListOfKeys();
68 while ((key = (
TKey*)next())) {
81 cout <<
"Big troubles in \"draw_network\" (1)" << endl;
84 std::cout<<
h->GetName()<<
"----"<<hName<<std::endl;
90 for (
Int_t i = 0; i < n1; i++) {
91 for (
Int_t j = 0; j < n2; j++) {
93 if (maxWeight < weight) maxWeight = weight;
99 cout <<
"Error: could not find histograms" << endl;
108 while ((key = (
TKey*)next())) {
118 cout <<
"Big troubles in \"draw_network\" (2)" << endl;
124 draw_layer(dataset,
c,
h, count++, numHists+1, maxWeight);
129 draw_layer_labels(numHists+1);
137 t->
DrawTextNDC( 1 -
c->GetRightMargin(), 1 -
c->GetTopMargin() - 0.033,
138 Form(
"Epoch: %s", epoch.
Data() ) );
142 if (__PRINT_LOGO__) TMVAGlob::plot_logo();
148 TString dirname =
"movieplots";
149 TString foutname = dirname +
"/" + hName;
154 cout <<
"storing file: " << foutname << endl;
160 TString fname = dataset+
"/plots/network";
161 TMVAGlob::imgconv(
c, fname );
174 const Double_t LABEL_HEIGHT = 0.032;
176 Double_t effWidth = 0.8*(1.0-LABEL_WIDTH)/nLayers;
178 Double_t margY = LABEL_HEIGHT - height;
180 for (
Int_t i = 0; i < nLayers; i++) {
182 if (i == nLayers-1) label =
"Output layer";
183 Double_t cx = i*(1.0-LABEL_WIDTH)/nLayers+1.0/(2.0*nLayers)+LABEL_WIDTH;
205 Double_t effHeight = 0.8*LABEL_HEIGHT;
208 if (varNames == 0) exit(1);
212 for (
Int_t i = 0; i < nInputs; i++) {
213 if (i != nInputs-1) input = varNames[i];
214 else input =
"Bias node";
231 const TString directories[6] = {
"InputVariables_NoTransform",
232 "InputVariables_DecorrTransform",
233 "InputVariables_PCATransform",
235 "InputVariables_Norm",
236 "InputVariables_Deco"};
239 for (
Int_t i=0; i<6; i++) {
244 cout <<
"*** Big troubles in macro \"network.cxx\": could not find directory for input variables, "
245 <<
"and hence could not determine variable names --> abort" << endl;
256 while ((key = (
TKey*)next())) {
272 vars[ivar] = hname; ivar++;
274 if (ivar > nVars-1)
break;
277 if (ivar != nVars-1) {
278 cout <<
"*** Troubles in \"network.cxx\": did not reproduce correct number of "
279 <<
"input variables: " << ivar <<
" != " << nVars << endl;
288 TImage *activation = NULL;
290 switch (whichActivation) {
298 cout <<
"Activation index " << whichActivation <<
" is not known." << endl;
299 cout <<
"You messed up or you need to modify network.cxx to introduce a new "
300 <<
"activation function (and image) corresponding to this index" << endl;
303 if (activation == NULL) {
304 cout <<
"Could not create an image... exit" << endl;
325 const Double_t MAX_NEURONS_NICE = 12;
332 rad = 0.04*650/
c->GetWindowHeight();
334 Int_t nNeurons1 =
h->GetNbinsX();
335 cx1 = iHist*(1.0-LABEL_WIDTH)/nLayers + 1.0/(2.0*nLayers) + LABEL_WIDTH;
338 Int_t nNeurons2 =
h->GetNbinsY();
339 cx2 = (iHist+1)*(1.0-LABEL_WIDTH)/nLayers + 1.0/(2.0*nLayers) + LABEL_WIDTH;
343 if (nNeurons1 > MAX_NEURONS_NICE)
344 effRad1 = 0.8*(1.0-LABEL_HEIGHT)/(2.0*nNeurons1);
346 for (
Int_t i = 0; i < nNeurons1; i++) {
347 cy1[nNeurons1-i-1] = i*(1.0-LABEL_HEIGHT)/nNeurons1 + 1.0/(2.0*nNeurons1) + LABEL_HEIGHT;
352 effRad1*ratio, effRad1, 0, 360, 0 );
359 if (nNeurons1 > MAX_NEURONS_NICE)
continue;
361 Int_t whichActivation = 0;
362 if (iHist==0 || iHist==nLayers-1 || i==0) whichActivation = 1;
364 rad*ratio, rad, whichActivation);
368 if (iHist == 0)
draw_input_labels(dataset,nNeurons1, cy1, rad, (1.0-LABEL_WIDTH)/nLayers);
371 if (nNeurons2 > MAX_NEURONS_NICE)
372 effRad2 = 0.8*(1.0-LABEL_HEIGHT)/(2.0*nNeurons2);
374 for (
Int_t i = 0; i < nNeurons2; i++) {
375 cy2[nNeurons2-i-1] = i*(1.0-LABEL_HEIGHT)/nNeurons2 + 1.0/(2.0*nNeurons2) + LABEL_HEIGHT;
378 new TEllipse(cx2, cy2[nNeurons2-i-1], effRad2*ratio, effRad2, 0, 360, 0);
385 if (nNeurons2 > MAX_NEURONS_NICE)
continue;
387 Int_t whichActivation = 0;
388 if (iHist+1==0 || iHist+1==nLayers-1 || i==0) whichActivation = 1;
389 draw_activation(
c, cx2, cy2[nNeurons2-i-1], rad*ratio, rad, whichActivation);
392 for (
Int_t i = 0; i < nNeurons1; i++) {
393 for (
Int_t j = 0; j < nNeurons2; j++) {
394 draw_synapse(cx1, cy1[i], cx2, cy2[j], effRad1*ratio, effRad2*ratio,
395 h->GetBinContent(i+1, j+1)/maxWeight);
411 if (weightNormed == 0)
return;
416 arrow->SetFillColor(1);
417 arrow->SetFillStyle(1001);
428 TMVAGlob::Initialize( useTMVAStyle );
432 TIter next(
file->GetDirectory(dataset.
Data())->GetListOfKeys());
434 while( (key = (
TKey*)next()) ) {
436 if( !
gROOT->GetClass(key->
GetClassName())->InheritsFrom(
"TDirectory") )
continue;
438 cout <<
"--- Found directory: " << ((
TDirectory*)key->
ReadObj())->GetName() << endl;
444 while((titkey = (
TKey*)keyIt())) {
445 if( !
gROOT->GetClass(titkey->
GetClassName())->InheritsFrom(
"TDirectory") )
continue;
450 UInt_t ni = TMVAGlob::GetListOfTitles( dir, titles );
452 cout <<
"No titles found for Method_MLP" << endl;
static const double x2[5]
static const double x1[5]
include TDocParser_001 C image html pict1_TDocParser_001 png width
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Draw all kinds of Arrows.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetConstRatio(Bool_t constRatio=kTRUE)
Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory named "apath".
Describe directory structure in memory.
virtual TList * GetListOfKeys() const
virtual Bool_t cd(const char *path=nullptr)
Change current directory to "this" directory.
virtual void Draw(Option_t *option="")
Draw this ellipse with its current attributes.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
TH1 is the base class of all histogram classes in ROOT.
2-D histogram with a float per channel (see TH1 documentation)}
An abstract interface to image processing library.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual const char * GetClassName() const
Short_t GetCycle() const
Return cycle number associated to this key.
virtual TObject * ReadObj()
To read a TObject* from the file.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
The most important graphics class in the ROOT system.
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
A Pave (see TPave) with a text centered in the Pave.
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
virtual void SetBorderSize(Int_t bordersize=4)
void Clear()
Clear string without changing its capacity.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TStyle objects may be created to define special styles.
void SetCanvasColor(Color_t color=19)
void SetTitleBorderSize(Width_t size=2)
Color_t GetTitleFillColor() const
void SetTitleTextColor(Color_t color=1)
Width_t GetTitleBorderSize() const
void SetTitleFillColor(Color_t color=1)
Color_t GetCanvasColor() const
Color_t GetTitleTextColor() const
Base class for several text objects.
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
virtual TText * DrawTextNDC(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates in NDC.
TImage * findImage(const char *imageName)
TString * get_var_names(TString dataset, Int_t nVars)
void draw_layer(TString dataset, TCanvas *c, TH2F *h, Int_t iHist, Int_t nLayers, Double_t maxWeight)
void draw_activation(TCanvas *c, Double_t cx, Double_t cy, Double_t radx, Double_t rady, Int_t whichActivation)
void draw_network(TString dataset, TFile *f, TDirectory *d, const TString &hName="weights_hist", Bool_t movieMode=kFALSE, const TString &epoch="")
void draw_input_labels(TString dataset, Int_t nInputs, Double_t *cy, Double_t rad, Double_t layerWidth)
void draw_layer_labels(Int_t nLayers)
void draw_synapse(Double_t cx1, Double_t cy1, Double_t cx2, Double_t cy2, Double_t rad1, Double_t rad2, Double_t weightNormed)
void network(TString dataset, TString fin="TMVA.root", Bool_t useTMVAStyle=kTRUE)
static Int_t c_DarkBackground