-
Notifications
You must be signed in to change notification settings - Fork 1
/
manhattan.cpp
73 lines (59 loc) · 2.36 KB
/
manhattan.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
#include <iostream>
#include <chrono>
#include <utility>
#include "./include/interfaces/mh_interface.hpp"
#include "./include/BruteForce/BruteForce.hpp"
#include "./include/utils/manhattan.hpp"
int main(int argc, char const *argv[]) {
/* define useful variables */
int success = 0;
interface::ExitCode status;
interface::Dataset<uint8_t> dataset;
interface::Dataset<uint8_t> queryset;
interface::Labelset<uint8_t> dataset_labels;
interface::Labelset<uint8_t> queryset_labels;
interface::IOFilesMH files;
/* parse input */
success = interface::input::MH::MHParseInput(argc, argv, files, status);
/* check for potential errors or violations */
if (success != 1) {
interface::output::PrintErrorMessageAndExit(status);
}
/* parse dataset */
success = interface::ParseDataset(files.input_file, dataset, status);
if (success != 1) {
interface::output::PrintErrorMessageAndExit(status);
}
interface::Data<uint8_t> data(dataset);
/* parse queryset */
success = interface::ParseDataset(files.query_file, queryset, status);
if (success != 1) {
interface::output::PrintErrorMessageAndExit(status);
}
interface::Data<uint8_t> queries(queryset);
/* parse dataset labels */
success = interface::ParseLabelset(files.input_labels_file, dataset_labels, status);
if (success != 1) {
interface::output::PrintErrorMessageAndExit(status);
}
/* parse queryset labels */
success = interface::ParseLabelset(files.query_labels_file, queryset_labels, status);
if (success != 1) {
interface::output::PrintErrorMessageAndExit(status);
}
// Initialize Brute Force for the dataset
BruteForce<uint8_t> bf = BruteForce<uint8_t>(data);
// for each query, get its k Nearest Neighbors
std::vector<std::vector<std::pair<int, Item<uint8_t>*>>> mneighbors = bf.getNeighbors(queryset, 10, 1);
// evaluate the results based on the labels of the neighbors
double mh_avg = utils::evaluate(mneighbors, dataset_labels, queryset_labels, 10);
// print/write the results
std::cout << "Average Correct Search Results Manhattan: " << mh_avg << '\n';
interface::output::MH::writeOutput(files.output_file, mh_avg, status);
/* free the datasets and return, as we have finished */
interface::freeDataset(dataset);
interface::freeDataset(queryset);
interface::freeLabelset(dataset_labels);
interface::freeLabelset(queryset_labels);
return 0;
}