00001 #ifndef INTERFACE_HEADER
00002 #define INTERFACE_HEADER
00003
00004 #include <cstdarg>
00005 #include <errno.h>
00006 #include <fstream.h>
00007 #include <iomanip.h>
00008 #include <iostream.h>
00009 #include <stdarg.h>
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string>
00013 #include <vector>
00014
00015 #include "TChain.h"
00016 #include "TFile.h"
00017 #include "TGraph.h"
00018 #include "TH1F.h"
00019 #include "TLeaf.h"
00020 #include "TObjArray.h"
00021 #include "TTree.h"
00022 #include "TTreeFormula.h"
00023
00024 #include "Pattern.h"
00025 #include "PatternManager.h"
00026 #include "SnnsKrui.h"
00027 #include "TVariable.h"
00028
00029 extern Int_t errno;
00030
00031 class Interface : public SnnsKrui, public PatternManager {
00032
00033 protected:
00034
00035 std::vector<TVariable> fInputVariables;
00036 std::vector<TVariable> fTargetVariables;
00037 std::string _pathto_ff_bignet;
00038 std::string fNetFilePrefix;
00039 std::string fNetFileSuffix;
00041 std::string fNetName;
00042 std::string fTreeName;
00043 std::string fDirName;
00044 std::string fSelection;
00045 TObjArray *fInputTrees;
00046 TFile *fOutFile;
00047 TTree *fMasterTree;
00048 TTree *fPatternTree;
00049 TTree *fPerformaceTree;
00050 Bool_t fWriteMasterTree;
00051 Bool_t fWritePerformanceTree;
00052 Bool_t fWritePatternTree;
00053 Bool_t fWriteErrorHistograms;
00054 Bool_t fBannerPrinted;
00055 Int_t fMaxEpochs;
00056 Int_t fUpdEpochs;
00057 Double_t averageValidError;
00058 Double_t minimumValidError;
00059 Int_t minimumValidErrorEpoch;
00060 Double_t RMSTestError;
00061 Int_t hiddenLayerSize;
00062 Int_t fRandomSeed;
00063
00064 public:
00065
00066 Interface();
00067 Interface(std::string trName, std::string dirName, std::string fileName);
00068 ~Interface();
00069
00070
00071 inline void SetInputVariableAt(Int_t index, TVariable var);
00072 inline void SetTargetVariableAt(Int_t index, TVariable var);
00073 inline TVariable& GetInputVariable(Int_t index);
00074 inline TVariable& GetTargetVariable(Int_t index);
00075 inline std::string getTreeName() const { return fTreeName; }
00076 inline std::string getNetName() { return fNetName; }
00077 inline TFile *GetOutFile() { return fOutFile; }
00078
00079 inline Double_t getAverageValidError() const { return averageValidError; }
00080 inline Double_t getMinimumValidError() const { return minimumValidError; }
00081 inline Int_t getMinimumValidErrorEpoch() const { return minimumValidErrorEpoch; }
00082
00083 inline void SetMaximumEpochs(Int_t i);
00084 inline void SetUpdateEpochs(Int_t i);
00085
00086 inline void setTreeName(std::string name) { fTreeName = name; }
00087 inline void setNetName(std::string name) { fNetName = name; }
00088 inline void setOutDirectory(std::string name) { fDirName = name; }
00089 inline void WriteMasterTree(Bool_t flag);
00090 inline void WritePerformanceTree(Bool_t flag);
00091 inline void WritePatternTree(Bool_t flag);
00092 inline void WriteErrorHistograms(Bool_t flag);
00093 inline Bool_t WriteMasterTree();
00094 inline Bool_t WritePerformanceTree();
00095 inline Bool_t WritePatternTree();
00096 inline Bool_t WriteErrorHistograms();
00097 inline void setMinimumValidError(Double_t value) { minimumValidError = value; }
00098
00099 Int_t PrintVariables();
00100 void AddInputVariable(TString formula, TString name,
00101 Double_t defValue = 0.0);
00102 void AddInputVariable(TString formula, Double_t defValue = 0.0);
00103 void AddTargetVariable(TString formula, TString name,
00104 Double_t defValue = 0.0);
00105 void AddTargetVariable(TString formula, Double_t defValue = 0.0);
00106 Int_t AllocatePatternSet(std::string type = "");
00107 void SetSelection(std::string selection = "");
00108 void FillPatternSet(std::string fileName, Int_t startEvent=0,
00109 Int_t nOfEvents=-1, std::string type="");
00110 void savePatternSets();
00111 std::string runtimeInput2string();
00112 std::string CreateNN(std::vector<Int_t> numHiddenNodes);
00113 void InitializeNN(std::vector<Float_t> initParams = 0,
00114 std::string initFunc = "Randomize_Weights",
00115 Int_t randomSeed = 12345);
00116 void TrainValidate(std::string trainType, std::string validType,
00117 std::vector<Double_t> learnParams);
00118 void TrainValidateApply(std::string trainType, std::string validType,
00119 std::vector<Double_t> learnParams, std::string genErrType);
00120 void PropagatePatterns(std::string type = "");
00121 void ActivateInputs(Pattern pattern);
00122 void FillPerformanceTree();
00123 void CalculateError(std::string type);
00124 Int_t AllocNewPatternSet();
00125 void LoadNN();
00126 void LoadNN(char *filename, char **netname);
00127 void SaveNN(char *filename, char *netname);
00128 void SetSeedNo(long seed);
00129 void SetLearnFunc(char *learning_func);
00130 char *GetLearnFunc();
00131 void Finalize();
00132 void PrintProgress(Int_t i, Int_t iMax);
00133 Int_t Timer(Int_t i);
00134 std::string TimeStoHMS(UInt_t diffTime);
00135
00136 ClassDef(Interface, 1)
00137 };
00138
00139 inline void Interface::SetInputVariableAt(Int_t index, TVariable var)
00140 {
00141 fInputVariables[index] = var;
00142 }
00143
00144 inline void Interface::SetTargetVariableAt(Int_t index, TVariable var)
00145 {
00146 fTargetVariables[index] = var;
00147 }
00148
00149 inline TVariable& Interface::GetInputVariable(Int_t index)
00150 {
00151 return fInputVariables[index];
00152 }
00153
00154 inline TVariable& Interface::GetTargetVariable(Int_t index)
00155 {
00156 return fTargetVariables[index];
00157 }
00158
00159 inline void Interface::SetMaximumEpochs(Int_t i) {
00160 (i > 0) ? fMaxEpochs = i : fMaxEpochs = 500;
00161 }
00162
00163 inline void Interface::SetUpdateEpochs(Int_t i) {
00164 (i > 0) ? fUpdEpochs = i : fUpdEpochs = 50;
00165 }
00166
00167 inline void Interface::WriteMasterTree(Bool_t flag)
00168 {
00169 fWriteMasterTree = flag;
00170 }
00171
00172 inline Bool_t Interface::WriteMasterTree()
00173 {
00174 return fWriteMasterTree;
00175 }
00176
00177 inline void Interface::WritePerformanceTree(Bool_t flag)
00178 {
00179 fWritePerformanceTree = flag;
00180 }
00181
00182 inline Bool_t Interface::WritePerformanceTree()
00183 {
00184 return fWritePerformanceTree;
00185 }
00186
00187 inline void Interface::WritePatternTree(Bool_t flag)
00188 {
00189 fWritePatternTree = flag;
00190 }
00191
00192 inline Bool_t Interface::WritePatternTree()
00193 {
00194 return fWritePatternTree;
00195 }
00196
00197 inline void Interface::WriteErrorHistograms(Bool_t flag)
00198 {
00199 fWriteErrorHistograms = flag;
00200 }
00201
00202 inline Bool_t Interface::WriteErrorHistograms()
00203 {
00204 return fWriteErrorHistograms;
00205 }
00206
00207 #endif