-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
108 lines (93 loc) · 2.84 KB
/
main.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Authors: Elena Hosseinmardi: ehoss003
Arrdya Srivastav: asriv033
Anthony Padilla: apadi089
Luis Magallanes Banuelos: lmaga024
// */
#include "src/Classifier.h"
#include "src/Search.h"
#include "src/Validator.h"
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main(int argc, char **argv)
{
if (argc < 3){
cout << "Usage: ./executable filepath algoChoiceNum" << endl;
return 1;
}
Search search;
string dataLoc = argv[1];
int numFeatures = 0;
int userChoice = stoi(argv[2]);
unordered_map<int, bool> subset;
cout << " Welcome to JAKLE's Feature Selection Algorithm\n" << endl;
cout << "Using a random evalation, with no features, I get an accuracy of " << static_cast<double>(rand()) / RAND_MAX << endl;
// go through file and get the number of features
ifstream inputFile(dataLoc);
if (!inputFile.is_open())
{
std::cerr << "Failed to open data file." << std::endl;
return 1;
}
string mystring;
getline(inputFile, mystring);
istringstream ss(mystring);
double value;
while (ss >> value)
{
numFeatures++;
}
numFeatures-=1;
cout << "Number of features: " << numFeatures << endl;
inputFile.close();
//start reading time
clock_t start = clock();
switch (userChoice)
{
case 1:
subset = search.greedyForward(numFeatures, dataLoc);
cout << " Search Finished ! The best feature subset was {";
for (auto it = subset.begin(); it != subset.end(); ++it)
{
cout << it->first + 1 << " ";
}
if (subset.size() == 0)
{
cout << "No features selected." << endl;
}
cout << "} with an accuracy of " << search.bestAccuracy * 100 << "%";
break;
case 2:
subset = search.greedyBackward(numFeatures, dataLoc);
cout << " Search Finished ! The best feature subset was {";
for (auto it = subset.begin(); it != subset.end(); ++it)
{
cout << it->first + 1 << " ";
}
if (subset.size() == 0)
{
cout << "No features selected.";
}
cout << "} with an accuracy of " << search.bestAccuracy * 100 << "%";
break;
case 3:
cout << "UHH under construction can we have data tho pls ;)\n";
break;
}
//end time
clock_t end = clock();
double elapsed_time = double(end - start) / CLOCKS_PER_SEC;
cout << endl << "Elapsed time: " << elapsed_time << " seconds" << endl;
cout << endl;
return 0;
}
// int main(){
// Validator validator;
// vector<int> featureSubset;
// string dataLoc = "data/large14.txt";
// featureSubset.push_back(13);
// featureSubset.push_back(32);
// cout << validator.validate(featureSubset, dataLoc);
// }