-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPartitionNode.cpp
More file actions
46 lines (37 loc) · 1.38 KB
/
PartitionNode.cpp
File metadata and controls
46 lines (37 loc) · 1.38 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
#include "PartitionNode.hpp"
//Constructor
PartitionNode::PartitionNode(std::string name):Node(name){
testSizeRatio = 0.3;
}
//Getter
double PartitionNode::TestSizeRatio() const{
return testSizeRatio;
}
//Setter
void PartitionNode::SetTestSizeRatio(const double &size){
testSizeRatio = size;
}
void PartitionNode::run(){
//Making a vector that contains field for every tuple, indicating whether the tuple belongs to the train or to the test set
unsigned long rowSize = InputDataTable()->DataMatrix().n_rows;
std::vector<bool> partition(rowSize);
//Finding size of test set
unsigned long testSize = static_cast<unsigned long>(static_cast<double>(rowSize)*testSizeRatio);
//int trainingSize = rowSize - testSize;
//Inserting adequate number of true/false values (true is for test)
for(unsigned long i = 0; i < testSize; i++){
partition[i] = true;
}
for(unsigned long long i = testSize; i < rowSize; i++){
partition[i] = false;
}
//Shuffling the vector in order to get random sets
srand(time(0));
std::random_shuffle(partition.begin(), partition.end());
DataTable dt = *InputDataTable();
//Seting outputDataTable with new data for partition
this->setOutDataTable(dt);
outputDataTable.SetIsPartitioned(true);
outputDataTable.SetPartition(partition);
outputDataTable.SetTestSize(testSize);
}