Changeset 7687 for trunk/MagicSoft/Mars/mranforest
- Timestamp:
- 05/03/06 14:13:48 (19 years ago)
- Location:
- trunk/MagicSoft/Mars/mranforest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
r7425 r7687 63 63 : fData(0), fRFOut(0), fTestMatrix(0), 64 64 fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1), 65 fLastDataColumnHasWeights(kFALSE), 65 66 fNameOutput(gsNameOutput), fDebug(kFALSE), fEstimationMode(kMean) 66 67 { … … 116 117 } 117 118 118 const Int_t nobs = fNumObsoleteVariables; // Number of obsolete columns 119 // The number of columns which have to be removed for the training 120 // The last data column may contain weight which also have to be removed 121 const Int_t nobs = fNumObsoleteVariables + (fLastDataColumnHasWeights?1:0); // Number of obsolete columns 119 122 120 123 const MDataArray &dcol = *matrixtrain.GetColumns(); 121 124 125 // Make a copy of the rules for accessing the train-data 122 126 MDataArray usedrules; 123 127 for (Int_t i=0; i<ncols; i++) … … 127 131 *fLog << inf << "Skipping " << dcol[i].GetRule() << " for training" << endl; 128 132 133 // In the case of regression store the rule to be regessed in the 134 // last entry of your rules 129 135 MDataArray rules(usedrules); 130 136 rules.AddEntry(ver<3?"Classification":dcol[ncols-1].GetRule()); 131 137 132 // prepare matrix for current energy bin138 // prepare train-matrix finally used 133 139 TMatrix mat(matrixtrain.GetM()); 134 140 135 // last column must be removed (true energy col.)141 // Resize it such that the obsolete columns are removed 136 142 mat.ResizeTo(nrows, ncols-nobs+1); 137 143 … … 139 145 gLog.SetNullOutput(kTRUE); 140 146 147 // In the case one independant RF is trained for each bin (e.g. 148 // energy-bin) train all of them 141 149 const Int_t nbins = ver>0 ? 1 : grid.GetSize()-1; 142 150 for (Int_t ie=0; ie<nbins; ie++) 143 151 { 152 // In the case weights should be used initialize the 153 // corresponding array 154 TArrayF weights(nrows); 155 if (fLastDataColumnHasWeights) 156 for (Int_t j=0; j<nrows; j++) 157 { 158 weights[j] = matrixtrain.GetM()(j, ncols-nobs); 159 if (j%100==0) 160 cout << weights[j] << " "; 161 } 162 163 // Setup the matrix such that the last comlumn contains 164 // the classifier or the regeression target value 144 165 switch (ver) 145 166 { 146 case 0: // Replace last column by a classification 167 case 0: // Replace last column by a classification which is 1 in 168 // the case the event belongs to this bin, 0 otherwise 147 169 { 148 170 Int_t irows=0; 149 171 for (Int_t j=0; j<nrows; j++) 150 172 { 151 const Double_t energy= matrixtrain.GetM()(j,ncols-1);152 const Bool_t inside = energy>grid[ie] && energy<=grid[ie+1];173 const Double_t value = matrixtrain.GetM()(j,ncols-1); 174 const Bool_t inside = value>grid[ie] && value<=grid[ie+1]; 153 175 154 176 mat(j, ncols-nobs) = inside ? 1 : 0; … … 162 184 *fLog << inf << "Training RF for"; 163 185 164 *fLog << " energybin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl;186 *fLog << " bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl; 165 187 166 188 if (irows==0) … … 191 213 if (ver==1) 192 214 rf.SetGrid(grid); 215 if (fLastDataColumnHasWeights) 216 rf.SetWeights(weights); 193 217 194 218 plist.AddToList(&rf); -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
r7425 r7687 44 44 45 45 Int_t fNumObsoleteVariables; //! Training parameters 46 Bool_t fLastDataColumnHasWeights; //! Training parameters 46 47 47 48 TString fFileName; // File name to forest … … 84 85 void SetDebug(Bool_t b=kTRUE) { fDebug = b; } 85 86 86 void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; } 87 void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; } 88 void SetLastDataColumnHasWeights(Bool_t b=kTRUE) { fLastDataColumnHasWeights = b; } 87 89 88 90 // Train Interface
Note:
See TracChangeset
for help on using the changeset viewer.