Logo ROOT   6.14/05
Reference Guide
MethodDNN.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Peter Speckmayer
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : MethodDNN *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * A neural network implementation *
12  * *
13  * Authors (alphabetical): *
14  * Simon Pfreundschuh <s.pfreundschuh@gmail.com> - CERN, Switzerland *
15  * Peter Speckmayer <peter.speckmayer@gmx.ch> - CERN, Switzerland *
16  * *
17  * Copyright (c) 2005-2015: *
18  * CERN, Switzerland *
19  * U. of Victoria, Canada *
20  * MPI-K Heidelberg, Germany *
21  * U. of Bonn, Germany *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 /*! \class TMVA::MethodDNN
29 \ingroup TMVA
30 Deep Neural Network Implementation.
31 */
32 
33 #include "TMVA/MethodDNN.h"
34 
35 #include "TString.h"
36 #include "TTree.h"
37 #include "TFile.h"
38 #include "TFormula.h"
39 
40 #include "TMVA/ClassifierFactory.h"
41 #include "TMVA/Configurable.h"
42 #include "TMVA/IMethod.h"
43 #include "TMVA/MsgLogger.h"
44 #include "TMVA/MethodBase.h"
45 #include "TMVA/Timer.h"
46 #include "TMVA/Types.h"
47 #include "TMVA/Tools.h"
48 #include "TMVA/Config.h"
49 #include "TMVA/Ranking.h"
50 
51 #include "TMVA/DNN/Net.h"
53 
54 #include "TMVA/NeuralNet.h"
55 #include "TMVA/Monitoring.h"
56 
57 #include <algorithm>
58 #include <iostream>
59 #include <string>
60 #include <iomanip>
61 
62 REGISTER_METHOD(DNN)
63 
65 
66 namespace TMVA
67 {
68  using namespace DNN;
69 
70  ////////////////////////////////////////////////////////////////////////////////
71  /// standard constructor
72 
73  TMVA::MethodDNN::MethodDNN(const TString &jobName, const TString &methodTitle, DataSetInfo &theData,
74  const TString &theOption)
75  : MethodBase(jobName, Types::kDNN, methodTitle, theData, theOption), fWeightInitialization(), fOutputFunction(),
76  fLayoutString(), fErrorStrategy(), fTrainingStrategyString(), fWeightInitializationString(),
77  fArchitectureString(), fTrainingSettings(), fResume(false), fSettings()
78  {
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// constructor from a weight file
83 
84 TMVA::MethodDNN::MethodDNN(DataSetInfo& theData,
85  const TString& theWeightFile)
86  : MethodBase( Types::kDNN, theData, theWeightFile),
90 {
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// destructor
97 
99 {
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// MLP can handle classification with 2 classes and regression with
106 /// one regression-target
107 
109  UInt_t numberClasses,
110  UInt_t /*numberTargets*/ )
111 {
112  if (type == Types::kClassification && numberClasses == 2 ) return kTRUE;
113  if (type == Types::kMulticlass ) return kTRUE;
114  if (type == Types::kRegression ) return kTRUE;
115 
116  return kFALSE;
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// default initializations
121 
122 void TMVA::MethodDNN::Init() {}
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Options to be set in the option string:
126 ///
127 /// - LearningRate <float> DNN learning rate parameter.
128 /// - DecayRate <float> Decay rate for learning parameter.
129 /// - TestRate <int> Period of validation set error computation.
130 /// - BatchSize <int> Number of event per batch.
131 ///
132 /// - ValidationSize <string> How many events to use for validation. "0.2"
133 /// or "20%" indicates that a fifth of the
134 /// training data should be used. "100"
135 /// indicates that 100 events should be used.
136 
138 {
139 
140  DeclareOptionRef(fLayoutString="SOFTSIGN|(N+100)*2,LINEAR",
141  "Layout",
142  "Layout of the network.");
143 
144  DeclareOptionRef(fValidationSize = "20%", "ValidationSize",
145  "Part of the training data to use for "
146  "validation. Specify as 0.2 or 20% to use a "
147  "fifth of the data set as validation set. "
148  "Specify as 100 to use exactly 100 events. "
149  "(Default: 20%)");
150 
151  DeclareOptionRef(fErrorStrategy="CROSSENTROPY",
152  "ErrorStrategy",
153  "Loss function: Mean squared error (regression)"
154  " or cross entropy (binary classification).");
155  AddPreDefVal(TString("CROSSENTROPY"));
156  AddPreDefVal(TString("SUMOFSQUARES"));
157  AddPreDefVal(TString("MUTUALEXCLUSIVE"));
158 
160  "WeightInitialization",
161  "Weight initialization strategy");
162  AddPreDefVal(TString("XAVIER"));
163  AddPreDefVal(TString("XAVIERUNIFORM"));
164 
165  DeclareOptionRef(fArchitectureString = "CPU", "Architecture", "Which architecture to perform the training on.");
166  AddPreDefVal(TString("STANDARD"));
167  AddPreDefVal(TString("CPU"));
168  AddPreDefVal(TString("GPU"));
169  AddPreDefVal(TString("OPENCL"));
170 
172  fTrainingStrategyString = "LearningRate=1e-1,"
173  "Momentum=0.3,"
174  "Repetitions=3,"
175  "ConvergenceSteps=50,"
176  "BatchSize=30,"
177  "TestRepetitions=7,"
178  "WeightDecay=0.0,"
179  "Renormalize=L2,"
180  "DropConfig=0.0,"
181  "DropRepetitions=5|LearningRate=1e-4,"
182  "Momentum=0.3,"
183  "Repetitions=3,"
184  "ConvergenceSteps=50,"
185  "BatchSize=20,"
186  "TestRepetitions=7,"
187  "WeightDecay=0.001,"
188  "Renormalize=L2,"
189  "DropConfig=0.0+0.5+0.5,"
190  "DropRepetitions=5,"
191  "Multithreading=True",
192  "TrainingStrategy",
193  "Defines the training strategies.");
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// parse layout specification string and return a vector, each entry
198 /// containing the number of neurons to go in each successive layer
199 
201  -> LayoutVector_t
202 {
203  LayoutVector_t layout;
204  const TString layerDelimiter(",");
205  const TString subDelimiter("|");
206 
207  const size_t inputSize = GetNvar();
208 
209  TObjArray* layerStrings = layoutString.Tokenize(layerDelimiter);
210  TIter nextLayer (layerStrings);
211  TObjString* layerString = (TObjString*)nextLayer ();
212 
213  for (; layerString != nullptr; layerString = (TObjString*) nextLayer()) {
214  int numNodes = 0;
215  EActivationFunction activationFunction = EActivationFunction::kTanh;
216 
217  TObjArray* subStrings = layerString->GetString().Tokenize(subDelimiter);
218  TIter nextToken (subStrings);
219  TObjString* token = (TObjString *) nextToken();
220  int idxToken = 0;
221  for (; token != nullptr; token = (TObjString *) nextToken()) {
222  switch (idxToken)
223  {
224  case 0:
225  {
226  TString strActFnc (token->GetString ());
227  if (strActFnc == "RELU") {
228  activationFunction = DNN::EActivationFunction::kRelu;
229  } else if (strActFnc == "TANH") {
230  activationFunction = DNN::EActivationFunction::kTanh;
231  } else if (strActFnc == "SYMMRELU") {
232  activationFunction = DNN::EActivationFunction::kSymmRelu;
233  } else if (strActFnc == "SOFTSIGN") {
234  activationFunction = DNN::EActivationFunction::kSoftSign;
235  } else if (strActFnc == "SIGMOID") {
236  activationFunction = DNN::EActivationFunction::kSigmoid;
237  } else if (strActFnc == "LINEAR") {
238  activationFunction = DNN::EActivationFunction::kIdentity;
239  } else if (strActFnc == "GAUSS") {
240  activationFunction = DNN::EActivationFunction::kGauss;
241  }
242  }
243  break;
244  case 1: // number of nodes
245  {
246  TString strNumNodes (token->GetString ());
247  TString strN ("x");
248  strNumNodes.ReplaceAll ("N", strN);
249  strNumNodes.ReplaceAll ("n", strN);
250  TFormula fml ("tmp",strNumNodes);
251  numNodes = fml.Eval (inputSize);
252  }
253  break;
254  }
255  ++idxToken;
256  }
257  layout.push_back(std::make_pair(numNodes, activationFunction));
258  }
259  return layout;
260 }
261 
262 ////////////////////////////////////////////////////////////////////////////////
263 /// parse key value pairs in blocks -> return vector of blocks with map of key value pairs
264 
266  TString blockDelim,
267  TString tokenDelim)
269 {
270  KeyValueVector_t blockKeyValues;
271  const TString keyValueDelim ("=");
272 
273  TObjArray* blockStrings = parseString.Tokenize (blockDelim);
274  TIter nextBlock (blockStrings);
275  TObjString* blockString = (TObjString *) nextBlock();
276 
277  for (; blockString != nullptr; blockString = (TObjString *) nextBlock())
278  {
279  blockKeyValues.push_back (std::map<TString,TString>());
280  std::map<TString,TString>& currentBlock = blockKeyValues.back ();
281 
282  TObjArray* subStrings = blockString->GetString ().Tokenize (tokenDelim);
283  TIter nextToken (subStrings);
284  TObjString* token = (TObjString*)nextToken ();
285 
286  for (; token != nullptr; token = (TObjString *)nextToken())
287  {
288  TString strKeyValue (token->GetString ());
289  int delimPos = strKeyValue.First (keyValueDelim.Data ());
290  if (delimPos <= 0)
291  continue;
292 
293  TString strKey = TString (strKeyValue (0, delimPos));
294  strKey.ToUpper();
295  TString strValue = TString (strKeyValue (delimPos+1, strKeyValue.Length ()));
296 
297  strKey.Strip (TString::kBoth, ' ');
298  strValue.Strip (TString::kBoth, ' ');
299 
300  currentBlock.insert (std::make_pair (strKey, strValue));
301  }
302  }
303  return blockKeyValues;
304 }
305 
306 ////////////////////////////////////////////////////////////////////////////////
307 
308 TString fetchValue (const std::map<TString, TString>& keyValueMap, TString key)
309 {
310  key.ToUpper ();
311  std::map<TString, TString>::const_iterator it = keyValueMap.find (key);
312  if (it == keyValueMap.end()) {
313  return TString ("");
314  }
315  return it->second;
316 }
317 
318 ////////////////////////////////////////////////////////////////////////////////
319 
320 template <typename T>
321 T fetchValue(const std::map<TString,TString>& keyValueMap,
322  TString key,
323  T defaultValue);
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 
327 template <>
328 int fetchValue(const std::map<TString,TString>& keyValueMap,
329  TString key,
330  int defaultValue)
331 {
332  TString value (fetchValue (keyValueMap, key));
333  if (value == "") {
334  return defaultValue;
335  }
336  return value.Atoi ();
337 }
338 
339 ////////////////////////////////////////////////////////////////////////////////
340 
341 template <>
342 double fetchValue (const std::map<TString,TString>& keyValueMap,
343  TString key, double defaultValue)
344 {
345  TString value (fetchValue (keyValueMap, key));
346  if (value == "") {
347  return defaultValue;
348  }
349  return value.Atof ();
350 }
351 
352 ////////////////////////////////////////////////////////////////////////////////
353 
354 template <>
355 TString fetchValue (const std::map<TString,TString>& keyValueMap,
356  TString key, TString defaultValue)
357 {
358  TString value (fetchValue (keyValueMap, key));
359  if (value == "") {
360  return defaultValue;
361  }
362  return value;
363 }
364 
365 ////////////////////////////////////////////////////////////////////////////////
366 
367 template <>
368 bool fetchValue (const std::map<TString,TString>& keyValueMap,
369  TString key, bool defaultValue)
370 {
371  TString value (fetchValue (keyValueMap, key));
372  if (value == "") {
373  return defaultValue;
374  }
375  value.ToUpper ();
376  if (value == "TRUE" || value == "T" || value == "1") {
377  return true;
378  }
379  return false;
380 }
381 
382 ////////////////////////////////////////////////////////////////////////////////
383 
384 template <>
385 std::vector<double> fetchValue(const std::map<TString, TString> & keyValueMap,
386  TString key,
387  std::vector<double> defaultValue)
388 {
389  TString parseString (fetchValue (keyValueMap, key));
390  if (parseString == "") {
391  return defaultValue;
392  }
393  parseString.ToUpper ();
394  std::vector<double> values;
395 
396  const TString tokenDelim ("+");
397  TObjArray* tokenStrings = parseString.Tokenize (tokenDelim);
398  TIter nextToken (tokenStrings);
399  TObjString* tokenString = (TObjString*)nextToken ();
400  for (; tokenString != NULL; tokenString = (TObjString*)nextToken ()) {
401  std::stringstream sstr;
402  double currentValue;
403  sstr << tokenString->GetString ().Data ();
404  sstr >> currentValue;
405  values.push_back (currentValue);
406  }
407  return values;
408 }
409 
410 ////////////////////////////////////////////////////////////////////////////////
411 
413 {
415  Log() << kINFO
416  << "Will ignore negative events in training!"
417  << Endl;
418  }
419 
420  if (fArchitectureString == "STANDARD") {
421  Log() << kERROR << "The STANDARD architecture has been deprecated. "
422  "Please use Architecture=CPU or Architecture=CPU."
423  "See the TMVA Users' Guide for instructions if you "
424  "encounter problems."
425  << Endl;
426  Log() << kFATAL << "The STANDARD architecture has been deprecated. "
427  "Please use Architecture=CPU or Architecture=CPU."
428  "See the TMVA Users' Guide for instructions if you "
429  "encounter problems."
430  << Endl;
431  }
432 
433  if (fArchitectureString == "OPENCL") {
434  Log() << kERROR << "The OPENCL architecture has not been implemented yet. "
435  "Please use Architecture=CPU or Architecture=CPU for the "
436  "time being. See the TMVA Users' Guide for instructions "
437  "if you encounter problems."
438  << Endl;
439  Log() << kFATAL << "The OPENCL architecture has not been implemented yet. "
440  "Please use Architecture=CPU or Architecture=CPU for the "
441  "time being. See the TMVA Users' Guide for instructions "
442  "if you encounter problems."
443  << Endl;
444  }
445 
446  if (fArchitectureString == "GPU") {
447 #ifndef DNNCUDA // Included only if DNNCUDA flag is _not_ set.
448  Log() << kERROR << "CUDA backend not enabled. Please make sure "
449  "you have CUDA installed and it was successfully "
450  "detected by CMAKE."
451  << Endl;
452  Log() << kFATAL << "CUDA backend not enabled. Please make sure "
453  "you have CUDA installed and it was successfully "
454  "detected by CMAKE."
455  << Endl;
456 #endif // DNNCUDA
457  }
458 
459  if (fArchitectureString == "CPU") {
460 #ifndef DNNCPU // Included only if DNNCPU flag is _not_ set.
461  Log() << kERROR << "Multi-core CPU backend not enabled. Please make sure "
462  "you have a BLAS implementation and it was successfully "
463  "detected by CMake as well that the imt CMake flag is set."
464  << Endl;
465  Log() << kFATAL << "Multi-core CPU backend not enabled. Please make sure "
466  "you have a BLAS implementation and it was successfully "
467  "detected by CMake as well that the imt CMake flag is set."
468  << Endl;
469 #endif // DNNCPU
470  }
471 
472  //
473  // Set network structure.
474  //
475 
477  size_t inputSize = GetNVariables ();
478  size_t outputSize = 1;
479  if (fAnalysisType == Types::kRegression && GetNTargets() != 0) {
480  outputSize = GetNTargets();
481  } else if (fAnalysisType == Types::kMulticlass && DataInfo().GetNClasses() >= 2) {
482  outputSize = DataInfo().GetNClasses();
483  }
484 
485  fNet.SetBatchSize(1);
486  fNet.SetInputWidth(inputSize);
487 
488  auto itLayout = std::begin (fLayout);
489  auto itLayoutEnd = std::end (fLayout)-1;
490  for ( ; itLayout != itLayoutEnd; ++itLayout) {
491  fNet.AddLayer((*itLayout).first, (*itLayout).second);
492  }
493  fNet.AddLayer(outputSize, EActivationFunction::kIdentity);
494 
495  //
496  // Loss function and output.
497  //
498 
499  fOutputFunction = EOutputFunction::kSigmoid;
501  {
502  if (fErrorStrategy == "SUMOFSQUARES") {
503  fNet.SetLossFunction(ELossFunction::kMeanSquaredError);
504  }
505  if (fErrorStrategy == "CROSSENTROPY") {
506  fNet.SetLossFunction(ELossFunction::kCrossEntropy);
507  }
508  fOutputFunction = EOutputFunction::kSigmoid;
509  } else if (fAnalysisType == Types::kRegression) {
510  if (fErrorStrategy != "SUMOFSQUARES") {
511  Log () << kWARNING << "For regression only SUMOFSQUARES is a valid "
512  << " neural net error function. Setting error function to "
513  << " SUMOFSQUARES now." << Endl;
514  }
515  fNet.SetLossFunction(ELossFunction::kMeanSquaredError);
516  fOutputFunction = EOutputFunction::kIdentity;
517  } else if (fAnalysisType == Types::kMulticlass) {
518  if (fErrorStrategy == "SUMOFSQUARES") {
519  fNet.SetLossFunction(ELossFunction::kMeanSquaredError);
520  }
521  if (fErrorStrategy == "CROSSENTROPY") {
522  fNet.SetLossFunction(ELossFunction::kCrossEntropy);
523  }
524  if (fErrorStrategy == "MUTUALEXCLUSIVE") {
525  fNet.SetLossFunction(ELossFunction::kSoftmaxCrossEntropy);
526  }
527  fOutputFunction = EOutputFunction::kSoftmax;
528  }
529 
530  //
531  // Initialization
532  //
533 
534  if (fWeightInitializationString == "XAVIER") {
536  }
537  else if (fWeightInitializationString == "XAVIERUNIFORM") {
539  }
540  else {
542  }
543 
544  //
545  // Training settings.
546  //
547 
548  // Force validation of the ValidationSize option
549  GetNumValidationSamples();
550 
552  TString ("|"),
553  TString (","));
554 
555  std::cout << "Parsed Training DNN string " << fTrainingStrategyString << std::endl;
556  std::cout << "STring has size " << strategyKeyValues.size() << std::endl;
557  for (auto& block : strategyKeyValues) {
558  TTrainingSettings settings;
559 
560  settings.convergenceSteps = fetchValue(block, "ConvergenceSteps", 100);
561  settings.batchSize = fetchValue(block, "BatchSize", 30);
562  settings.testInterval = fetchValue(block, "TestRepetitions", 7);
563  settings.weightDecay = fetchValue(block, "WeightDecay", 0.0);
564  settings.learningRate = fetchValue(block, "LearningRate", 1e-5);
565  settings.momentum = fetchValue(block, "Momentum", 0.3);
566  settings.dropoutProbabilities = fetchValue(block, "DropConfig",
567  std::vector<Double_t>());
568 
569  TString regularization = fetchValue(block, "Regularization",
570  TString ("NONE"));
571  if (regularization == "L1") {
573  } else if (regularization == "L2") {
575  } else {
577  }
578 
579  TString strMultithreading = fetchValue(block, "Multithreading",
580  TString ("True"));
581  if (strMultithreading.BeginsWith ("T")) {
582  settings.multithreading = true;
583  } else {
584  settings.multithreading = false;
585  }
586 
587  fTrainingSettings.push_back(settings);
588  }
589 }
590 
591 ////////////////////////////////////////////////////////////////////////////////
592 /// Validation of the ValidationSize option. Allowed formats are 20%, 0.2 and
593 /// 100 etc.
594 /// - 20% and 0.2 selects 20% of the training set as validation data.
595 /// - 100 selects 100 events as the validation data.
596 ///
597 /// @return number of samples in validation set
598 ///
599 
601 {
602  Int_t nValidationSamples = 0;
603  UInt_t trainingSetSize = GetEventCollection(Types::kTraining).size();
604 
605  // Parsing + Validation
606  // --------------------
607  if (fValidationSize.EndsWith("%")) {
608  // Relative spec. format 20%
609  TString intValStr = TString(fValidationSize.Strip(TString::kTrailing, '%'));
610 
611  if (intValStr.IsFloat()) {
612  Double_t valSizeAsDouble = fValidationSize.Atof() / 100.0;
613  nValidationSamples = GetEventCollection(Types::kTraining).size() * valSizeAsDouble;
614  } else {
615  Log() << kFATAL << "Cannot parse number \"" << fValidationSize
616  << "\". Expected string like \"20%\" or \"20.0%\"." << Endl;
617  }
618  } else if (fValidationSize.IsFloat()) {
619  Double_t valSizeAsDouble = fValidationSize.Atof();
620 
621  if (valSizeAsDouble < 1.0) {
622  // Relative spec. format 0.2
623  nValidationSamples = GetEventCollection(Types::kTraining).size() * valSizeAsDouble;
624  } else {
625  // Absolute spec format 100 or 100.0
626  nValidationSamples = valSizeAsDouble;
627  }
628  } else {
629  Log() << kFATAL << "Cannot parse number \"" << fValidationSize << "\". Expected string like \"0.2\" or \"100\"."
630  << Endl;
631  }
632 
633  // Value validation
634  // ----------------
635  if (nValidationSamples < 0) {
636  Log() << kFATAL << "Validation size \"" << fValidationSize << "\" is negative." << Endl;
637  }
638 
639  if (nValidationSamples == 0) {
640  Log() << kFATAL << "Validation size \"" << fValidationSize << "\" is zero." << Endl;
641  }
642 
643  if (nValidationSamples >= (Int_t)trainingSetSize) {
644  Log() << kFATAL << "Validation size \"" << fValidationSize
645  << "\" is larger than or equal in size to training set (size=\"" << trainingSetSize << "\")." << Endl;
646  }
647 
648  return nValidationSamples;
649 }
650 
651 ////////////////////////////////////////////////////////////////////////////////
652 
654 {
656  std::vector<TString> titles = {"Error on training set", "Error on test set"};
657  fInteractive->Init(titles);
658  // JsMVA progress bar maximum (100%)
659  fIPyMaxIter = 100;
660  }
661 
662  if (fArchitectureString == "GPU") {
663  TrainGpu();
666  return;
667  } else if (fArchitectureString == "OpenCL") {
668  Log() << kFATAL << "OpenCL backend not yet supported." << Endl;
669  return;
670  } else if (fArchitectureString == "CPU") {
671  TrainCpu();
674  return;
675  }
676 
677  Log() << kINFO << "Using Standard Implementation.";
678 
679  std::vector<Pattern> trainPattern;
680  std::vector<Pattern> testPattern;
681 
682  size_t nValidationSamples = GetNumValidationSamples();
683  size_t nTrainingSamples = GetEventCollection(Types::kTraining).size() - nValidationSamples;
684 
685  const std::vector<TMVA::Event *> &allData = GetEventCollection(Types::kTraining);
686  const std::vector<TMVA::Event *> eventCollectionTraining{allData.begin(), allData.begin() + nTrainingSamples};
687  const std::vector<TMVA::Event *> eventCollectionTesting{allData.begin() + nTrainingSamples, allData.end()};
688 
689  for (auto &event : eventCollectionTraining) {
690  const std::vector<Float_t>& values = event->GetValues();
692  double outputValue = event->GetClass () == 0 ? 0.9 : 0.1;
693  trainPattern.push_back(Pattern (values.begin(),
694  values.end(),
695  outputValue,
696  event->GetWeight()));
697  trainPattern.back().addInput(1.0);
698  } else if (fAnalysisType == Types::kMulticlass) {
699  std::vector<Float_t> oneHot(DataInfo().GetNClasses(), 0.0);
700  oneHot[event->GetClass()] = 1.0;
701  trainPattern.push_back(Pattern (values.begin(), values.end(),
702  oneHot.cbegin(), oneHot.cend(),
703  event->GetWeight()));
704  trainPattern.back().addInput(1.0);
705  } else {
706  const std::vector<Float_t>& targets = event->GetTargets ();
707  trainPattern.push_back(Pattern(values.begin(),
708  values.end(),
709  targets.begin(),
710  targets.end(),
711  event->GetWeight ()));
712  trainPattern.back ().addInput (1.0); // bias node
713  }
714  }
715 
716  for (auto &event : eventCollectionTesting) {
717  const std::vector<Float_t>& values = event->GetValues();
719  double outputValue = event->GetClass () == 0 ? 0.9 : 0.1;
720  testPattern.push_back(Pattern (values.begin(),
721  values.end(),
722  outputValue,
723  event->GetWeight()));
724  testPattern.back().addInput(1.0);
725  } else if (fAnalysisType == Types::kMulticlass) {
726  std::vector<Float_t> oneHot(DataInfo().GetNClasses(), 0.0);
727  oneHot[event->GetClass()] = 1.0;
728  testPattern.push_back(Pattern (values.begin(), values.end(),
729  oneHot.cbegin(), oneHot.cend(),
730  event->GetWeight()));
731  testPattern.back().addInput(1.0);
732  } else {
733  const std::vector<Float_t>& targets = event->GetTargets ();
734  testPattern.push_back(Pattern(values.begin(),
735  values.end(),
736  targets.begin(),
737  targets.end(),
738  event->GetWeight ()));
739  testPattern.back ().addInput (1.0); // bias node
740  }
741  }
742 
743  TMVA::DNN::Net net;
744  std::vector<double> weights;
745 
747 
748  net.setInputSize(fNet.GetInputWidth() + 1);
749  net.setOutputSize(fNet.GetOutputWidth() + 1);
750 
751  for (size_t i = 0; i < fNet.GetDepth(); i++) {
752  EActivationFunction f = fNet.GetLayer(i).GetActivationFunction();
753  EnumFunction g = EnumFunction::LINEAR;
754  switch(f) {
755  case EActivationFunction::kIdentity: g = EnumFunction::LINEAR; break;
756  case EActivationFunction::kRelu: g = EnumFunction::RELU; break;
757  case EActivationFunction::kSigmoid: g = EnumFunction::SIGMOID; break;
758  case EActivationFunction::kTanh: g = EnumFunction::TANH; break;
759  case EActivationFunction::kSymmRelu: g = EnumFunction::SYMMRELU; break;
760  case EActivationFunction::kSoftSign: g = EnumFunction::SOFTSIGN; break;
761  case EActivationFunction::kGauss: g = EnumFunction::GAUSS; break;
762  }
763  if (i < fNet.GetDepth() - 1) {
764  net.addLayer(Layer(fNet.GetLayer(i).GetWidth(), g));
765  } else {
766  ModeOutputValues h = ModeOutputValues::DIRECT;
767  switch(fOutputFunction) {
768  case EOutputFunction::kIdentity: h = ModeOutputValues::DIRECT; break;
769  case EOutputFunction::kSigmoid: h = ModeOutputValues::SIGMOID; break;
770  case EOutputFunction::kSoftmax: h = ModeOutputValues::SOFTMAX; break;
771  }
772  net.addLayer(Layer(fNet.GetLayer(i).GetWidth(), g, h));
773  }
774  }
775 
776  switch(fNet.GetLossFunction()) {
777  case ELossFunction::kMeanSquaredError:
778  net.setErrorFunction(ModeErrorFunction::SUMOFSQUARES);
779  break;
780  case ELossFunction::kCrossEntropy:
781  net.setErrorFunction(ModeErrorFunction::CROSSENTROPY);
782  break;
783  case ELossFunction::kSoftmaxCrossEntropy:
784  net.setErrorFunction(ModeErrorFunction::CROSSENTROPY_MUTUALEXCLUSIVE);
785  break;
786  }
787 
788  switch(fWeightInitialization) {
789  case EInitialization::kGauss:
790  net.initializeWeights(WeightInitializationStrategy::XAVIER,
791  std::back_inserter(weights));
792  break;
793  case EInitialization::kUniform:
794  net.initializeWeights(WeightInitializationStrategy::XAVIERUNIFORM,
795  std::back_inserter(weights));
796  break;
797  default:
798  net.initializeWeights(WeightInitializationStrategy::XAVIER,
799  std::back_inserter(weights));
800  break;
801  }
802 
803  int idxSetting = 0;
804  for (auto s : fTrainingSettings) {
805 
807  switch(s.regularization) {
809  case ERegularization::kL1: r = EnumRegularization::L1; break;
810  case ERegularization::kL2: r = EnumRegularization::L2; break;
811  }
812 
813  Settings * settings = new Settings(TString(), s.convergenceSteps, s.batchSize,
814  s.testInterval, s.weightDecay, r,
815  MinimizerType::fSteepest, s.learningRate,
816  s.momentum, 1, s.multithreading);
817  std::shared_ptr<Settings> ptrSettings(settings);
818  ptrSettings->setMonitoring (0);
819  Log() << kINFO
820  << "Training with learning rate = " << ptrSettings->learningRate ()
821  << ", momentum = " << ptrSettings->momentum ()
822  << ", repetitions = " << ptrSettings->repetitions ()
823  << Endl;
824 
825  ptrSettings->setProgressLimits ((idxSetting)*100.0/(fSettings.size ()),
826  (idxSetting+1)*100.0/(fSettings.size ()));
827 
828  const std::vector<double>& dropConfig = ptrSettings->dropFractions ();
829  if (!dropConfig.empty ()) {
830  Log () << kINFO << "Drop configuration" << Endl
831  << " drop repetitions = " << ptrSettings->dropRepetitions()
832  << Endl;
833  }
834 
835  int idx = 0;
836  for (auto f : dropConfig) {
837  Log () << kINFO << " Layer " << idx << " = " << f << Endl;
838  ++idx;
839  }
840  Log () << kINFO << Endl;
841 
842  DNN::Steepest minimizer(ptrSettings->learningRate(),
843  ptrSettings->momentum(),
844  ptrSettings->repetitions());
845  net.train(weights, trainPattern, testPattern, minimizer, *ptrSettings.get());
846  ptrSettings.reset();
847  Log () << kINFO << Endl;
848  idxSetting++;
849  }
850  size_t weightIndex = 0;
851  for (size_t l = 0; l < fNet.GetDepth(); l++) {
852  auto & layerWeights = fNet.GetLayer(l).GetWeights();
853  for (Int_t j = 0; j < layerWeights.GetNcols(); j++) {
854  for (Int_t i = 0; i < layerWeights.GetNrows(); i++) {
855  layerWeights(i,j) = weights[weightIndex];
856  weightIndex++;
857  }
858  }
859  auto & layerBiases = fNet.GetLayer(l).GetBiases();
860  if (l == 0) {
861  for (Int_t i = 0; i < layerBiases.GetNrows(); i++) {
862  layerBiases(i,0) = weights[weightIndex];
863  weightIndex++;
864  }
865  } else {
866  for (Int_t i = 0; i < layerBiases.GetNrows(); i++) {
867  layerBiases(i,0) = 0.0;
868  }
869  }
870  }
873 }
874 
875 ////////////////////////////////////////////////////////////////////////////////
876 
878 {
879 
880 #ifdef DNNCUDA // Included only if DNNCUDA flag is set.
881  Log() << kINFO << "Start of neural network training on GPU." << Endl << Endl;
882 
883  size_t nValidationSamples = GetNumValidationSamples();
884  size_t nTrainingSamples = GetEventCollection(Types::kTraining).size() - nValidationSamples;
885  size_t nTestSamples = nValidationSamples;
886 
887  Log() << kDEBUG << "Using " << nValidationSamples << " validation samples." << Endl;
888  Log() << kDEBUG << "Using " << nTestSamples << " training samples." << Endl;
889 
890  size_t trainingPhase = 1;
891  fNet.Initialize(fWeightInitialization);
892  for (TTrainingSettings & settings : fTrainingSettings) {
893 
894  if (fInteractive){
896  }
897 
898  TNet<TCuda<>> net(settings.batchSize, fNet);
899  net.SetWeightDecay(settings.weightDecay);
900  net.SetRegularization(settings.regularization);
901 
902  // Need to convert dropoutprobabilities to conventions used
903  // by backend implementation.
904  std::vector<Double_t> dropoutVector(settings.dropoutProbabilities);
905  for (auto & p : dropoutVector) {
906  p = 1.0 - p;
907  }
908  net.SetDropoutProbabilities(dropoutVector);
909 
910  net.InitializeGradients();
911  auto testNet = net.CreateClone(settings.batchSize);
912 
913  Log() << kINFO << "Training phase " << trainingPhase << " of "
914  << fTrainingSettings.size() << ":" << Endl;
915  trainingPhase++;
916 
917  using DataLoader_t = TDataLoader<TMVAInput_t, TCuda<>>;
918 
919  // Split training data into training and validation set
920  const std::vector<Event *> &allData = GetEventCollection(Types::kTraining);
921  const std::vector<Event *> trainingInputData =
922  std::vector<Event *>(allData.begin(), allData.begin() + nTrainingSamples);
923  const std::vector<Event *> testInputData =
924  std::vector<Event *>(allData.begin() + nTrainingSamples, allData.end());
925 
926  if (trainingInputData.size() != nTrainingSamples) {
927  Log() << kFATAL << "Inconsistent training sample size" << Endl;
928  }
929  if (testInputData.size() != nTestSamples) {
930  Log() << kFATAL << "Inconsistent test sample size" << Endl;
931  }
932 
933  size_t nThreads = 1;
934  TMVAInput_t trainingTuple = std::tie(trainingInputData, DataInfo());
935  TMVAInput_t testTuple = std::tie(testInputData, DataInfo());
936  DataLoader_t trainingData(trainingTuple, nTrainingSamples,
937  net.GetBatchSize(), net.GetInputWidth(),
938  net.GetOutputWidth(), nThreads);
939  DataLoader_t testData(testTuple, nTestSamples, testNet.GetBatchSize(),
940  net.GetInputWidth(), net.GetOutputWidth(),
941  nThreads);
942  DNN::TGradientDescent<TCuda<>> minimizer(settings.learningRate,
943  settings.convergenceSteps,
944  settings.testInterval);
945 
946  std::vector<TNet<TCuda<>>> nets{};
947  std::vector<TBatch<TCuda<>>> batches{};
948  nets.reserve(nThreads);
949  for (size_t i = 0; i < nThreads; i++) {
950  nets.push_back(net);
951  for (size_t j = 0; j < net.GetDepth(); j++)
952  {
953  auto &masterLayer = net.GetLayer(j);
954  auto &layer = nets.back().GetLayer(j);
955  TCuda<>::Copy(layer.GetWeights(),
956  masterLayer.GetWeights());
957  TCuda<>::Copy(layer.GetBiases(),
958  masterLayer.GetBiases());
959  }
960  }
961 
962  bool converged = false;
963  size_t stepCount = 0;
964  size_t batchesInEpoch = nTrainingSamples / net.GetBatchSize();
965 
966  std::chrono::time_point<std::chrono::system_clock> start, end;
967  start = std::chrono::system_clock::now();
968 
969  if (!fInteractive) {
970  Log() << std::setw(10) << "Epoch" << " | "
971  << std::setw(12) << "Train Err."
972  << std::setw(12) << "Test Err."
973  << std::setw(12) << "GFLOP/s"
974  << std::setw(12) << "Conv. Steps" << Endl;
975  std::string separator(62, '-');
976  Log() << separator << Endl;
977  }
978 
979  while (!converged)
980  {
981  stepCount++;
982 
983  // Perform minimization steps for a full epoch.
984  trainingData.Shuffle();
985  for (size_t i = 0; i < batchesInEpoch; i += nThreads) {
986  batches.clear();
987  for (size_t j = 0; j < nThreads; j++) {
988  batches.reserve(nThreads);
989  batches.push_back(trainingData.GetBatch());
990  }
991  if (settings.momentum > 0.0) {
992  minimizer.StepMomentum(net, nets, batches, settings.momentum);
993  } else {
994  minimizer.Step(net, nets, batches);
995  }
996  }
997 
998  if ((stepCount % minimizer.GetTestInterval()) == 0) {
999 
1000  // Compute test error.
1001  Double_t testError = 0.0;
1002  for (auto batch : testData) {
1003  auto inputMatrix = batch.GetInput();
1004  auto outputMatrix = batch.GetOutput();
1005  testError += testNet.Loss(inputMatrix, outputMatrix);
1006  }
1007  testError /= (Double_t) (nTestSamples / settings.batchSize);
1008 
1009  end = std::chrono::system_clock::now();
1010 
1011  // Compute training error.
1012  Double_t trainingError = 0.0;
1013  for (auto batch : trainingData) {
1014  auto inputMatrix = batch.GetInput();
1015  auto outputMatrix = batch.GetOutput();
1016  trainingError += net.Loss(inputMatrix, outputMatrix);
1017  }
1018  trainingError /= (Double_t) (nTrainingSamples / settings.batchSize);
1019 
1020  // Compute numerical throughput.
1021  std::chrono::duration<double> elapsed_seconds = end - start;
1022  double seconds = elapsed_seconds.count();
1023  double nFlops = (double) (settings.testInterval * batchesInEpoch);
1024  nFlops *= net.GetNFlops() * 1e-9;
1025 
1026  converged = minimizer.HasConverged(testError);
1027  start = std::chrono::system_clock::now();
1028 
1029  if (fInteractive) {
1030  fInteractive->AddPoint(stepCount, trainingError, testError);
1031  fIPyCurrentIter = 100.0 * minimizer.GetConvergenceCount()
1032  / minimizer.GetConvergenceSteps ();
1033  if (fExitFromTraining) break;
1034  } else {
1035  Log() << std::setw(10) << stepCount << " | "
1036  << std::setw(12) << trainingError
1037  << std::setw(12) << testError
1038  << std::setw(12) << nFlops / seconds
1039  << std::setw(12) << minimizer.GetConvergenceCount() << Endl;
1040  if (converged) {
1041  Log() << Endl;
1042  }
1043  }
1044  }
1045  }
1046  for (size_t l = 0; l < net.GetDepth(); l++) {
1047  fNet.GetLayer(l).GetWeights() = (TMatrixT<Double_t>) net.GetLayer(l).GetWeights();
1048  fNet.GetLayer(l).GetBiases() = (TMatrixT<Double_t>) net.GetLayer(l).GetBiases();
1049  }
1050  }
1051 
1052 #else // DNNCUDA flag not set.
1053 
1054  Log() << kFATAL << "CUDA backend not enabled. Please make sure "
1055  "you have CUDA installed and it was successfully "
1056  "detected by CMAKE." << Endl;
1057 #endif // DNNCUDA
1058 }
1059 
1060 ////////////////////////////////////////////////////////////////////////////////
1061 
1063 {
1064 
1065 #ifdef DNNCPU // Included only if DNNCPU flag is set.
1066  Log() << kINFO << "Start of neural network training on CPU." << Endl << Endl;
1067 
1068  size_t nValidationSamples = GetNumValidationSamples();
1069  size_t nTrainingSamples = GetEventCollection(Types::kTraining).size() - nValidationSamples;
1070  size_t nTestSamples = nValidationSamples;
1071 
1072  Log() << kDEBUG << "Using " << nValidationSamples << " validation samples." << Endl;
1073  Log() << kDEBUG << "Using " << nTestSamples << " training samples." << Endl;
1074 
1075  fNet.Initialize(fWeightInitialization);
1076 
1077  size_t trainingPhase = 1;
1078  for (TTrainingSettings & settings : fTrainingSettings) {
1079 
1080  if (fInteractive){
1082  }
1083 
1084  Log() << "Training phase " << trainingPhase << " of "
1085  << fTrainingSettings.size() << ":" << Endl;
1086  trainingPhase++;
1087 
1088  TNet<TCpu<>> net(settings.batchSize, fNet);
1089  net.SetWeightDecay(settings.weightDecay);
1090  net.SetRegularization(settings.regularization);
1091  // Need to convert dropoutprobabilities to conventions used
1092  // by backend implementation.
1093  std::vector<Double_t> dropoutVector(settings.dropoutProbabilities);
1094  for (auto & p : dropoutVector) {
1095  p = 1.0 - p;
1096  }
1097  net.SetDropoutProbabilities(dropoutVector);
1098  //net.SetDropoutProbabilities(settings.dropoutProbabilities);
1099  net.InitializeGradients();
1100  auto testNet = net.CreateClone(settings.batchSize);
1101 
1102  using DataLoader_t = TDataLoader<TMVAInput_t, TCpu<>>;
1103 
1104  // Split training data into training and validation set
1105  const std::vector<Event *> &allData = GetEventCollection(Types::kTraining);
1106  const std::vector<Event *> trainingInputData =
1107  std::vector<Event *>(allData.begin(), allData.begin() + nTrainingSamples);
1108  const std::vector<Event *> testInputData =
1109  std::vector<Event *>(allData.begin() + nTrainingSamples, allData.end());
1110 
1111  if (trainingInputData.size() != nTrainingSamples) {
1112  Log() << kFATAL << "Inconsistent training sample size" << Endl;
1113  }
1114  if (testInputData.size() != nTestSamples) {
1115  Log() << kFATAL << "Inconsistent test sample size" << Endl;
1116  }
1117 
1118  size_t nThreads = 1;
1119  TMVAInput_t trainingTuple = std::tie(trainingInputData, DataInfo());
1120  TMVAInput_t testTuple = std::tie(testInputData, DataInfo());
1121  DataLoader_t trainingData(trainingTuple, nTrainingSamples,
1122  net.GetBatchSize(), net.GetInputWidth(),
1123  net.GetOutputWidth(), nThreads);
1124  DataLoader_t testData(testTuple, nTestSamples, testNet.GetBatchSize(),
1125  net.GetInputWidth(), net.GetOutputWidth(),
1126  nThreads);
1127  DNN::TGradientDescent<TCpu<>> minimizer(settings.learningRate,
1128  settings.convergenceSteps,
1129  settings.testInterval);
1130 
1131  std::vector<TNet<TCpu<>>> nets{};
1132  std::vector<TBatch<TCpu<>>> batches{};
1133  nets.reserve(nThreads);
1134  for (size_t i = 0; i < nThreads; i++) {
1135  nets.push_back(net);
1136  for (size_t j = 0; j < net.GetDepth(); j++)
1137  {
1138  auto &masterLayer = net.GetLayer(j);
1139  auto &layer = nets.back().GetLayer(j);
1140  TCpu<>::Copy(layer.GetWeights(),
1141  masterLayer.GetWeights());
1142  TCpu<>::Copy(layer.GetBiases(),
1143  masterLayer.GetBiases());
1144  }
1145  }
1146 
1147  bool converged = false;
1148  size_t stepCount = 0;
1149  size_t batchesInEpoch = nTrainingSamples / net.GetBatchSize();
1150 
1151  std::chrono::time_point<std::chrono::system_clock> start, end;
1152  start = std::chrono::system_clock::now();
1153 
1154  if (!fInteractive) {
1155  Log() << std::setw(10) << "Epoch" << " | "
1156  << std::setw(12) << "Train Err."
1157  << std::setw(12) << "Test Err."
1158  << std::setw(12) << "GFLOP/s"
1159  << std::setw(12) << "Conv. Steps" << Endl;
1160  std::string separator(62, '-');
1161  Log() << separator << Endl;
1162  }
1163 
1164  while (!converged)
1165  {
1166  stepCount++;
1167  // Perform minimization steps for a full epoch.
1168  trainingData.Shuffle();
1169  for (size_t i = 0; i < batchesInEpoch; i += nThreads) {
1170  batches.clear();
1171  for (size_t j = 0; j < nThreads; j++) {
1172  batches.reserve(nThreads);
1173  batches.push_back(trainingData.GetBatch());
1174  }
1175  if (settings.momentum > 0.0) {
1176  minimizer.StepMomentum(net, nets, batches, settings.momentum);
1177  } else {
1178  minimizer.Step(net, nets, batches);
1179  }
1180  }
1181 
1182  if ((stepCount % minimizer.GetTestInterval()) == 0) {
1183 
1184  // Compute test error.
1185  Double_t testError = 0.0;
1186  for (auto batch : testData) {
1187  auto inputMatrix = batch.GetInput();
1188  auto outputMatrix = batch.GetOutput();
1189  auto weightMatrix = batch.GetWeights();
1190  testError += testNet.Loss(inputMatrix, outputMatrix, weightMatrix);
1191  }
1192  testError /= (Double_t) (nTestSamples / settings.batchSize);
1193 
1194  end = std::chrono::system_clock::now();
1195 
1196  // Compute training error.
1197  Double_t trainingError = 0.0;
1198  for (auto batch : trainingData) {
1199  auto inputMatrix = batch.GetInput();
1200  auto outputMatrix = batch.GetOutput();
1201  auto weightMatrix = batch.GetWeights();
1202  trainingError += net.Loss(inputMatrix, outputMatrix, weightMatrix);
1203  }
1204  trainingError /= (Double_t) (nTrainingSamples / settings.batchSize);
1205 
1206  if (fInteractive){
1207  fInteractive->AddPoint(stepCount, trainingError, testError);
1208  fIPyCurrentIter = 100*(double)minimizer.GetConvergenceCount() /(double)settings.convergenceSteps;
1209  if (fExitFromTraining) break;
1210  }
1211 
1212  // Compute numerical throughput.
1213  std::chrono::duration<double> elapsed_seconds = end - start;
1214  double seconds = elapsed_seconds.count();
1215  double nFlops = (double) (settings.testInterval * batchesInEpoch);
1216  nFlops *= net.GetNFlops() * 1e-9;
1217 
1218  converged = minimizer.HasConverged(testError);
1219  start = std::chrono::system_clock::now();
1220 
1221  if (fInteractive) {
1222  fInteractive->AddPoint(stepCount, trainingError, testError);
1223  fIPyCurrentIter = 100.0 * minimizer.GetConvergenceCount()
1224  / minimizer.GetConvergenceSteps ();
1225  if (fExitFromTraining) break;
1226  } else {
1227  Log() << std::setw(10) << stepCount << " | "
1228  << std::setw(12) << trainingError
1229  << std::setw(12) << testError
1230  << std::setw(12) << nFlops / seconds
1231  << std::setw(12) << minimizer.GetConvergenceCount() << Endl;
1232  if (converged) {
1233  Log() << Endl;
1234  }
1235  }
1236  }
1237  }
1238 
1239 
1240  for (size_t l = 0; l < net.GetDepth(); l++) {
1241  auto & layer = fNet.GetLayer(l);
1242  layer.GetWeights() = (TMatrixT<Double_t>) net.GetLayer(l).GetWeights();
1243  layer.GetBiases() = (TMatrixT<Double_t>) net.GetLayer(l).GetBiases();
1244  }
1245  }
1246 
1247 #else // DNNCPU flag not set.
1248  Log() << kFATAL << "Multi-core CPU backend not enabled. Please make sure "
1249  "you have a BLAS implementation and it was successfully "
1250  "detected by CMake as well that the imt CMake flag is set." << Endl;
1251 #endif // DNNCPU
1252 }
1253 
1254 ////////////////////////////////////////////////////////////////////////////////
1255 
1257 {
1258  size_t nVariables = GetEvent()->GetNVariables();
1259  Matrix_t X(1, nVariables);
1260  Matrix_t YHat(1, 1);
1261 
1262  const std::vector<Float_t>& inputValues = GetEvent()->GetValues();
1263  for (size_t i = 0; i < nVariables; i++) {
1264  X(0,i) = inputValues[i];
1265  }
1266 
1267  fNet.Prediction(YHat, X, fOutputFunction);
1268  return YHat(0,0);
1269 }
1270 
1271 ////////////////////////////////////////////////////////////////////////////////
1272 
1273 const std::vector<Float_t> & TMVA::MethodDNN::GetRegressionValues()
1274 {
1275  size_t nVariables = GetEvent()->GetNVariables();
1276  Matrix_t X(1, nVariables);
1277 
1278  const Event *ev = GetEvent();
1279  const std::vector<Float_t>& inputValues = ev->GetValues();
1280  for (size_t i = 0; i < nVariables; i++) {
1281  X(0,i) = inputValues[i];
1282  }
1283 
1284  size_t nTargets = std::max(1u, ev->GetNTargets());
1285  Matrix_t YHat(1, nTargets);
1286  std::vector<Float_t> output(nTargets);
1287  auto net = fNet.CreateClone(1);
1288  net.Prediction(YHat, X, fOutputFunction);
1289 
1290  for (size_t i = 0; i < nTargets; i++)
1291  output[i] = YHat(0, i);
1292 
1293  if (fRegressionReturnVal == NULL) {
1294  fRegressionReturnVal = new std::vector<Float_t>();
1295  }
1296  fRegressionReturnVal->clear();
1297 
1298  Event * evT = new Event(*ev);
1299  for (size_t i = 0; i < nTargets; ++i) {
1300  evT->SetTarget(i, output[i]);
1301  }
1302 
1303  const Event* evT2 = GetTransformationHandler().InverseTransform(evT);
1304  for (size_t i = 0; i < nTargets; ++i) {
1305  fRegressionReturnVal->push_back(evT2->GetTarget(i));
1306  }
1307  delete evT;
1308  return *fRegressionReturnVal;
1309 }
1310 
1311 const std::vector<Float_t> & TMVA::MethodDNN::GetMulticlassValues()
1312 {
1313  size_t nVariables = GetEvent()->GetNVariables();
1314  Matrix_t X(1, nVariables);
1315  Matrix_t YHat(1, DataInfo().GetNClasses());
1316  if (fMulticlassReturnVal == NULL) {
1317  fMulticlassReturnVal = new std::vector<Float_t>(DataInfo().GetNClasses());
1318  }
1319 
1320  const std::vector<Float_t>& inputValues = GetEvent()->GetValues();
1321  for (size_t i = 0; i < nVariables; i++) {
1322  X(0,i) = inputValues[i];
1323  }
1324 
1325  fNet.Prediction(YHat, X, fOutputFunction);
1326  for (size_t i = 0; i < (size_t) YHat.GetNcols(); i++) {
1327  (*fMulticlassReturnVal)[i] = YHat(0, i);
1328  }
1329  return *fMulticlassReturnVal;
1330 }
1331 
1332 ////////////////////////////////////////////////////////////////////////////////
1333 
1334 void TMVA::MethodDNN::AddWeightsXMLTo( void* parent ) const
1335 {
1336  void* nn = gTools().xmlengine().NewChild(parent, 0, "Weights");
1337  Int_t inputWidth = fNet.GetInputWidth();
1338  Int_t depth = fNet.GetDepth();
1339  char lossFunction = static_cast<char>(fNet.GetLossFunction());
1340  gTools().xmlengine().NewAttr(nn, 0, "InputWidth",
1341  gTools().StringFromInt(inputWidth));
1342  gTools().xmlengine().NewAttr(nn, 0, "Depth", gTools().StringFromInt(depth));
1343  gTools().xmlengine().NewAttr(nn, 0, "LossFunction", TString(lossFunction));
1344  gTools().xmlengine().NewAttr(nn, 0, "OutputFunction",
1345  TString(static_cast<char>(fOutputFunction)));
1346 
1347  for (Int_t i = 0; i < depth; i++) {
1348  const auto& layer = fNet.GetLayer(i);
1349  auto layerxml = gTools().xmlengine().NewChild(nn, 0, "Layer");
1350  int activationFunction = static_cast<int>(layer.GetActivationFunction());
1351  gTools().xmlengine().NewAttr(layerxml, 0, "ActivationFunction",
1352  TString::Itoa(activationFunction, 10));
1353  WriteMatrixXML(layerxml, "Weights", layer.GetWeights());
1354  WriteMatrixXML(layerxml, "Biases", layer.GetBiases());
1355  }
1356 }
1357 
1358 ////////////////////////////////////////////////////////////////////////////////
1359 
1361 {
1362  auto netXML = gTools().GetChild(rootXML, "Weights");
1363  if (!netXML){
1364  netXML = rootXML;
1365  }
1366 
1367  fNet.Clear();
1368  fNet.SetBatchSize(1);
1369 
1370  size_t inputWidth, depth;
1371  gTools().ReadAttr(netXML, "InputWidth", inputWidth);
1372  gTools().ReadAttr(netXML, "Depth", depth);
1373  char lossFunctionChar;
1374  gTools().ReadAttr(netXML, "LossFunction", lossFunctionChar);
1375  char outputFunctionChar;
1376  gTools().ReadAttr(netXML, "OutputFunction", outputFunctionChar);
1377 
1378  fNet.SetInputWidth(inputWidth);
1379  fNet.SetLossFunction(static_cast<ELossFunction>(lossFunctionChar));
1380  fOutputFunction = static_cast<EOutputFunction>(outputFunctionChar);
1381 
1382  size_t previousWidth = inputWidth;
1383  auto layerXML = gTools().xmlengine().GetChild(netXML, "Layer");
1384  for (size_t i = 0; i < depth; i++) {
1385  TString fString;
1387 
1388  // Read activation function.
1389  gTools().ReadAttr(layerXML, "ActivationFunction", fString);
1390  f = static_cast<EActivationFunction>(fString.Atoi());
1391 
1392  // Read number of neurons.
1393  size_t width;
1394  auto matrixXML = gTools().GetChild(layerXML, "Weights");
1395  gTools().ReadAttr(matrixXML, "rows", width);
1396 
1397  fNet.AddLayer(width, f);
1398  TMatrixT<Double_t> weights(width, previousWidth);
1399  TMatrixT<Double_t> biases(width, 1);
1400  ReadMatrixXML(layerXML, "Weights", weights);
1401  ReadMatrixXML(layerXML, "Biases", biases);
1402  fNet.GetLayer(i).GetWeights() = weights;
1403  fNet.GetLayer(i).GetBiases() = biases;
1404 
1405  layerXML = gTools().GetNextChild(layerXML);
1406  previousWidth = width;
1407  }
1408 }
1409 
1410 ////////////////////////////////////////////////////////////////////////////////
1411 
1412 void TMVA::MethodDNN::ReadWeightsFromStream( std::istream & /*istr*/)
1413 {
1414 }
1415 
1416 ////////////////////////////////////////////////////////////////////////////////
1417 
1419 {
1420  fRanking = new Ranking( GetName(), "Importance" );
1421  for (UInt_t ivar=0; ivar<GetNvar(); ivar++) {
1422  fRanking->AddRank( Rank( GetInputLabel(ivar), 1.0));
1423  }
1424  return fRanking;
1425 }
1426 
1427 ////////////////////////////////////////////////////////////////////////////////
1428 
1429 void TMVA::MethodDNN::MakeClassSpecific( std::ostream& /*fout*/,
1430  const TString& /*className*/ ) const
1431 {
1432 }
1433 
1434 ////////////////////////////////////////////////////////////////////////////////
1435 
1437 {
1438  // get help message text
1439  //
1440  // typical length of text line:
1441  // "|--------------------------------------------------------------|"
1442  TString col = gConfig().WriteOptionsReference() ? TString() : gTools().Color("bold");
1443  TString colres = gConfig().WriteOptionsReference() ? TString() : gTools().Color("reset");
1444 
1445  Log() << Endl;
1446  Log() << col << "--- Short description:" << colres << Endl;
1447  Log() << Endl;
1448  Log() << "The DNN neural network is a feedforward" << Endl;
1449  Log() << "multilayer perceptron implementation. The DNN has a user-" << Endl;
1450  Log() << "defined hidden layer architecture, where the number of input (output)" << Endl;
1451  Log() << "nodes is determined by the input variables (output classes, i.e., " << Endl;
1452  Log() << "signal and one background, regression or multiclass). " << Endl;
1453  Log() << Endl;
1454  Log() << col << "--- Performance optimisation:" << colres << Endl;
1455  Log() << Endl;
1456 
1457  const char* txt = "The DNN supports various options to improve performance in terms of training speed and \n \
1458 reduction of overfitting: \n \
1459 \n \
1460  - different training settings can be stacked. Such that the initial training \n\
1461  is done with a large learning rate and a large drop out fraction whilst \n \
1462  in a later stage learning rate and drop out can be reduced. \n \
1463  - drop out \n \
1464  [recommended: \n \
1465  initial training stage: 0.0 for the first layer, 0.5 for later layers. \n \
1466  later training stage: 0.1 or 0.0 for all layers \n \
1467  final training stage: 0.0] \n \
1468  Drop out is a technique where a at each training cycle a fraction of arbitrary \n \
1469  nodes is disabled. This reduces co-adaptation of weights and thus reduces overfitting. \n \
1470  - L1 and L2 regularization are available \n \
1471  - Minibatches \n \
1472  [recommended 10 - 150] \n \
1473  Arbitrary mini-batch sizes can be chosen. \n \
1474  - Multithreading \n \
1475  [recommended: True] \n \
1476  Multithreading can be turned on. The minibatches are distributed to the available \n \
1477  cores. The algorithm is lock-free (\"Hogwild!\"-style) for each cycle. \n \
1478  \n \
1479  Options: \n \
1480  \"Layout\": \n \
1481  - example: \"TANH|(N+30)*2,TANH|(N+30),LINEAR\" \n \
1482  - meaning: \n \
1483  . two hidden layers (separated by \",\") \n \
1484  . the activation function is TANH (other options: RELU, SOFTSIGN, LINEAR) \n \
1485  . the activation function for the output layer is LINEAR \n \
1486  . the first hidden layer has (N+30)*2 nodes where N is the number of input neurons \n \
1487  . the second hidden layer has N+30 nodes, where N is the number of input neurons \n \
1488  . the number of nodes in the output layer is determined by the number of output nodes \n \
1489  and can therefore not be chosen freely. \n \
1490  \n \
1491  \"ErrorStrategy\": \n \
1492  - SUMOFSQUARES \n \
1493  The error of the neural net is determined by a sum-of-squares error function \n \
1494  For regression, this is the only possible choice. \n \
1495  - CROSSENTROPY \n \
1496  The error of the neural net is determined by a cross entropy function. The \n \
1497  output values are automatically (internally) transformed into probabilities \n \
1498  using a sigmoid function. \n \
1499  For signal/background classification this is the default choice. \n \
1500  For multiclass using cross entropy more than one or no output classes \n \
1501  can be equally true or false (e.g. Event 0: A and B are true, Event 1: \n \
1502  A and C is true, Event 2: C is true, ...) \n \
1503  - MUTUALEXCLUSIVE \n \
1504  In multiclass settings, exactly one of the output classes can be true (e.g. either A or B or C) \n \
1505  \n \
1506  \"WeightInitialization\" \n \
1507  - XAVIER \n \
1508  [recommended] \n \
1509  \"Xavier Glorot & Yoshua Bengio\"-style of initializing the weights. The weights are chosen randomly \n \
1510  such that the variance of the values of the nodes is preserved for each layer. \n \
1511  - XAVIERUNIFORM \n \
1512  The same as XAVIER, but with uniformly distributed weights instead of gaussian weights \n \
1513  - LAYERSIZE \n \
1514  Random values scaled by the layer size \n \
1515  \n \
1516  \"TrainingStrategy\" \n \
1517  - example: \"LearningRate=1e-1,Momentum=0.3,ConvergenceSteps=50,BatchSize=30,TestRepetitions=7,WeightDecay=0.0,Renormalize=L2,DropConfig=0.0,DropRepetitions=5|LearningRate=1e-4,Momentum=0.3,ConvergenceSteps=50,BatchSize=20,TestRepetitions=7,WeightDecay=0.001,Renormalize=L2,DropFraction=0.0,DropRepetitions=5\" \n \
1518  - explanation: two stacked training settings separated by \"|\" \n \
1519  . first training setting: \"LearningRate=1e-1,Momentum=0.3,ConvergenceSteps=50,BatchSize=30,TestRepetitions=7,WeightDecay=0.0,Renormalize=L2,DropConfig=0.0,DropRepetitions=5\" \n \
1520  . second training setting : \"LearningRate=1e-4,Momentum=0.3,ConvergenceSteps=50,BatchSize=20,TestRepetitions=7,WeightDecay=0.001,Renormalize=L2,DropFractions=0.0,DropRepetitions=5\" \n \
1521  . LearningRate : \n \
1522  - recommended for classification: 0.1 initially, 1e-4 later \n \
1523  - recommended for regression: 1e-4 and less \n \
1524  . Momentum : \n \
1525  preserve a fraction of the momentum for the next training batch [fraction = 0.0 - 1.0] \n \
1526  . Repetitions : \n \
1527  train \"Repetitions\" repetitions with the same minibatch before switching to the next one \n \
1528  . ConvergenceSteps : \n \
1529  Assume that convergence is reached after \"ConvergenceSteps\" cycles where no improvement \n \
1530  of the error on the test samples has been found. (Mind that only at each \"TestRepetitions\" \n \
1531  cycle the test samples are evaluated and thus the convergence is checked) \n \
1532  . BatchSize \n \
1533  Size of the mini-batches. \n \
1534  . TestRepetitions \n \
1535  Perform testing the neural net on the test samples each \"TestRepetitions\" cycle \n \
1536  . WeightDecay \n \
1537  If \"Renormalize\" is set to L1 or L2, \"WeightDecay\" provides the renormalization factor \n \
1538  . Renormalize \n \
1539  NONE, L1 (|w|) or L2 (w^2) \n \
1540  . DropConfig \n \
1541  Drop a fraction of arbitrary nodes of each of the layers according to the values given \n \
1542  in the DropConfig. \n \
1543  [example: DropConfig=0.0+0.5+0.3 \n \
1544  meaning: drop no nodes in layer 0 (input layer), half of the nodes in layer 1 and 30% of the nodes \n \
1545  in layer 2 \n \
1546  recommended: leave all the nodes turned on for the input layer (layer 0) \n \
1547  turn off half of the nodes in later layers for the initial training; leave all nodes \n \
1548  turned on (0.0) in later training stages] \n \
1549  . DropRepetitions \n \
1550  Each \"DropRepetitions\" cycle the configuration of which nodes are dropped is changed \n \
1551  [recommended : 1] \n \
1552  . Multithreading \n \
1553  turn on multithreading [recommended: True] \n \
1554  \n";
1555  Log () << txt << Endl;
1556 }
1557 
1558 } // namespace TMVA
Types::EAnalysisType fAnalysisType
Definition: MethodBase.h:584
void GetHelpMessage() const
Definition: MethodDNN.cxx:1436
Scalar_t Loss(const Matrix_t &Y, const Matrix_t &weights, bool includeRegularization=true) const
Evaluate the loss function of the net using the activations that are currently stored in the output l...
Definition: Net.h:305
An array of TObjects.
Definition: TObjArray.h:37
TXMLEngine & xmlengine()
Definition: Tools.h:270
LayoutVector_t ParseLayoutString(TString layerSpec)
static TString Itoa(Int_t value, Int_t base)
Converts an Int_t to a TString with respect to the base specified (2-36).
Definition: TString.cxx:2000
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
void AddPoint(Double_t x, Double_t y1, Double_t y2)
This function is used only in 2 TGraph case, and it will add new data points to graphs.
Definition: MethodBase.cxx:212
void ProcessOptions()
Definition: MethodDNN.cxx:412
TString fLayoutString
The string defining the layout of the deep net.
Definition: MethodDL.h:156
Collectable string class.
Definition: TObjString.h:28
Steepest Gradient Descent algorithm (SGD)
Definition: NeuralNet.h:334
double T(double x)
Definition: ChebyshevPol.h:34
#define g(i)
Definition: RSha256.hxx:105
std::vector< std::map< TString, TString > > KeyValueVector_t
Definition: MethodDNN.h:82
void SetDropoutProbabilities(const std::vector< Double_t > &probabilities)
Definition: Net.h:378
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
UInt_t GetNvar() const
Definition: MethodBase.h:335
Config & gConfig()
MsgLogger & Log() const
Definition: Configurable.h:122
void MakeClassSpecific(std::ostream &, const TString &) const
Definition: MethodDNN.cxx:1429
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
Definition: TString.cxx:1766
EAnalysisType
Definition: Types.h:127
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1113
DNN::EOutputFunction fOutputFunction
The output function for making the predictions.
Definition: MethodDL.h:151
DNN::EInitialization fWeightInitialization
The initialization method.
Definition: MethodDL.h:150
bool fExitFromTraining
Definition: MethodBase.h:438
void setErrorFunction(ModeErrorFunction eErrorFunction)
which error function is to be used
Definition: NeuralNet.h:1103
Basic string class.
Definition: TString.h:131
typename Architecture_t::Matrix_t Matrix_t
Definition: MethodDNN.h:78
TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
Definition: MethodBase.h:385
Ranking for variables in method (implementation)
Definition: Ranking.h:48
#define f(i)
Definition: RSha256.hxx:104
Scalar_t GetNFlops()
Definition: Net.h:347
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Definition: Pattern.h:7
UInt_t GetNClasses() const
Definition: DataSetInfo.h:136
UInt_t GetNTargets() const
Definition: MethodBase.h:337
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
void setOutputSize(size_t sizeOutput)
set the output size of the DNN
Definition: NeuralNet.h:1100
void SetWeightDecay(Scalar_t weightDecay)
Definition: Net.h:152
neural net
Definition: NeuralNet.h:1068
TString fArchitectureString
The string defining the architecure: CPU or GPU.
Definition: MethodDL.h:160
const TString & GetInputLabel(Int_t i) const
Definition: MethodBase.h:341
void ReadWeightsFromStream(std::istream &i)
Definition: MethodDNN.cxx:1412
void SetIpythonInteractive(IPythonInteractive *fI, bool *fE, UInt_t *M, UInt_t *C)
Definition: NeuralNet.h:1290
std::vector< Double_t > dropoutProbabilities
Definition: MethodDNN.h:93
const Event * GetEvent() const
Definition: MethodBase.h:740
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="")
standard constructor
Definition: MethodBase.cxx:242
void ClearGraphs()
This function sets the point number to 0 for all graphs.
Definition: MethodBase.cxx:198
void ReadWeightsFromXML(void *wghtnode)
Definition: MethodDNN.cxx:1360
void * GetChild(void *parent, const char *childname=0)
get child node
Definition: Tools.cxx:1162
void setInputSize(size_t sizeInput)
set the input size of the DNN
Definition: NeuralNet.h:1099
TString fTrainingStrategyString
The string defining the training strategy.
Definition: MethodDL.h:158
Generic neural network class.
Definition: Net.h:49
std::vector< std::map< TString, TString > > KeyValueVector_t
Definition: MethodDL.h:79
void Init(std::vector< TString > &graphTitles)
This function gets some title and it creates a TGraph for every title.
Definition: MethodBase.cxx:174
DataSetInfo & DataInfo() const
Definition: MethodBase.h:401
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:487
UInt_t fIPyCurrentIter
Definition: MethodBase.h:439
UInt_t GetNTargets() const
accessor to the number of targets
Definition: Event.cxx:320
KeyValueVector_t ParseKeyValueString(TString parseString, TString blockDelim, TString tokenDelim)
void initializeWeights(WeightInitializationStrategy eInitStrategy, OutIterator itWeight)
initialize the weights with the given strategy
Definition: NeuralNet.icc:1481
const TString & GetString() const
Definition: TObjString.h:47
Float_t GetTarget(UInt_t itgt) const
Definition: Event.h:97
ROOT::R::TRInterface & r
Definition: Object.C:4
const char * GetName() const
Definition: MethodBase.h:325
KeyValueVector_t ParseKeyValueString(TString parseString, TString blockDelim, TString tokenDelim)
Function for parsing the training settings, provided as a string in a key-value form.
Definition: MethodDL.cxx:912
TDataLoader.
Definition: DataLoader.h:79
The Formula class.
Definition: TFormula.h:83
std::vector< TTrainingSettings > fTrainingSettings
The vector defining each training strategy.
Definition: MethodDL.h:165
const Ranking * CreateRanking()
Definition: MethodDNN.cxx:1418
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:610
UInt_t fIPyMaxIter
Definition: MethodBase.h:439
void SetRegularization(ERegularization R)
Definition: Net.h:150
unsigned int UInt_t
Definition: RtypesCore.h:42
const Handle_t kNone
Definition: GuiTypes.h:87
const Event * InverseTransform(const Event *, Bool_t suppressIfNoTargets=true) const
size_t GetDepth() const
Definition: Net.h:137
auto regularization(const typename Architecture_t::Matrix_t &A, ERegularization R) -> decltype(Architecture_t::L1Regularization(A))
Evaluate the regularization functional for a given weight matrix.
Definition: Functions.h:207
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1081
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
Definition: Event.cxx:360
void ReadAttr(void *node, const char *, T &value)
read attribute from xml
Definition: Tools.h:335
Tools & gTools()
Settings for the training of the neural net.
Definition: NeuralNet.h:736
TNet< Architecture_t, TSharedLayer< Architecture_t > > CreateClone(size_t batchSize)
Create a clone that uses the same weight and biases matrices but potentially a difference batch size...
Definition: Net.h:212
#define h(i)
Definition: RSha256.hxx:106
UInt_t GetNVariables() const
Definition: MethodBase.h:336
UInt_t GetNVariables() const
accessor to the number of variables
Definition: Event.cxx:309
const Bool_t kFALSE
Definition: RtypesCore.h:88
KeyValueVector_t fSettings
Map for the training strategy.
Definition: MethodDL.h:164
TString fErrorStrategy
The string defining the error strategy for training.
Definition: MethodDL.h:157
Layer defines the layout of a layer.
Definition: NeuralNet.h:676
Bool_t IgnoreEventsWithNegWeightsInTraining() const
Definition: MethodBase.h:675
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
Definition: TXMLEngine.cxx:578
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2172
const std::vector< TMVA::Event * > & GetEventCollection(Types::ETreeType type)
returns the event collection (i.e.
size_t GetOutputWidth() const
Definition: Net.h:144
#define NONE
Definition: Rotated.cxx:52
void Copy(void *source, void *dest)
size_t GetInputWidth() const
Definition: Net.h:143
#define ClassImp(name)
Definition: Rtypes.h:359
UInt_t GetNumValidationSamples()
ModeOutputValues
Definition: NeuralNet.h:179
double Double_t
Definition: RtypesCore.h:55
Bool_t WriteOptionsReference() const
Definition: Config.h:71
Deep Neural Network Implementation.
Definition: MethodDNN.h:72
TString fetchValue(const std::map< TString, TString > &keyValueMap, TString key)
Definition: MethodDNN.cxx:308
std::vector< Float_t > * fMulticlassReturnVal
Definition: MethodBase.h:587
double train(std::vector< double > &weights, std::vector< Pattern > &trainPattern, const std::vector< Pattern > &testPattern, Minimizer &minimizer, Settings &settings)
start the training
Definition: NeuralNet.icc:710
EOutputFunction
Enum that represents output functions.
Definition: Functions.h:43
int type
Definition: TGX11.cxx:120
void * GetNextChild(void *prevchild, const char *childname=0)
XML helpers.
Definition: Tools.cxx:1174
static constexpr double s
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
DNN::ERegularization regularization
Definition: MethodDNN.h:89
void AddPreDefVal(const T &)
Definition: Configurable.h:168
void ExitFromTraining()
Definition: MethodBase.h:453
void DeclareOptions()
const TString & Color(const TString &)
human readable color strings
Definition: Tools.cxx:840
#define REGISTER_METHOD(CLASS)
for example
virtual ~MethodDNN()
void addLayer(Layer &layer)
add a layer (layout)
Definition: NeuralNet.h:1101
Abstract ClassifierFactory template that handles arbitrary types.
Ranking * fRanking
Definition: MethodBase.h:576
std::vector< Float_t > & GetValues()
Definition: Event.h:89
IPythonInteractive * fInteractive
Definition: MethodBase.h:437
virtual Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
Definition: MethodDNN.cxx:1256
void InitializeGradients()
Initialize the gradients in the net to zero.
Definition: Net.h:263
auto * l
Definition: textangle.C:4
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
returns first child of xmlnode
virtual void AddRank(const Rank &rank)
Add a new rank take ownership of it.
Definition: Ranking.cxx:86
MethodDNN(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption)
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=0)
create new child element for parent node
Definition: TXMLEngine.cxx:707
std::tuple< const std::vector< Event * > &, const DataSetInfo & > TMVAInput_t
Definition: DataLoader.h:40
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1896
EActivationFunction
Enum that represents layer activation functions.
Definition: Functions.h:31
std::vector< Float_t > * fRegressionReturnVal
Definition: MethodBase.h:586
Double_t Atof() const
Return floating-point value contained in string.
Definition: TString.cxx:1962
void AddWeightsXMLTo(void *parent) const
Definition: MethodDNN.cxx:1334
size_t GetBatchSize() const
Definition: Net.h:138
EnumRegularization
Definition: NeuralNet.h:173
virtual const std::vector< Float_t > & GetMulticlassValues()
Definition: MethodDNN.cxx:1311
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual const std::vector< Float_t > & GetRegressionValues()
Definition: MethodDNN.cxx:1273
TString fWeightInitializationString
The string defining the weight initialization method.
Definition: MethodDL.h:159
Layer_t & GetLayer(size_t i)
Definition: Net.h:139
std::unique_ptr< DeepNetImpl_t > fNet
Definition: MethodDL.h:91
const char * Data() const
Definition: TString.h:364