11 #include "TDirectory.h"
51 static Int_t icanvas = -1;
52 Int_t ixc = 100 + (icanvas)*40;
53 Int_t iyc = 0 + (icanvas+1)*20;
58 ixc, 0 + (icanvas+1)*20, 1000, 650 );
75 cout <<
"Big troubles in \"draw_network\" (1)" << endl;
83 for (
Int_t i = 0; i < n1; i++) {
84 for (
Int_t j = 0; j < n2; j++) {
86 if (maxWeight < weight) maxWeight = weight;
92 cout <<
"Error: could not find histograms" << endl;
111 cout <<
"Big troubles in \"draw_network\" (2)" << endl;
117 draw_layer(c, h, count++, numHists+1, maxWeight);
130 t->
DrawTextNDC( 1 - c->GetRightMargin(), 1 - c->GetTopMargin() - 0.033,
131 Form(
"Epoch: %s", epoch.
Data() ) );
141 TString dirname =
"movieplots";
142 TString foutname = dirname +
"/" + hName;
147 cout <<
"storing file: " << foutname << endl;
153 TString fname =
"plots/network";
167 const Double_t LABEL_HEIGHT = 0.032;
169 Double_t effWidth = 0.8*(1.0-LABEL_WIDTH)/nLayers;
171 Double_t margY = LABEL_HEIGHT - height;
173 for (
Int_t i = 0; i < nLayers; i++) {
175 if (i == nLayers-1) label =
"Output layer";
176 Double_t cx = i*(1.0-LABEL_WIDTH)/nLayers+1.0/(2.0*nLayers)+LABEL_WIDTH;
196 Double_t width = LABEL_WIDTH + (layerWidth-4*rad);
198 Double_t effHeight = 0.8*LABEL_HEIGHT;
201 if (varNames == 0) exit(1);
205 for (
Int_t i = 0; i < nInputs; i++) {
206 if (i != nInputs-1) input = varNames[i];
207 else input =
"Bias node";
216 t->
DrawText( x, y+0.018, input +
" :");
224 const TString directories[6] = {
"InputVariables_NoTransform",
225 "InputVariables_DecorrTransform",
226 "InputVariables_PCATransform",
228 "InputVariables_Norm",
229 "InputVariables_Deco"};
232 for (
Int_t i=0; i<6; i++) {
237 cout <<
"*** Big troubles in macro \"network.cxx\": could not find directory for input variables, "
238 <<
"and hence could not determine variable names --> abort" << endl;
250 if (key->GetCycle() != 1)
continue;
252 if (!
TString(key->GetName()).Contains(
"__S") &&
253 !
TString(key->GetName()).Contains(
"__r") &&
254 !
TString(key->GetName()).Contains(
"Regression"))
256 if (
TString(key->GetName()).Contains(
"target"))
262 TH1 *sig = (
TH1*)key->ReadObj();
265 vars[ivar] = hname; ivar++;
267 if (ivar > nVars-1)
break;
270 if (ivar != nVars-1) {
271 cout <<
"*** Troubles in \"network.cxx\": did not reproduce correct number of "
272 <<
"input variables: " << ivar <<
" != " << nVars << endl;
283 switch (whichActivation) {
291 cout <<
"Activation index " << whichActivation <<
" is not known." << endl;
292 cout <<
"You messed up or you need to modify network.cxx to introduce a new "
293 <<
"activation function (and image) corresponding to this index" << endl;
296 if (activation ==
NULL) {
297 cout <<
"Could not create an image... exit" << endl;
306 TPad* p =
new TPad(name+
"", name+
"", cx-radx, cy-rady, cx+radx, cy+rady);
318 const Double_t MAX_NEURONS_NICE = 12;
328 cx1 = iHist*(1.0-LABEL_WIDTH)/nLayers + 1.0/(2.0*nLayers) + LABEL_WIDTH;
332 cx2 = (iHist+1)*(1.0-LABEL_WIDTH)/nLayers + 1.0/(2.0*nLayers) + LABEL_WIDTH;
336 if (nNeurons1 > MAX_NEURONS_NICE)
337 effRad1 = 0.8*(1.0-LABEL_HEIGHT)/(2.0*nNeurons1);
339 for (
Int_t i = 0; i < nNeurons1; i++) {
340 cy1[nNeurons1-i-1] = i*(1.0-LABEL_HEIGHT)/nNeurons1 + 1.0/(2.0*nNeurons1) + LABEL_HEIGHT;
345 effRad1*ratio, effRad1, 0, 360, 0 );
352 if (nNeurons1 > MAX_NEURONS_NICE)
continue;
354 Int_t whichActivation = 0;
355 if (iHist==0 || iHist==nLayers-1 || i==0) whichActivation = 1;
357 rad*ratio, rad, whichActivation);
361 if (iHist == 0)
draw_input_labels(nNeurons1, cy1, rad, (1.0-LABEL_WIDTH)/nLayers);
364 if (nNeurons2 > MAX_NEURONS_NICE)
365 effRad2 = 0.8*(1.0-LABEL_HEIGHT)/(2.0*nNeurons2);
367 for (
Int_t i = 0; i < nNeurons2; i++) {
368 cy2[nNeurons2-i-1] = i*(1.0-LABEL_HEIGHT)/nNeurons2 + 1.0/(2.0*nNeurons2) + LABEL_HEIGHT;
371 new TEllipse(cx2, cy2[nNeurons2-i-1], effRad2*ratio, effRad2, 0, 360, 0);
378 if (nNeurons2 > MAX_NEURONS_NICE)
continue;
380 Int_t whichActivation = 0;
381 if (iHist+1==0 || iHist+1==nLayers-1 || i==0) whichActivation = 1;
382 draw_activation(c, cx2, cy2[nNeurons2-i-1], rad*ratio, rad, whichActivation);
385 for (
Int_t i = 0; i < nNeurons1; i++) {
386 for (
Int_t j = 0; j < nNeurons2; j++) {
387 draw_synapse(cx1, cy1[i], cx2, cy2[j], effRad1*ratio, effRad2*ratio,
404 if (weightNormed == 0)
return;
412 arrow->
SetLineColor((
Int_t)((weightNormed+1.0)/2.0*(MAX_COLOR-MIN_COLOR)+MIN_COLOR+0.5));
429 if( !
gROOT->GetClass(key->GetClassName())->InheritsFrom(
"TDirectory") )
continue;
431 cout <<
"--- Found directory: " << ((
TDirectory*)key->ReadObj())->GetName() << endl;
437 while((titkey = (
TKey*)keyIt())) {
438 if( !
gROOT->GetClass(titkey->GetClassName())->InheritsFrom(
"TDirectory") )
continue;
445 cout <<
"No titles found for Method_MLP" << endl;
void network(TString fin="TMVA.root", Bool_t useTMVAStyle=kTRUE)
virtual const char * GetTitle() const
Returns title of object.
TString * get_var_names(Int_t nVars)
virtual void SetLineWidth(Width_t lwidth)
void imgconv(TCanvas *c, const TString &fname)
virtual TList * GetListOfKeys() const
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
static Int_t c_DarkBackground
TString & ReplaceAll(const TString &s1, const TString &s2)
R__EXTERN TStyle * gStyle
TFile * OpenFile(const TString &fin)
virtual TList * GetListOfKeys() const
Color_t GetTitleFillColor() const
virtual void SetConstRatio(Bool_t constRatio=kTRUE)
Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual const char * GetClassName() const
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual void SetFillStyle(Style_t fstyle)
An abstract interface to image processing library.
virtual Int_t GetNbinsX() const
UInt_t GetWindowHeight() const
void draw_activation(TCanvas *c, Double_t cx, Double_t cy, Double_t radx, Double_t rady, Int_t whichActivation)
Width_t GetTitleBorderSize() const
void SetCanvasColor(Color_t color=19)
const char * Data() const
void SetTitleBorderSize(Width_t size=2)
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
static const double x2[5]
Color_t GetTitleTextColor() const
virtual TText * DrawTextNDC(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates in NDC.
virtual void Draw(Option_t *option="")
Draw this arrow with its current attributes.
void Clear()
Clear string without changing its capacity.
Base class for several text objects.
void draw_input_labels(Int_t nInputs, Double_t *cy, Double_t rad, Double_t layerWidth)
void SetTitleTextColor(Color_t color=1)
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
virtual void Draw(Option_t *option="")
Draw this ellipse with its current attributes.
virtual void SetTextAlign(Short_t align=11)
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
A Pave (see TPave) with a text centered in the Pave.
TStyle objects may be created to define special styles.
virtual void SetLineColor(Color_t lcolor)
void draw_network(TFile *f, TDirectory *d, const TString &hName="weights_hist", Bool_t movieMode=kFALSE, const TString &epoch="")
void Initialize(Bool_t useTMVAStyle=kTRUE)
virtual void SetFillColor(Color_t fcolor)
2-D histogram with a float per channel (see TH1 documentation)}
The most important graphics class in the ROOT system.
char * Form(const char *fmt,...)
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb"...
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
UInt_t GetWindowWidth() const
static const double x1[5]
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
Describe directory structure in memory.
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 draw_layer(TCanvas *c, TH2F *h, Int_t iHist, Int_t nLayers, Double_t maxWeight)
virtual Int_t GetNbinsY() const
virtual TObject * ReadObj()
To read a TObject* from the file.
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
void SetTitleFillColor(Color_t color=1)
void draw_layer_labels(Int_t nLayers)
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
virtual void SetTextColor(Color_t tcolor=1)
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
virtual void SetTextSize(Float_t tsize=1)
Draw all kinds of Arrows.
Color_t GetCanvasColor() const
virtual void SetBorderSize(Int_t bordersize=4)
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
TImage * findImage(const char *imageName)
UInt_t GetListOfTitles(TDirectory *rfdir, TList &titles)