Created
March 26, 2019 23:47
-
-
Save Roffild/08e289db362b3349858169c849c1918c to your computer and use it in GitHub Desktop.
Modification of a random forest with predictive significance calculations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CDForestUtils : public CDForest | |
{ | |
protected: | |
static void DFProcessInternal(CDecisionForest &df,const int offs, | |
double &x[],double &y[],ulong &stats[]) | |
{ | |
//--- create variables | |
int k=0; | |
int idx=0; | |
//--- Set pointer to the root | |
k=offs+1; | |
//--- Navigate through the tree | |
while(true) | |
{ | |
//--- check | |
if(df.m_trees[k]==-1.0) | |
{ | |
//--- check | |
if(df.m_nclasses==1) | |
y[0]=y[0]+df.m_trees[k+1]; | |
else | |
{ | |
idx=(int)MathRound(df.m_trees[k+1]); | |
y[idx]=y[idx]+1; | |
} | |
//--- break the cycle | |
break; | |
} | |
//--- check | |
idx=(int)MathRound(df.m_trees[k]); | |
stats[idx]++; | |
if(x[idx]<df.m_trees[k+1]) | |
k=k+m_innernodewidth; | |
else | |
k=offs+(int)MathRound(df.m_trees[k+2]); | |
} | |
} | |
public: | |
static void DFProcess(CDecisionForest &df,double &x[],double &y[],ulong &stats[]) | |
{ | |
//--- create variables | |
int offs=0; | |
int i=0; | |
double v=0; | |
int i_=0; | |
//--- Proceed | |
if(CAp::Len(y)<df.m_nclasses) | |
ArrayResizeAL(y,df.m_nclasses); | |
//--- initialization | |
offs=0; | |
for(i=0;i<=df.m_nclasses-1;i++) | |
y[i]=0; | |
for(i=0;i<=df.m_ntrees-1;i++) | |
{ | |
//--- Process basic tree | |
DFProcessInternal(df,offs,x,y,stats); | |
//--- Next tree | |
offs=offs+(int)MathRound(df.m_trees[offs]); | |
} | |
//--- calculation | |
v=1.0/(double)df.m_ntrees; | |
for(i_=0;i_<=df.m_nclasses-1;i_++) | |
y[i_]=v*y[i_]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment