-
Notifications
You must be signed in to change notification settings - Fork 1
/
TreeBuilder.h
59 lines (46 loc) · 1.37 KB
/
TreeBuilder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef _TREE_BUILDER_H_
#define _TREE_BUILDER_H_
#include "BasicDataStructures.h"
#include "Helper.h"
#include <stdio.h>
#include <string.h>
using namespace BasicDataStructures;
using namespace MyHelper;
class TreeBuilder
{
#define MIN_NODE_SIZE 1
#define MIN_NODE_SIZE_TO_SPLIT 2
#define NUM_CHILDREN 2
public:
TreeBuilder();
~TreeBuilder();
void Init(
const vector<NumericAttr>& fv,
const vector<char*>& cv,
const Instance* it,
const unsigned int numInstances );
TreeNode* BuildTree( const unsigned int numFeaToSelect );
void PrintTree( const TreeNode* node, unsigned int h );
void DestroyNode( TreeNode* node );
private:
TreeNode* Split(
MiniInstance* miniInstanceArr,
unsigned int* featureIndexArray,
const unsigned int* parentClassDist,
const unsigned int numInstances,
unsigned int height );
inline double ComputeGini(
const unsigned int* classDistribution,
const unsigned int numInstances );
inline double ComputeEntropy(
const unsigned int* classDistribution,
const unsigned int numInstances );
vector<char*> classVec;
vector<NumericAttr> featureVec;
const Instance* instanceTable;
unsigned int numFeaToTry;
unsigned int numFeaTotal;
unsigned int numInstTotal;
unsigned short numClasses;
};
#endif