101 const TString& theWeightFile) :
144 while (layerSpec.
Length()>0) {
146 if (layerSpec.
First(
',')<0) {
151 sToAdd = layerSpec(0,layerSpec.
First(
','));
152 layerSpec = layerSpec(layerSpec.
First(
',')+1,layerSpec.
Length());
156 nNodes += atoi(sToAdd);
161 std::vector<TString>::iterator itrVar = (*fInputVars).begin();
162 std::vector<TString>::iterator itrVarEnd = (*fInputVars).end();
164 for (; itrVar != itrVarEnd; ++itrVar) {
198 DeclareOptionRef(
fLayerSpec =
"N,N-1",
"HiddenLayers",
"Specification of hidden layer architecture (N stands for number of variables; any integers may also be used)" );
201 "Fraction of events in training tree used for cross validation" );
220 Log() << kFATAL <<
"Mechanism to ignore events with negative weights in training not available for method"
222 <<
" --> please remove \"IgnoreNegWeightsInTraining\" option from booking string."
235 for (
UInt_t ivar = 0; ivar<
Data()->GetNVariables(); ivar++) {
264 const Long_t basketsize = 128000;
267 TTree *localTrainingTree =
new TTree(
"TMLPtrain",
"Local training tree for TMlpANN" );
268 localTrainingTree->
Branch(
"type", &
type,
"type/I", basketsize );
269 localTrainingTree->
Branch(
"weight", &weight,
"weight/F", basketsize );
274 localTrainingTree->
Branch( myVar.
Data(), &vArr[ivar], myTyp.
Data(), basketsize );
277 for (
UInt_t ievt=0; ievt<
Data()->GetNEvents(); ievt++) {
284 localTrainingTree->
Fill();
294 trainList += (
Int_t)
Data()->GetNEvtSigTrain();
295 trainList +=
" || (Entry$>";
296 trainList += (
Int_t)
Data()->GetNEvtSigTrain();
297 trainList +=
" && Entry$<";
303 Log() << kHEADER <<
"Requirement for training events: \"" << trainList <<
"\"" <<
Endl;
304 Log() << kINFO <<
"Requirement for validation events: \"" << testList <<
"\"" <<
Endl;
314 fMLP->SetEventWeight(
"weight" );
329 fMLP->SetLearningMethod( learningMethod );
336 delete localTrainingTree;
352 fMLP->DumpWeights( tmpfile.
Data() );
353 std::ifstream inf( tmpfile.
Data() );
357 while (inf.getline(temp,256)) {
363 dummy = dummy(0,dummy.
First(
' '));
368 data += (dummy +
" ");
386 std::ofstream fout( fname.
Data() );
387 double temp1=0,temp2=0;
390 std::stringstream content(nodecontent);
392 fout <<
"#input normalization" << std::endl;
393 while ((content >> temp1) &&(content >> temp2)) {
394 fout << temp1 <<
" " << temp2 << std::endl;
398 fout <<
"#output normalization" << std::endl;
399 while ((content >> temp1) &&(content >> temp2)) {
400 fout << temp1 <<
" " << temp2 << std::endl;
404 fout <<
"#neurons weights" << std::endl;
405 while (content >> temp1) {
406 fout << temp1 << std::endl;
410 fout <<
"#synapses weights" ;
411 while (content >> temp1) {
412 fout << std::endl << temp1 ;
425 TTree * dummyTree =
new TTree(
"dummy",
"Empty dummy tree", 1);
426 for (
UInt_t ivar = 0; ivar<
Data()->GetNVariables(); ivar++) {
435 fMLP->LoadWeights( fname );
445 std::ofstream fout(
"./TMlp.nn.weights.temp" );
446 fout << istr.rdbuf();
450 Log() << kINFO <<
"Load TMLP weights into " <<
fMLP <<
Endl;
455 TTree * dummyTree =
new TTree(
"dummy",
"Empty dummy tree", 1);
456 for (
UInt_t ivar = 0; ivar<
Data()->GetNVariables(); ivar++) {
466 fMLP->LoadWeights(
"./TMlp.nn.weights.temp" );
480 if (theClassFileName ==
"")
483 classFileName = theClassFileName;
486 Log() << kINFO <<
"Creating specific (TMultiLayerPerceptron) standalone response class: " << classFileName <<
Endl;
487 fMLP->Export( classFileName.
Data() );
509 Log() <<
"This feed-forward multilayer perceptron neural network is the " <<
Endl;
510 Log() <<
"standard implementation distributed with ROOT (class TMultiLayerPerceptron)." <<
Endl;
512 Log() <<
"Detailed information is available here:" <<
Endl;
513 if (
gConfig().WriteOptionsReference()) {
514 Log() <<
"<a href=\"http://root.cern/root/html/TMultiLayerPerceptron.html\">";
515 Log() <<
"http://root.cern/root/html/TMultiLayerPerceptron.html</a>" <<
Endl;
517 else Log() <<
"http://root.cern/root/html/TMultiLayerPerceptron.html" <<
Endl;
#define REGISTER_METHOD(CLASS)
for example
const Bool_t EnforceNormalization__
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
void AddPreDefVal(const T &)
Class that contains all the data information.
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="")
standard constructor
TString GetMethodTypeName() const
const char * GetName() const
const TString & GetJobName() const
Bool_t IgnoreEventsWithNegWeightsInTraining() const
const TString & GetWeightFileDir() const
const TString & GetMethodName() const
const Event * GetEvent() const
DataSetInfo & DataInfo() const
UInt_t GetNVariables() const
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
const TString & GetInternalVarName(Int_t ivar) const
This is the TMVA TMultiLayerPerceptron interface class.
void ReadWeightsFromStream(std::istream &istr)
read weights from stream since the MLP can not read from the stream, we 1st: write the weights to tem...
Double_t fValidationFraction
fraction of events in training tree used for cross validation
void Init(void)
default initialisations
TString fLearningMethod
the learning method (given via option string)
TString fMLPBuildOptions
option string to build the mlp
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
TMlpANN can handle classification with 2 classes.
void Train(void)
performs TMlpANN training available learning methods:
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr)
calculate the value of the neural net for the current event
void DeclareOptions()
define the options (their key words) that can be set in the option string
TTree * fLocalTrainingTree
local copy of training tree
void CreateMLPOptions(TString)
translates options from option string into TMlpANN language
void ReadWeightsFromXML(void *wghtnode)
rebuild temporary textfile from xml weightfile and load this file into MLP
MethodTMlpANN(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="3000:N-1:N-2")
standard constructor
void ProcessOptions()
builds the neural network as specified by the user
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response nothing to do here - all taken care of by TMultiLayerPerceptron
TMultiLayerPerceptron * fMLP
the TMLP
void AddWeightsXMLTo(void *parent) const
write weights to xml file
void MakeClass(const TString &classFileName=TString("")) const
create reader class for classifier -> overwrites base class function create specific class for TMulti...
TString fLayerSpec
Layer specification option.
virtual ~MethodTMlpANN(void)
destructor
Int_t fNcycles
number of training cycles
void GetHelpMessage() const
get help message text
TString fHiddenLayer
string containing the hidden layer structure
Singleton class for Global types used by TMVA.
This class describes a neural network.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Remove(Ssiz_t pos)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
create variable transformations
MsgLogger & Endl(MsgLogger &ml)