-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathForest.hpp
81 lines (75 loc) · 2.86 KB
/
Forest.hpp
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
/*
* Forest.h
*
* Created on: Aug 12, 2015
* Author: tadeze
*/
#ifndef FOREST_H_
#define FOREST_H_
#include "utility.hpp"
#include "Tree.hpp"
#include "cincl.hpp"
class Forest {
public:
std::vector<Tree*> trees;
int ntree;bool rsample;
int nsample;
int maxheight;
Forest() {
rsample = false;
maxheight = 0;
ntree = 0;
nsample = 256;
}
Forest(int _ntree, int _nsample, int _maxheight,
bool _rsample) {
ntree = _ntree;
nsample = _nsample;
maxheight = _maxheight;
rsample = _rsample;
}
virtual ~Forest() {
for (std::vector<Tree*>::iterator it = trees.begin(); it != trees.end();
++it) {
delete (*it);
}
}
std::vector<double> getScore(doubleframe *df, int type);
void writeScoreDatabase(doubleframe *dtTestNorm, doubleframe *dtTestAnom, char fName[]);
void writeScores(doubleframe *dt, char fNamesuf[]);
std::vector<int> getSeqMarExplanation(const double *inst, int dim, bool **exclude, int k = 0);
std::vector<int> getSeqDropExplanation(const double *inst, int dim, bool **exclude, int k = 0);
std::vector<int> getRevSeqMarExplanation(const double *inst, int dim, bool **exclude);
std::vector<int> getRevSeqDropExplanation(const double *inst, int dim, bool **exclude);
virtual double instanceMarginalScore(const double *inst, bool **marginalize);
virtual double instanceScore(double *inst);
std::vector<double> AnomalyScore(const doubleframe* df, bool **marginalize);
std::vector<double> AnomalyScore(doubleframe* df);
double getL2Norm2(double *inst);
double getL1NormofWeights();
void getCurrentWeights(std::vector<double> &w);
void reinitializeWeights();
virtual std::vector<double> pathLength(double *inst);
std::vector<std::vector<double> > pathLength(doubleframe* data);
std::vector<double> ADtest(
const std::vector<std::vector<double> > &pathlength,
bool weighttotail);
std::vector<double> importance(double *inst);
double getdepth(double *inst, Tree* tree);
void getSample(std::vector<int> &sampleIndex, int nsample,
bool rSample, int nrow, int *rndIdx);
void printStat(std::ofstream &out);
void printPatternFreq(const doubleframe *df, int n, std::ofstream &out);
void updateWeightsLLH(std::vector<double> &scores, double *inst, int direction, double lrate,
double reg = 0, int regType = 1);
void updateWeights(std::vector<double> &scores, double *inst, int direction, int type, double change = 1,
double reg = 0, int regType = 1);
void updateWeightsRunAvg(std::vector<double> &scores, double *inst, int direction);
void updateWeightsPassAggr(std::vector<double> &scores, double *inst, int direction, double change, bool reg);
void indexInstancesIntoNodes(const doubleframe* df);
void computeMass(std::vector<double> &probScores);
std::vector<double> anomalyScoreFromWeights(doubleframe* df);
void weightIndexedScore(std::vector<double> &scores);
double instanceScoreFromWeights(double *inst);
};
#endif /* FOREST_H_ */