-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStatisticsNode.cpp
More file actions
72 lines (59 loc) · 2.33 KB
/
StatisticsNode.cpp
File metadata and controls
72 lines (59 loc) · 2.33 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
#include "StatisticsNode.hpp"
StatisticsNode::StatisticsNode(std::string name) : Node(name){}
void StatisticsNode::run() {
arma::mat data = InputDataTable()->DataMatrix();
std::vector<std::string> columns = InputDataTable()->ColumnNames();
std::map<std::string, std::set<std::string>> mapOfCategories = InputDataTable()->CategoricalValues();
unsigned long k = 0;
std::string result = "";
for (unsigned long j = 0; j < columns.size(); j++){
//Putting a column name in the reulting string
result += "Column name: ";
result += columns[j];
result += "\n";
if (mapOfCategories.find(columns[j]) == mapOfCategories.end()){
double minimum_value = data(0, k);
double maximum_value = data(0, k);
double mean_value = 0;
//Finding min, max and mean for the values in that column
for(unsigned long i = 0; i < data.n_rows; i++) {
if (minimum_value > data(i, k)){
minimum_value = data(i, k);
} else if (maximum_value < data(i, k)){
maximum_value = data(i, k);
}
mean_value += data(i, k);
}
mean_value /= data.n_rows;
//Finding variance for the values in that column
double variance_value = 0;
for(unsigned long i = 0; i < data.n_rows; i++) {
variance_value += (data(i, k) - mean_value)*(data(i, k) - mean_value);
}
variance_value /= data.n_rows;
//Puting all those values in the resulting string
result += "Min: ";
result += std::to_string(minimum_value);
result += " Max: ";
result += std::to_string(maximum_value);
result += " Mean: ";
result += std::to_string(mean_value);
result += " Var: ";
result += std::to_string(variance_value);
result += "\n";
k++;
} else {
//TODO
k += mapOfCategories[columns[j]].size();
}
}
//Setting output message and outputDataTable
statistics = result;
setOutputMessage(result);
DataTable dt = *InputDataTable();
this->setOutDataTable(dt);
}
//Getter
std::string StatisticsNode::GetStatistics() const{
return statistics;
}