| 1 | #ifndef MARS_MRanTree
|
|---|
| 2 | #define MARS_MRanTree
|
|---|
| 3 |
|
|---|
| 4 | #ifndef MARS_MParContainer
|
|---|
| 5 | #include "MParContainer.h"
|
|---|
| 6 | #endif
|
|---|
| 7 |
|
|---|
| 8 | #ifndef ROOT_TArrayI
|
|---|
| 9 | #include <TArrayI.h>
|
|---|
| 10 | #endif
|
|---|
| 11 |
|
|---|
| 12 | #ifndef ROOT_TArrayF
|
|---|
| 13 | #include <TArrayF.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | class TMatrix;
|
|---|
| 17 | class TMatrixRow;
|
|---|
| 18 | class TVector;
|
|---|
| 19 | class TRandom;
|
|---|
| 20 |
|
|---|
| 21 | class MRanTree : public MParContainer
|
|---|
| 22 | {
|
|---|
| 23 | private:
|
|---|
| 24 | Bool_t fClassify;
|
|---|
| 25 |
|
|---|
| 26 | Int_t fNdSize;
|
|---|
| 27 | Int_t fNumTry;
|
|---|
| 28 |
|
|---|
| 29 | Int_t fNumNodes;
|
|---|
| 30 | Int_t fNumEndNodes;
|
|---|
| 31 | Float_t fError;
|
|---|
| 32 |
|
|---|
| 33 | TArrayI fBestVar;
|
|---|
| 34 | TArrayI fTreeMap1;
|
|---|
| 35 | TArrayI fTreeMap2;
|
|---|
| 36 | TArrayF fBestSplit;
|
|---|
| 37 | TArrayF fGiniDec;
|
|---|
| 38 |
|
|---|
| 39 | int (MRanTree::*FindBestSplit)
|
|---|
| 40 | (const TArrayI &, const TArrayI &, const TArrayF &, const TArrayI &,
|
|---|
| 41 | Int_t, Int_t , TArrayF &, float &, float &, Int_t &, Float_t &,
|
|---|
| 42 | Int_t &, const TArrayF &, const int); //!
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | int FindBestSplitGini(const TArrayI &datasort, const TArrayI &datarang,
|
|---|
| 46 | const TArrayF &hadtrue, const TArrayI &idclass,
|
|---|
| 47 | Int_t ndstart, Int_t ndend, TArrayF &tclasspop,
|
|---|
| 48 | float &mean, float &square, Int_t &msplit,
|
|---|
| 49 | Float_t &decsplit, Int_t &nbest, const TArrayF &winbag,
|
|---|
| 50 | const int nclass);
|
|---|
| 51 |
|
|---|
| 52 | int FindBestSplitSigma(const TArrayI &datasort, const TArrayI &datarang,
|
|---|
| 53 | const TArrayF &hadtrue, const TArrayI &idclass,
|
|---|
| 54 | Int_t ndstart, Int_t ndend, TArrayF &tclasspop,
|
|---|
| 55 | float &mean, float &square, Int_t &msplit,
|
|---|
| 56 | Float_t &decsplit, Int_t &nbest, const TArrayF &winbag,
|
|---|
| 57 | const int nclass);
|
|---|
| 58 |
|
|---|
| 59 | void MoveData(TArrayI &datasort, Int_t ndstart, Int_t ndend,
|
|---|
| 60 | TArrayI &idmove, TArrayI &ncase, Int_t msplit,
|
|---|
| 61 | Int_t nbest, Int_t &ndendl);
|
|---|
| 62 |
|
|---|
| 63 | void BuildTree(TArrayI &datasort, const TArrayI &datarang, const TArrayF &hadtrue,
|
|---|
| 64 | const TArrayI &idclass,TArrayI &bestsplit,TArrayI &bestsplitnext,
|
|---|
| 65 | TArrayF &tclasspop, float &tmean, float &tsquare, const TArrayF &winbag,
|
|---|
| 66 | Int_t ninbag, const int nclass);
|
|---|
| 67 |
|
|---|
| 68 | public:
|
|---|
| 69 | MRanTree(const char *name=NULL, const char *title=NULL);
|
|---|
| 70 | MRanTree(const MRanTree &tree);
|
|---|
| 71 |
|
|---|
| 72 | void SetNdSize(Int_t n);
|
|---|
| 73 | void SetNumTry(Int_t n);
|
|---|
| 74 | void SetError(Float_t f) { fError = f; }
|
|---|
| 75 |
|
|---|
| 76 | Int_t GetNdSize() const { return fNdSize; }
|
|---|
| 77 | Int_t GetNumTry() const { return fNumTry; }
|
|---|
| 78 | Int_t GetNumNodes() const { return fNumNodes; }
|
|---|
| 79 | Int_t GetNumEndNodes() const { return fNumEndNodes; }
|
|---|
| 80 | Int_t IsClassify() const { return fClassify; }
|
|---|
| 81 | Float_t GetError() const { return fError; }
|
|---|
| 82 |
|
|---|
| 83 | Int_t GetBestVar(Int_t i) const { return fBestVar.At(i); }
|
|---|
| 84 | Int_t GetTreeMap1(Int_t i) const { return fTreeMap1.At(i); }
|
|---|
| 85 | Int_t GetTreeMap2(Int_t i) const { return fTreeMap2.At(i); }
|
|---|
| 86 | Int_t GetNodeClass(Int_t i) const { return fBestVar.At(i)+2; }
|
|---|
| 87 | Int_t GetNodeStatus(Int_t i) const { return TMath::Sign(1,fBestVar.At(i));}
|
|---|
| 88 | Float_t GetBestSplit(Int_t i)const { return fBestSplit.At(i); }
|
|---|
| 89 |
|
|---|
| 90 | Float_t GetGiniDec(Int_t i) const { return fGiniDec.At(i); }
|
|---|
| 91 |
|
|---|
| 92 | void SetClassify(Bool_t n){ fClassify=n; }
|
|---|
| 93 |
|
|---|
| 94 | // functions used in tree growing process
|
|---|
| 95 | void GrowTree(TMatrix *mat, const TArrayF &hadtrue, const TArrayI &idclass,
|
|---|
| 96 | TArrayI &datasort, const TArrayI &datarang,TArrayF &tclasspop,
|
|---|
| 97 | float &mean, float &square, TArrayI &jinbag, const TArrayF &winbag,
|
|---|
| 98 | const int nclass);
|
|---|
| 99 |
|
|---|
| 100 | Double_t TreeHad(const TVector &event);
|
|---|
| 101 | Double_t TreeHad(const TMatrixRow &event);
|
|---|
| 102 | Double_t TreeHad(const TMatrix &m, Int_t ievt);
|
|---|
| 103 |
|
|---|
| 104 | Bool_t AsciiWrite(ostream &out) const;
|
|---|
| 105 |
|
|---|
| 106 | ClassDef(MRanTree, 1) // Storage container for tree structure
|
|---|
| 107 | };
|
|---|
| 108 |
|
|---|
| 109 | #endif
|
|---|