#include <M5Tree.hh>
Classes | |
struct | tree_experience |
struct | tree_node |
Public Member Functions | |
tree_node * | allocateNode () |
void | buildTree (tree_node *node, const std::vector< tree_experience * > &instances, bool changed) |
float | calcSDforSet (const std::vector< tree_experience * > &instances) |
float | calcSDR (int dim, float val, const std::vector< tree_experience * > &instances, float sd, std::vector< tree_experience * > &left, std::vector< tree_experience * > &right) |
void | compareSplits (float sdr, int dim, float val, const std::vector< tree_experience * > &left, const std::vector< tree_experience * > &right, int *nties, float *bestSDR, int *bestDim, float *bestVal, std::vector< tree_experience * > *bestLeft, std::vector< tree_experience * > *bestRight) |
void | copyTree (tree_node *newNode, tree_node *origNode) |
void | deallocateNode (tree_node *node) |
void | deleteTree (tree_node *node) |
int | fitLinearModel (tree_node *node, const std::vector< tree_experience * > &instances, std::vector< bool > featureMask, int nFeats, float *resSum) |
int | fitSimpleLinearModel (tree_node *node, const std::vector< tree_experience * > &instances, std::vector< bool > featureMask, int nFeats, float *resSum) |
virtual float | getConf (const std::vector< float > &input) |
virtual M5Tree * | getCopy () |
tree_node * | getCorrectChild (tree_node *node, const std::vector< float > &input) |
void | getFeatsUsed (tree_node *node, std::vector< bool > *featsUsed) |
std::set< float > | getUniques (int dim, const std::vector< tree_experience * > &instances, float &minVal, float &maxVal) |
void | implementSplit (tree_node *node, const std::vector< tree_experience * > &instances, float bestSDR, int bestDim, float bestVal, const std::vector< tree_experience * > &left, const std::vector< tree_experience * > &right, bool changed) |
void | initNodes () |
void | initTree () |
void | initTreeNode (tree_node *node) |
void | leafPrediction (tree_node *t, const std::vector< float > &in, std::map< float, float > *retval) |
M5Tree (int id, int trainMode, int trainFreq, int m, float featPct, bool simple, bool allowAllFeats, float min_sdr, Random rng) | |
M5Tree (const M5Tree &) | |
void | makeLeaf (tree_node *node) |
bool | passTest (int dim, float val, const std::vector< float > &input) |
void | printTree (tree_node *t, int level) |
void | pruneTree (tree_node *node, const std::vector< tree_experience * > &instances) |
void | rebuildTree () |
void | removeChildren (tree_node *node) |
float * | sortOnDim (int dim, const std::vector< tree_experience * > &instances) |
virtual void | testInstance (const std::vector< float > &input, std::map< float, float > *retval) |
void | testPossibleSplits (const std::vector< tree_experience * > &instances, float *bestSDR, int *bestDim, float *bestVal, std::vector< tree_experience * > *bestLeft, std::vector< tree_experience * > *bestRight) |
virtual bool | trainInstance (classPair &instance) |
virtual bool | trainInstances (std::vector< classPair > &instances) |
tree_node * | traverseTree (tree_node *node, const std::vector< float > &input) |
~M5Tree () | |
Public Attributes | |
bool | COPYDEBUG |
bool | DTDEBUG |
bool | INCDEBUG |
bool | LMDEBUG |
int | nExperiences |
bool | NODEDEBUG |
float | SPLIT_MARGIN |
bool | SPLITDEBUG |
bool | STOCH_DEBUG |
Private Attributes | |
tree_experience | allExp [N_M5_EXP] |
tree_node | allNodes [N_M5_NODES] |
const bool | ALLOW_ALL_FEATS |
std::vector< tree_experience * > | experiences |
float | featPct |
std::vector< int > | freeNodes |
const int | freq |
bool | hadError |
const int | id |
tree_node * | lastNode |
const int | M |
int | maxnodes |
const float | MIN_SDR |
const int | mode |
int | nfeat |
int | nnodes |
int | nOutput |
Random | rng |
tree_node * | root |
const bool | SIMPLE |
int | totalnodes |
M5Tree::M5Tree | ( | int | id, |
int | trainMode, | ||
int | trainFreq, | ||
int | m, | ||
float | featPct, | ||
bool | simple, | ||
bool | allowAllFeats, | ||
float | min_sdr, | ||
Random | rng | ||
) |
Default constructor
id | id of the tree for debug |
trainMode | build every step? only on errors? every freq steps? |
trainFreq | frequency of model building if using latter mode |
m | # of visits for a given state-action to be considered known |
featPct | pct of features to remove from set used for each tree split |
simple | do simple linear regression (predict from one variable) rather than full multivariate linear regression |
allowAllFeats | all linear regression to use all features, regardless of if they were in the subtree being replaced |
min_sdr | Minimum standard deviation reduction for a split to be implemented. |
rng | Random Number Generator |
true;
M5Tree::M5Tree | ( | const M5Tree & | m5 | ) |
M5Tree::~M5Tree | ( | ) |
void M5Tree::buildTree | ( | tree_node * | node, |
const std::vector< tree_experience * > & | instances, | ||
bool | changed | ||
) |
float M5Tree::calcSDforSet | ( | const std::vector< tree_experience * > & | instances | ) |
float M5Tree::calcSDR | ( | int | dim, |
float | val, | ||
const std::vector< tree_experience * > & | instances, | ||
float | sd, | ||
std::vector< tree_experience * > & | left, | ||
std::vector< tree_experience * > & | right | ||
) |
void M5Tree::compareSplits | ( | float | sdr, |
int | dim, | ||
float | val, | ||
const std::vector< tree_experience * > & | left, | ||
const std::vector< tree_experience * > & | right, | ||
int * | nties, | ||
float * | bestSDR, | ||
int * | bestDim, | ||
float * | bestVal, | ||
std::vector< tree_experience * > * | bestLeft, | ||
std::vector< tree_experience * > * | bestRight | ||
) |
void M5Tree::copyTree | ( | tree_node * | newNode, |
tree_node * | origNode | ||
) |
void M5Tree::deallocateNode | ( | tree_node * | node | ) |
void M5Tree::deleteTree | ( | tree_node * | node | ) |
int M5Tree::fitLinearModel | ( | tree_node * | node, |
const std::vector< tree_experience * > & | instances, | ||
std::vector< bool > | featureMask, | ||
int | nFeats, | ||
float * | resSum | ||
) |
int M5Tree::fitSimpleLinearModel | ( | tree_node * | node, |
const std::vector< tree_experience * > & | instances, | ||
std::vector< bool > | featureMask, | ||
int | nFeats, | ||
float * | resSum | ||
) |
float M5Tree::getConf | ( | const std::vector< float > & | input | ) | [virtual] |
Implements Classifier.
M5Tree * M5Tree::getCopy | ( | ) | [virtual] |
Implements Classifier.
M5Tree::tree_node * M5Tree::getCorrectChild | ( | tree_node * | node, |
const std::vector< float > & | input | ||
) |
void M5Tree::getFeatsUsed | ( | tree_node * | node, |
std::vector< bool > * | featsUsed | ||
) |
std::set< float > M5Tree::getUniques | ( | int | dim, |
const std::vector< tree_experience * > & | instances, | ||
float & | minVal, | ||
float & | maxVal | ||
) |
void M5Tree::implementSplit | ( | tree_node * | node, |
const std::vector< tree_experience * > & | instances, | ||
float | bestSDR, | ||
int | bestDim, | ||
float | bestVal, | ||
const std::vector< tree_experience * > & | left, | ||
const std::vector< tree_experience * > & | right, | ||
bool | changed | ||
) |
void M5Tree::initNodes | ( | ) |
void M5Tree::initTree | ( | ) |
void M5Tree::initTreeNode | ( | tree_node * | node | ) |
void M5Tree::leafPrediction | ( | tree_node * | t, |
const std::vector< float > & | in, | ||
std::map< float, float > * | retval | ||
) |
void M5Tree::makeLeaf | ( | tree_node * | node | ) |
bool M5Tree::passTest | ( | int | dim, |
float | val, | ||
const std::vector< float > & | input | ||
) |
void M5Tree::printTree | ( | tree_node * | t, |
int | level | ||
) |
void M5Tree::pruneTree | ( | tree_node * | node, |
const std::vector< tree_experience * > & | instances | ||
) |
void M5Tree::rebuildTree | ( | ) |
void M5Tree::removeChildren | ( | tree_node * | node | ) |
float * M5Tree::sortOnDim | ( | int | dim, |
const std::vector< tree_experience * > & | instances | ||
) |
void M5Tree::testInstance | ( | const std::vector< float > & | input, |
std::map< float, float > * | retval | ||
) | [virtual] |
Implements Classifier.
void M5Tree::testPossibleSplits | ( | const std::vector< tree_experience * > & | instances, |
float * | bestSDR, | ||
int * | bestDim, | ||
float * | bestVal, | ||
std::vector< tree_experience * > * | bestLeft, | ||
std::vector< tree_experience * > * | bestRight | ||
) |
bool M5Tree::trainInstance | ( | classPair & | instance | ) | [virtual] |
Implements Classifier.
bool M5Tree::trainInstances | ( | std::vector< classPair > & | instances | ) | [virtual] |
Implements Classifier.
M5Tree::tree_node * M5Tree::traverseTree | ( | tree_node * | node, |
const std::vector< float > & | input | ||
) |
tree_experience M5Tree::allExp[N_M5_EXP] [private] |
tree_node M5Tree::allNodes[N_M5_NODES] [private] |
const bool M5Tree::ALLOW_ALL_FEATS [private] |
std::vector<tree_experience*> M5Tree::experiences [private] |
float M5Tree::featPct [private] |
std::vector<int> M5Tree::freeNodes [private] |
const int M5Tree::freq [private] |
bool M5Tree::hadError [private] |
const int M5Tree::id [private] |
tree_node* M5Tree::lastNode [private] |
int M5Tree::maxnodes [private] |
const float M5Tree::MIN_SDR [private] |
const int M5Tree::mode [private] |
int M5Tree::nfeat [private] |
int M5Tree::nnodes [private] |
int M5Tree::nOutput [private] |
Random M5Tree::rng [private] |
tree_node* M5Tree::root [private] |
const bool M5Tree::SIMPLE [private] |
float M5Tree::SPLIT_MARGIN |
int M5Tree::totalnodes [private] |