Changeset 7420 for trunk/MagicSoft/Mars
- Timestamp:
- 11/22/05 11:06:56 (19 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r7418 r7420 30 30 * mfbase/MFEventSelector.cc: 31 31 - also reset fSelRatio if totalnumber of events from file. 32 33 * mranforest/MHRanForestGini.[h,cc]: 34 - added a TPaveText containing text information to output 35 36 * mranforest/MRanForest.[h,cc]: 37 - replaced type of fClassify by Bool_t 38 - improved handling of allocated memory (still to be checked 39 further) 40 41 * mranforest/MRanForestCalc.[h,cc]: 42 - added another training type 43 - added some comments 44 45 * mranforest/MRanTree.[h,cc]: 46 - replaced type of fClassify by Bool_t 47 48 * mjtrain/MJTrainDisp.cc, mjtrain/MJTrainEnegry.cc: 49 - renamed TrainSingleRF to TrainRegression 50 51 * mjtrain/MJTrainDisp.cc: 52 - replaced training variable (hypot(dist,dca)) by dist 53 54 * mjtrain/MJTrainRanForest.cc: 55 - added some comment 56 57 * mjtrain/MJTrainSeparation.cc: 58 - updated output 59 - made it work properly 32 60 33 61 -
trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc
r7412 r7420 115 115 MHMatrix train("Train"); 116 116 train.AddColumns(fRules); 117 //train.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");118 train.AddColumn("TMath::Hypot(MHillasSrc.fDCA, MHillasSrc.fDist)*MGeomCam.fConvMm2Deg");117 train.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg"); 118 //train.AddColumn("TMath::Hypot(MHillasSrc.fDCA, MHillasSrc.fDist)*MGeomCam.fConvMm2Deg"); 119 119 120 120 // ----------------------- Fill Matrix RF ---------------------- … … 147 147 return; 148 148 */ 149 if (!rf.Train SingleRF(train)) // regression (best choice)149 if (!rf.TrainRegression(train)) // regression (best choice) 150 150 return kFALSE; 151 151 -
trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
r7412 r7420 141 141 return; 142 142 */ 143 if (!rf.Train SingleRF(train)) // regression (best choice)143 if (!rf.TrainRegression(train)) // regression (best choice) 144 144 return kFALSE; 145 145 -
trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc
r7412 r7420 26 26 // 27 27 // MJTrainRanForest 28 // 29 // Base class for classes training a random forest 28 30 // 29 31 ///////////////////////////////////////////////////////////////////////////// -
trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc
r7412 r7420 30 30 #include "MJTrainSeparation.h" 31 31 32 #include <TH2.h> 33 #include <TGraph.h> 34 #include <TVirtualPad.h> 35 32 36 #include "MHMatrix.h" 33 37 … … 36 40 37 41 // tools 42 #include "MMath.h" 38 43 #include "MDataSet.h" 39 44 #include "MTFillMatrix.h" 40 45 #include "MChisqEval.h" 46 #include "MStatusDisplay.h" 41 47 42 48 // eventloop … … 63 69 // filter 64 70 #include "MF.h" 71 #include "MFEventSelector.h" 65 72 #include "MFilterList.h" 66 73 … … 68 75 69 76 using namespace std; 77 78 void MJTrainSeparation::DisplayResult(MH3 &h31, MH3 &h32) 79 { 80 TH2 &g = (TH2&)h32.GetHist(); 81 TH2 &h = (TH2&)h31.GetHist(); 82 83 h.SetMarkerColor(kRed); 84 g.SetMarkerColor(kGreen); 85 86 const Int_t nx = h.GetNbinsX(); 87 const Int_t ny = h.GetNbinsY(); 88 89 gROOT->SetSelectedPad(NULL); 90 91 TGraph gr1; 92 TGraph gr2; 93 for (int x=0; x<nx; x++) 94 { 95 TH1 *hx = h.ProjectionY("H_py", x+1, x+1); 96 TH1 *gx = g.ProjectionY("G_py", x+1, x+1); 97 98 Double_t max1 = -1; 99 Double_t max2 = -1; 100 Int_t maxy1 = 0; 101 Int_t maxy2 = 0; 102 for (int y=0; y<ny; y++) 103 { 104 const Float_t s = gx->Integral(1, y+1); 105 const Float_t b = hx->Integral(1, y+1); 106 const Float_t sig1 = MMath::SignificanceLiMa(s+b, b); 107 const Float_t sig2 = s<1 ? 0 : MMath::SignificanceLiMa(s+b, b)*TMath::Log10(s); 108 if (sig1>max1) 109 { 110 maxy1 = y; 111 max1 = sig1; 112 } 113 if (sig2>max2) 114 { 115 maxy2 = y; 116 max2 = sig2; 117 } 118 } 119 120 gr1.SetPoint(x, h.GetXaxis()->GetBinCenter(x+1), h.GetYaxis()->GetBinCenter(maxy1+1)); 121 gr2.SetPoint(x, h.GetXaxis()->GetBinCenter(x+1), h.GetYaxis()->GetBinCenter(maxy2+1)); 122 123 delete hx; 124 delete gx; 125 } 126 127 fDisplay->AddTab("OptCut"); 128 gPad->SetLogx(); 129 h.DrawCopy(); 130 g.DrawCopy("same"); 131 gr1.SetMarkerStyle(kFullDotMedium); 132 gr1.DrawClone("LP")->SetBit(kCanDelete); 133 gr2.SetLineColor(kBlue); 134 gr2.SetMarkerStyle(kFullDotMedium); 135 gr2.DrawClone("LP")->SetBit(kCanDelete); 136 } 70 137 71 138 Bool_t MJTrainSeparation::Train(const char *out) … … 83 150 84 151 // --------------------- Setup files -------------------- 85 MReadMarsFile read ("Events");152 MReadMarsFile read1("Events"); 86 153 MReadMarsFile read2("Events"); 87 154 MReadMarsFile read3("Events"); 88 read.DisableAutoScheme(); 155 MReadMarsFile read4("Events"); 156 read1.DisableAutoScheme(); 89 157 read2.DisableAutoScheme(); 90 158 read3.DisableAutoScheme(); 91 92 fDataSetTrain.AddFilesOn(read); 159 read4.DisableAutoScheme(); 160 161 fDataSetTrain.AddFilesOn(read1); 93 162 fDataSetTrain.AddFilesOff(read3); 94 163 95 164 fDataSetTest.AddFilesOff(read2); 96 fDataSetTest.AddFilesOn(read2); 97 98 read2.VetoBranch("MMcTrig"); 99 read2.VetoBranch("MTime"); 100 read2.VetoBranch("MMcRunHeader"); 101 read2.VetoBranch("MMcTrigHeader"); 102 read2.VetoBranch("MMcFadcHeader"); 103 read2.VetoBranch("MMcCorsikaRunHeader"); 104 read2.VetoBranch("MMcConfigRunHeader"); 105 165 fDataSetTest.AddFilesOn(read4); 106 166 107 167 // ----------------------- Setup RF ---------------------- … … 116 176 MParList plistx; 117 177 plistx.AddToList(&had); 178 plistx.AddToList(this); 118 179 119 180 MTFillMatrix fill; … … 127 188 fill.SetName("FillGammas"); 128 189 fill.SetDestMatrix1(&train, fNumTrainOn); 129 fill.SetReader(&read );190 fill.SetReader(&read1); 130 191 if (!fill.Process(plistx)) 131 192 return kFALSE; … … 160 221 return kFALSE; 161 222 223 //fDisplay = rf.GetDisplay(); 224 162 225 // --------------------- Display result ---------------------- 163 164 226 gLog.Separator("Test"); 165 227 … … 172 234 plist.AddToList(&mcevt); 173 235 236 // ----- Setup histograms ----- 174 237 MBinning binsy(100, 0 , 1, "BinningMH3Y", "lin"); 175 MBinning binsx( 100, 10, 100000, "BinningMH3X", "log");238 MBinning binsx( 50, 10, 100000, "BinningMH3X", "log"); 176 239 177 240 plist.AddToList(&binsx); … … 183 246 h32.SetTitle("Background probability vs. Size:Size [phe]:Hadronness"); 184 247 185 MF f("MRawRunHeader.fRunType>255");186 MFilterList list;187 list.SetInverted();188 list.AddToList(&f);189 190 248 MHHadronness hist; 191 249 192 MFillH fillh(&hist, "", "FillHadronness");193 MFillH fillh 1(&h31, "", "FillGammas");194 MFillH fillh 2(&h32, "", "FillBackground");195 fillh1.SetNameTab("Gammas");196 fillh 2.SetNameTab("Background");197 198 fillh 1.SetFilter(&f);199 fillh2.SetFilter(&list); 200 250 // ----- Setup tasks ----- 251 MFillH fillh0(&hist, "", "FillHadronness"); 252 MFillH fillh1(&h31); 253 MFillH fillh2(&h32); 254 fillh1.SetNameTab("Background"); 255 fillh2.SetNameTab("Gammas"); 256 fillh0.SetBit(MFillH::kDoNotDisplay); 257 258 // ----- Setup filter ----- 201 259 MFilterList precuts; 202 260 precuts.AddToList(fPreCuts); … … 204 262 205 263 MContinue c0(&precuts); 264 c0.SetName("PreCuts"); 206 265 c0.SetInverted(); 207 266 267 MFEventSelector sel; 268 sel.SetNumSelectEvts(fNumTestOn); 269 270 MContinue c1(&sel); 271 c1.SetInverted(); 272 273 // ----- Setup tasklist ----- 208 274 tlist.AddToList(&read2); 209 275 tlist.AddToList(&c0); 276 tlist.AddToList(&c1); 210 277 tlist.AddToList(&rf); 211 tlist.AddToList(&fillh); 212 tlist.AddToList(&list); 278 tlist.AddToList(&fillh0); 213 279 tlist.AddToList(&fillh1); 214 tlist.AddToList(&fillh2); 215 280 281 // ----- Run eventloop on gammas ----- 216 282 MEvtLoop loop; 217 283 loop.SetDisplay(fDisplay); … … 222 288 return kFALSE; 223 289 290 // ----- Setup and run eventloop on background ----- 291 sel.SetNumSelectEvts(fNumTestOff); 292 fillh0.ResetBit(MFillH::kDoNotDisplay); 293 294 tlist.Replace(&read4); 295 tlist.Replace(&fillh2); 296 297 if (!loop.Eventloop()) 298 return kFALSE; 299 300 DisplayResult(h31, h32); 301 224 302 if (!WriteDisplay(out)) 225 303 return kFALSE; -
trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h
r7412 r7420 10 10 #endif 11 11 12 class MH3; 13 12 14 class MJTrainSeparation : public MJTrainRanForest 13 15 { … … 19 21 UInt_t fNumTrainOff; 20 22 23 UInt_t fNumTestOn; 24 UInt_t fNumTestOff; 25 26 void DisplayResult(MH3 &h31, MH3 &h32); 27 21 28 public: 22 MJTrainSeparation() { } 29 MJTrainSeparation() : 30 fNumTrainOn((UInt_t)-1), fNumTrainOff((UInt_t)-1), fNumTestOn((UInt_t)-1), fNumTestOff((UInt_t)-1) 31 { } 23 32 24 void SetDataSetTrain(const MDataSet &ds, UInt_t non , UInt_t noff)33 void SetDataSetTrain(const MDataSet &ds, UInt_t non=(UInt_t)-1, UInt_t noff=(UInt_t)-1) 25 34 { 26 35 ds.Copy(fDataSetTrain); … … 28 37 fNumTrainOff = noff; 29 38 } 30 void SetDataSetTest(const MDataSet &ds )39 void SetDataSetTest(const MDataSet &ds, UInt_t non=(UInt_t)-1, UInt_t noff=(UInt_t)-1) 31 40 { 32 41 ds.Copy(fDataSetTest); 42 fNumTestOn = non; 43 fNumTestOff = noff; 33 44 } 34 45 -
trunk/MagicSoft/Mars/mranforest/MRanForest.cc
r7417 r7420 62 62 // Default constructor. 63 63 // 64 MRanForest::MRanForest(const char *name, const char *title) : fClassify(1), fNumTrees(100), fNumTry(0), fNdSize(1), fRanTree(NULL), fUserVal(-1) 64 MRanForest::MRanForest(const char *name, const char *title) 65 : fClassify(kTRUE), fNumTrees(100), fNumTry(0), fNdSize(1), 66 fRanTree(NULL), fRules(NULL), fMatrix(NULL), fUserVal(-1) 65 67 { 66 68 fName = name ? name : "MRanForest"; … … 125 127 { 126 128 delete fForest; 129 if (fMatrix) 130 delete fMatrix; 131 if (fRules) 132 delete fRules; 127 133 } 128 134 … … 152 158 void MRanForest::SetWeights(const TArrayF &weights) 153 159 { 154 const int n=weights.GetSize();155 fWeight.Set(n);156 160 fWeight=weights; 157 158 return;159 161 } 160 162 … … 175 177 //for(int i=0;i<n;i++) 176 178 // *fLog<<inf<<" "<<i<<") "<<fGrid[i]<<endl; 177 178 return;179 179 } 180 180 … … 227 227 } 228 228 229 /*230 Bool_t MRanForest::PreProcess(MParList *plist)231 {232 if (!fRules)233 {234 *fLog << err << dbginf << "MDataArray with rules not initialized... aborting." << endl;235 return kFALSE;236 }237 238 if (!fRules->PreProcess(plist))239 {240 *fLog << err << dbginf << "PreProcessing of MDataArray failed... aborting." << endl;241 return kFALSE;242 }243 244 return kTRUE;245 }246 */247 248 229 Double_t MRanForest::CalcHadroness() 249 230 { … … 285 266 // access matrix, copy last column (target) preliminarily 286 267 // into fHadTrue 268 if (fMatrix) 269 delete fMatrix; 287 270 fMatrix = new TMatrix(mat->GetM()); 288 271 … … 337 320 } 338 321 322 if (fRules) 323 delete fRules; 339 324 fRules = new MDataArray(); 340 325 fRules->Reset(); -
trunk/MagicSoft/Mars/mranforest/MRanForest.h
r7396 r7420 30 30 { 31 31 private: 32 Int_t fClassify;32 Bool_t fClassify; 33 33 34 34 Int_t fNumTrees; // Number of trees … … 83 83 void SetNdSize(Int_t n); 84 84 85 void SetClassify( Int_t n){ fClassify=n; }85 void SetClassify(Bool_t n){ fClassify=n; } 86 86 void PrepareClasses(); 87 87 -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
r7413 r7420 79 79 } 80 80 81 // -------------------------------------------------------------------------- 82 // 83 // ver=0: One yes/no-classification forest is trained for each bin. 84 // the yes/no classification is done using the grid 85 // ver=1: One classification forest is trained. The last column contains a 86 // value which is turned into a classifier by rf itself using the grid 87 // ver=2: One classification forest is trained. The last column already contains 88 // the classifier 89 // ver=3: A regression forest is trained. The last column contains the 90 // classifier 91 // 81 92 Int_t MRanForestCalc::Train(const MHMatrix &matrixtrain, const TArrayD &grid, Int_t ver) 82 93 { … … 117 128 118 129 MDataArray rules(usedrules); 119 rules.AddEntry(ver< 2?"Classification":dcol[ncols-1].GetRule());130 rules.AddEntry(ver<3?"Classification":dcol[ncols-1].GetRule()); 120 131 121 132 // prepare matrix for current energy bin … … 133 144 switch (ver) 134 145 { 135 case 0: // Replace Energy Grid byclassification146 case 0: // Replace last column by a classification 136 147 { 137 148 Int_t irows=0; … … 158 169 break; 159 170 160 case 1: // Use Energy as classifier171 case 1: // Use last column as classifier or for regression 161 172 case 2: 173 case 3: 162 174 for (Int_t j=0; j<nrows; j++) 163 175 mat(j, ncols-nobs) = matrixtrain.GetM()(j,ncols-1); … … 176 188 rf.SetNumTry(fNumTry); 177 189 rf.SetNdSize(fNdSize); 178 rf.SetClassify(ver< 2 ? 1 : 0);190 rf.SetClassify(ver<3 ? kTRUE : kFALSE); 179 191 if (ver==1) 180 192 rf.SetGrid(grid); -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
r7413 r7420 65 65 66 66 // Train Interface 67 Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver =2);67 Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver); 68 68 69 69 public: … … 87 87 Int_t TrainMultiRF(const MHMatrix &n, const TArrayD &grid) 88 88 { 89 // One yes/no-classification forest is trained for each bin 89 90 return Train(n, grid, 0); 90 91 } 91 92 Int_t TrainSingleRF(const MHMatrix &n, const TArrayD &grid=TArrayD()) 92 93 { 94 // w/o Grid: Last Column contains classifier 95 // w/ Grid: Last Column will be converted by grid into classifier 93 96 return Train(n, grid, grid.GetSize()==0 ? 2 : 1); 97 } 98 Int_t TrainRegression(const MHMatrix &n) 99 { 100 // Use last column for regression 101 return Train(n, TArrayD(), 3); 94 102 } 95 103 -
trunk/MagicSoft/Mars/mranforest/MRanTree.cc
r7396 r7420 49 49 // Default constructor. 50 50 // 51 MRanTree::MRanTree(const char *name, const char *title):fClassify( 1),fNdSize(0), fNumTry(3)51 MRanTree::MRanTree(const char *name, const char *title):fClassify(kTRUE),fNdSize(0), fNumTry(3) 52 52 { 53 53 -
trunk/MagicSoft/Mars/mranforest/MRanTree.h
r7413 r7420 22 22 { 23 23 private: 24 Int_t fClassify; 24 Bool_t fClassify; 25 25 26 Int_t fNdSize; 26 27 Int_t fNumTry; … … 88 89 Float_t GetGiniDec(Int_t i) const { return fGiniDec.At(i); } 89 90 90 void SetClassify( Int_t n){ fClassify=n; }91 void SetClassify(Bool_t n){ fClassify=n; } 91 92 92 93 // functions used in tree growing process
Note:
See TracChangeset
for help on using the changeset viewer.