-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomForest.c
More file actions
40 lines (34 loc) · 1.2 KB
/
RandomForest.c
File metadata and controls
40 lines (34 loc) · 1.2 KB
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
#include "RandomForest.h"
struct RandomForest{
RandomTree *trees;
int size;
};
// D contains the time series from the datasets and the corresponding class labels
RandomForest createRandomForest(TimeSerieArray D, int t, int l, int u, int r){
RandomForest random_forest = malloc(sizeof(*random_forest));
random_forest->size = 0;
random_forest->trees = malloc(sizeof(RandomTree) * t);
srand(time(NULL)); //needed in sampleTimeSerie
while(random_forest->size < t){
int dataset_size = getTimeSerieArraySize(D);
TimeSerieArray time_serie_samples = sampleTimeSerie(D, dataset_size); //contains samples and associated class labels
RandomTree random_tree = createRandomTree(time_serie_samples, l, u, r);
// addTree(random_forest, random_tree);
random_forest->size++;
}
return random_forest;
}
TimeSerieArray sampleTimeSerie(TimeSerieArray D, int size){
TimeSerieArray samples = createTimeSerieArray(size);
int random_index;
int i;
for(i=0; i<size; i++){
random_index = randomUniformIndex(0, size);
TimeSerie selected = getTimeSerie(D, random_index);
addTimeSerie(samples, selected);
}
return samples;
}
void addTree(RandomForest forest, RandomTree tree){
forest->trees[forest->size++] = tree;
}