-
Notifications
You must be signed in to change notification settings - Fork 118
/
eif.hxx
134 lines (105 loc) · 2.66 KB
/
eif.hxx
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <random>
#include <algorithm>
#include <unordered_set>
#define EULER_CONSTANT 0.5772156649
#define RANDOM_ENGINE std::mt19937_64
#define RANDOM_SEED_GENERATOR std::random_device
/****************************
Class Node
****************************/
class Node
{
private:
protected:
public:
int e;
int size;
// double* X; // unused in original code
std::vector<double> normal_vector;
std::vector<double> point;
Node* left;
Node* right;
std::string node_type;
Node (int, int, double*, double*, int, Node*, Node*, std::string);
~Node ();
};
/****************************
Class iTree
****************************/
class iTree
{
private:
int exlevel;
int e;
int size;
// int* Q; // unused in original code
int dim;
int limit;
int exnodes;
// double* point; // in original code, but not necessary
// double* normal_vector; // in original code, but not necessary
// double* X; // unused in original code
protected:
public:
Node* root;
iTree ();
~iTree ();
void build_tree (double*, int, int, int, int, RANDOM_ENGINE&, int);
Node* add_node (double*, int, int, RANDOM_ENGINE&);
};
/*************************
Class Path
*************************/
class Path
{
private:
int dim;
double* x;
double e;
protected:
public:
std::vector<char> path_list;
double pathlength;
Path (int, double*, iTree);
~Path ();
double find_path (Node*);
};
/****************************
Class iForest
****************************/
class iForest
{
private:
int nobjs;
int dim;
int sample;
int ntrees;
int exlevel;
double* X;
double c;
iTree* Trees;
unsigned random_seed;
bool CheckExtensionLevel ();
bool CheckSampleSize ();
protected:
public:
int limit;
iForest (int, int, int, int, int);
~iForest ();
void fit (double*, int, int);
void predict (double*, double*, int);
void predictSingleTree (double*, double*, int, int);
void OutputTreeNodes (int);
};
/********************************
Utility functions
********************************/
inline double inner_product (double*, double*, int);
inline double c_factor (int);
inline std::vector<int> sample_without_replacement (int, int, RANDOM_ENGINE&);
void output_tree_node (Node*, std::string);
void delete_tree_node (Node*);