-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGStump.cpp
94 lines (76 loc) · 2.13 KB
/
GStump.cpp
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
/*
* GStump.cpp
* TTree
*
* Created by Vincent Botta on 08/04/09.
* Copyright 2009 University of Liège. All rights reserved.
*
*/
#include "GStump.h"
#include "Sampler.h"
GStump::GStump(DB *database) : Learner(database) {
nbtree = 0;
//for (int i = 500 ; i < 1500 ; ++i)
// emptyls.push_back(i);
//Sampler::print(emptyls);
}
GStump::GStump(DB *database, std::vector<unsigned int> *att) : Learner(database) {
setAttCand(att);
}
GStump::~GStump() {
for (int i = 0 ; i < nbtree ; ++i)
delete term[i];
}
void GStump::setAttCand(std::vector<unsigned int> *_cand) {
cand = _cand;
nbtree = (int) _cand->size();
term = new ClassicTree*[nbtree];
}
double GStump::learn() {
clock_t clock_start = clock();
if (ls->size() > 0)
nmin = (int) ls->size();
else
fprintf(stderr,"######### WARNING : NO LS SPECIFIED !!! #########\n");
for (int t = 0 ; t < nbtree ; ++t) {
term[t] = new ClassicTree(db,nmin);
term[t]->setLearnFonction();
term[t]->setLS(ls); // CONSUMMING...
std::vector<unsigned int> a; a.push_back((*cand)[t]);
term[t]->setAttCand(&a);
term[t]->learn();
//term[t]->setLS(emptyls);
//fprintf(stderr, "Tree %03d - Att %03d - Complexity : %03d\n",t+1,a[0],term[t]->getComplexity());
}
return (clock() - clock_start);
}
Result GStump::test() {
//fprintf(stderr,"GStump::test()\n");
return test(ts);
}
Result GStump::test(unsigned int obj) {
std::vector<unsigned int> v;
v.push_back(obj);
return test(&v);
}
void GStump::test(Result &result, unsigned int obj) {
}
Result GStump::test(std::vector<unsigned int> *set) {
//fprintf(stderr,"GStump::test(&set)\n");
Result r(db);
std::vector<Result> vr;
for (int t = 0 ; t < nbtree ; ++t)
vr.push_back(term[t]->test(set));
r.aggregate(vr);
return r;
}
void GStump::computeVimp() { // should be done !
for (int t = 0 ; t < nbtree ; ++t) {
term[t]->computeVimp();
VimpList interm = term[t]->getVimpCompact(false);
for (int i = 0 ; i < interm.size() ; ++i)
vimp[interm.getNum(i)] += interm.getImp(i);
}
}
//void GStump::computeVimp(std::vector<float> &vim) {}
void GStump::computeVimp(std::vector<float> &vim, std::vector<unsigned int> &set) {}