Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (67 loc) · 2.45 KB
/
Copy pathmain.cpp
File metadata and controls
74 lines (67 loc) · 2.45 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
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
//#include "c:\Eigen\Eigen\Dense"
#include <iostream>
#include "InOut.h"
#include "Sample.h"
#include "FeatureFactory.h"
#include "Node.h"
#include "Forest.h"
int main(int argc, char** argv)
{
// prepare dataset
// instantiate a training object
InOut trnObj;
Eigen::MatrixXf trnData;
Eigen::VectorXi trnLabels;
trnObj.readPoints("./dataset/downsampled.txt", trnData);
trnObj.readLabels("./dataset/downsampled.labels", trnLabels);
// search for the k nearest neighbors for each point in the dataset
// and store the indices and dists in two matrices for later use by
// indexing instead of searching again
Eigen::MatrixXi trnIndices;
Eigen::MatrixXf trnDists;
const int numNeighbors = 11;
trnObj.searchNN(trnData, numNeighbors, trnIndices, trnDists);
//std::cout << "indices\n" << trnIndices << std::endl;
// instantiate a sampling object which is responsible for
// sampling the dataset (bagging) and doing the comparison
// in each node
const int numClasses = 8;
const int numFeatures = 10;
Sample smpObj(trnData, trnLabels, trnIndices, trnDists, numClasses, numFeatures);
// ratio controls the number of samples to be selected from the dataset
// in a sampling object and this sampling is one with replacement
// (bagging process), usually ratio is set as 0.67 (two thirds)
const float ratio = 0.1;
smpObj.randomSampleDataset(ratio);
//std::cout << smpObj.getSelectedSamplesId() << std::endl;
/*Eigen::MatrixXf neighborhood;
int pointId = 0;
neighborhood = smpObj.buildNeighborhood(pointId);
std::cout << "Neighborhood is: \n" << neighborhood << std::endl;
std::vector<Features> features;
smpObj.randomSampleFeatures(neighborhood);
features = smpObj.getSelectedFeatures();
for (auto f : features)
{
std::cout << f._point1 << " " << f._point2 << " " << f._featType;
std::cout << std::endl;
}*/
//std::cout << neighborhood << std::endl;
/*Random rd(100, 2);
std::vector<int> samples = rd.sampleWithouReplacement();
for (auto ele : samples)
std::cout << ele << " ";
std::cout << std::endl;*/
//Eigen::VectorXi samplesId = smpObj.getSelectedSamplesId();
//std::cout << "sample indices: \n" << samplesId;
std::vector<Node*> nodes;
Node* node = new Node();
node->_samples = &smpObj;
/*node->computeNodeGini();
std::cout << "\nGini at this node is: " << node->getNodeGini() << std::endl;*/
node->splitNodeByGini(nodes, 0, 10);
RandomForest rf(10, 10, 10, 0);
rf.train(trnData, trnLabels, trnIndices, trnDists, 8, 10);
system("pause");
return 0;
}