82 using
std::stringstream;
129 TMVA::
MethodBase( jobName,
Types::kCFMlpANN, methodTitle, theData, theOption, theTargetDir ),
184 Int_t currentHiddenLayer = 1;
186 while(layerSpec.
Length()>0) {
188 if (layerSpec.
First(
',')<0) {
193 sToAdd = layerSpec(0,layerSpec.
First(
','));
194 layerSpec = layerSpec(layerSpec.First(
',')+1,layerSpec.Length());
198 nNodes += atoi(sToAdd);
199 fNodes[currentHiddenLayer++] = nNodes;
206 Log() <<
kFATAL <<
"Mechanism to ignore events with negative weights in training not yet available for method: " 208 <<
" --> please remove \"IgnoreNegWeightsInTraining\" option from booking string." 212 Log() <<
kINFO <<
"Use configuration (nodes per layer): in=";
226 fClass =
new std::vector<Int_t>( nEvtTrain );
231 for (
Int_t ievt=0; ievt<nEvtTrain; ievt++) {
238 for (ivar=0; ivar<
GetNvar(); ivar++) {
239 (*fData)( ievt, ivar ) = ev->
GetValue(ivar);
286 Int_t ntrain(
Data()->GetNTrainingEvents());
293 for (
Int_t i=0; i<nlayers; i++) nodes[i] =
fNodes[i];
301 for (
Int_t layer=0; layer<nlayers; layer++)
306 Train_nn( &dumDat, &dumDat, &ntrain, &ntest, &nvar, &nlayers, nodes, &ncycles );
308 Log() <<
kWARNING <<
"<Train> sorry CFMlpANN does not run on Windows" <<
Endl;
324 std::vector<Double_t> inputVec(
GetNvar() );
328 if (!isOK)
Log() <<
kFATAL <<
"EvalANN returns (!isOK) for event " <<
Endl;
343 for (
UInt_t ivar=0; ivar<
GetNvar(); ivar++) xeev[ivar] = inVar[ivar];
349 if (
fVarn_1.xmax[jvar] < xeev[jvar]) xeev[jvar] =
fVarn_1.xmax[jvar];
350 if (
fVarn_1.xmin[jvar] > xeev[jvar]) xeev[jvar] =
fVarn_1.xmin[jvar];
356 xeev[jvar] = xeev[jvar] - ((
fVarn_1.xmax[jvar] +
fVarn_1.xmin[jvar])/2);
357 xeev[jvar] = xeev[jvar] / ((
fVarn_1.xmax[jvar] -
fVarn_1.xmin[jvar])/2);
375 for (
Int_t ivar=0; ivar<
fNeur_1.neuron[0]; ivar++)
fYNN[0][ivar] = xeev[ivar];
397 if (u/
fDel_1.temp[i] > 170) f = +1;
398 else if (u/
fDel_1.temp[i] < -170) f = -1;
401 f = (1 - yy)/(1 + yy);
419 Log() <<
kFATAL <<
"<ReadWeightsFromFile> mismatch in number of variables" <<
Endl;
423 Log() <<
kFATAL <<
"<ReadWeightsFromFile> mismatch in number of classes" <<
Endl;
427 Log() <<
kFATAL <<
"<ReadWeightsFromStream> reached EOF prematurely " <<
Endl;
450 const Int_t nchar( 100 );
451 char* dumchar =
new char[nchar];
463 for (
Int_t k=1; k<=kk; k++) {
464 Int_t jmin = 10*k - 9;
467 for (
Int_t j=jmin; j<=jmax; j++) {
471 for (
Int_t j=jmin; j<=jmax; j++) {
476 istr.getline( dumchar, nchar );
483 istr.getline( dumchar, nchar );
484 istr.getline( dumchar, nchar );
486 istr >>
fDel_1.temp[layer];
491 Log() <<
kFATAL <<
"<ReadWeightsFromFile> mismatch in zeroth layer:" 515 Log() <<
kFATAL <<
"ERROR in MethodCFMlpANN_DataInterface zero pointer xpg" <<
Endl;
518 Log() <<
kFATAL <<
"ERROR in MethodCFMlpANN_DataInterface mismatch in num of variables: " 545 s << std::scientific <<
fVarn_1.xmin[ivar] <<
" " <<
fVarn_1.xmax[ivar] <<
" ";
551 n << std::scientific <<
fNeur_1.neuron[layer] <<
" ";
556 void* neuronnode=
NULL;
559 stringstream weights;
560 weights.precision( 16 );
570 temp.precision( 16 );
572 temp << std::scientific <<
fDel_1.temp[layer] <<
" ";
584 stringstream content(minmaxcontent);
595 stringstream ncontent(neuronscontent);
599 ncontent >>
fNeur_1.neuron[layer];
604 void* neuronnode=
NULL;
608 stringstream weights(neuronweights);
618 stringstream t(temp);
631 o <<
"Number of vars " <<
fParam_1.nvar << std::endl;
632 o <<
"Output nodes " <<
fParam_1.lclass << std::endl;
636 o <<
"Var " << ivar <<
" [" <<
fVarn_1.xmin[ivar] <<
" - " <<
fVarn_1.xmax[ivar] <<
"]" << std::endl;
639 o <<
"Number of layers " <<
fParam_1.layerm << std::endl;
641 o <<
"Nodes per layer ";
644 o <<
fNeur_1.neuron[layer] <<
" ";
657 for (
Int_t k=1; k<=kk; k++) {
658 Int_t jmin = 10*k - 9;
662 for (j=jmin; j<=jmax; j++) {
670 for (i=1; i<=
fNeur_1.neuron[layer-1]; i++) {
671 for (j=jmin; j<=jmax; j++) {
683 o <<
"Del.temp in layer " << layer <<
" : " <<
fDel_1.temp[layer] << std::endl;
696 fout <<
" // not implemented for class: \"" << className <<
"\"" << std::endl;
697 fout <<
"};" << std::endl;
Double_t GetData(Int_t isel, Int_t ivar) const
void Train(void)
training of the Clement-Ferrand NN classifier
void DeclareOptions()
define the options (their key words) that can be set in the option string know options: NCycles=xx :t...
MsgLogger & Endl(MsgLogger &ml)
Double_t temp[max_nLayers_]
void NN_ava(Double_t *)
auxiliary functions
void MakeClassSpecificHeader(std::ostream &, const TString &="") const
write specific classifier response for header
Int_t MethodCFMlpANN_nsel
Int_t GetClass(Int_t ivar) const
void ReadWeightsFromXML(void *wghtnode)
read weights from xml file
void MakeClassSpecific(std::ostream &, const TString &) const
static MethodCFMlpANN * fgThis
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
struct TMVA::MethodCFMlpANN_Utils::@211 fNeur_1
Double_t W_ref(const Double_t wNN[], Int_t a_1, Int_t a_2, Int_t a_3) const
Int_t DataInterface(Double_t *, Double_t *, Int_t *, Int_t *, Int_t *, Int_t *, Double_t *, Int_t *, Int_t *)
data interface function
virtual ~MethodCFMlpANN(void)
destructor
const Event * GetEvent() const
std::vector< Int_t > * fClass
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t)
CFMlpANN can handle classification with 2 classes.
DataSetInfo & DataInfo() const
Ssiz_t First(char c) const
Find first occurrence of a character c.
void PrintWeights(std::ostream &o) const
write the weights of the neural net
Long64_t GetNTrainingEvents() const
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns CFMlpANN output (normalised within [0,1])
Double_t NN_fonc(Int_t, Double_t) const
activation function
struct TMVA::MethodCFMlpANN_Utils::@209 fParam_1
MethodCFMlpANN(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="3000:N-1:N-2", TDirectory *theTargetDir=0)
standard constructor option string: "n_training_cycles:n_hidden_layers" default is: n_training_cycles...
void Train_nn(Double_t *tin2, Double_t *tout2, Int_t *ntrain, Int_t *ntest, Int_t *nvar2, Int_t *nlayer, Int_t *nodes, Int_t *ncycle)
struct TMVA::MethodCFMlpANN_Utils::@212 fDel_1
Double_t Ww_ref(const Double_t wwNN[], Int_t a_1, Int_t a_2) const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Double_t x[max_nLayers_ *max_nNodes_]
void GetHelpMessage() const
get help message text
Double_t EvalANN(std::vector< Double_t > &, Bool_t &isOK)
evaluates NN value as function of input variables
void ReadWeightsFromStream(std::istream &istr)
read back the weight from the training from file (stream)
void SetNormalised(Bool_t norm)
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
TString & Remove(Ssiz_t pos)
Bool_t IgnoreEventsWithNegWeightsInTraining() const
Describe directory structure in memory.
Int_t neuron[max_nLayers_]
void AddWeightsXMLTo(void *parent) const
write weights to xml file
TMatrixT< Float_t > TMatrix
void Init(void)
default initialisation called by all constructors
void ProcessOptions()
decode the options in the option string
void SetLogger(MsgLogger *l)
struct TMVA::MethodCFMlpANN_Utils::@210 fVarn_1
#define REGISTER_METHOD(CLASS)
for example
Abstract ClassifierFactory template that handles arbitrary types.
TString GetMethodTypeName() const
Bool_t IsSignal(const Event *ev) const
static MethodCFMlpANN * This(void)
static pointer to this object (required for external functions
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
if(line.BeginsWith("/*"))