| 23 | using namespace std::chrono; |
| 24 | |
| 25 | int main(int argc, char* argv[]) { |
| 26 | // Parameter |
| 27 | // -------------------------------------------------------------------------------- |
| 28 | |
| 29 | const auto pathMeta = SOLUTION_DIR"data/DARPA/darpa_shape.txt"; |
| 30 | const auto pathData = SOLUTION_DIR"data/DARPA/darpa_processed.csv"; |
| 31 | const auto pathGroundTruth = SOLUTION_DIR"data/DARPA/darpa_ground_truth.csv"; |
| 32 | |
| 33 | // Random seed |
| 34 | // -------------------------------------------------------------------------------- |
| 35 | |
| 36 | const unsigned seed = time(nullptr); |
| 37 | printf("Seed = %u\t// In case of reproduction\n", seed); |
| 38 | srand(seed); // Many rand(), need to init |
| 39 | |
| 40 | // Read meta (total number of records) |
| 41 | // -------------------------------------------------------------------------------- |
| 42 | // PreprocessData.py will generate those meta files |
| 43 | |
| 44 | const auto fileMeta = fopen(pathMeta, "r"); |
| 45 | int n; |
| 46 | fscanf(fileMeta, "%d", &n); |
| 47 | fclose(fileMeta); |
| 48 | |
| 49 | // Read dataset |
| 50 | // -------------------------------------------------------------------------------- |
| 51 | |
| 52 | const auto fileData = fopen(pathData, "r"); |
| 53 | const auto source = new int[n]; |
| 54 | const auto destination = new int[n]; |
| 55 | const auto timestamp = new int[n]; |
| 56 | for (int i = 0; i < n; i++) |
| 57 | fscanf(fileData, "%d,%d,%d", &source[i], &destination[i], ×tamp[i]); |
| 58 | fclose(fileData); |
| 59 | printf("# Records = %d\t// Dataset is loaded\n", n); |
| 60 | |
| 61 | // Do the magic |
| 62 | // -------------------------------------------------------------------------------- |
| 63 | // Of course, I can merge loading and processing together, but this demo is also for benchmarking. |
| 64 | |
| 65 | // MIDAS::NormalCore midas(2, 1024); |
| 66 | // MIDAS::RelationalCore midas(2, 1024); |
| 67 | MIDAS::FilteringCore midas(2, 1024, 1e3f); |
| 68 | const auto score = new float[n]; |
| 69 | const auto time = high_resolution_clock::now(); |
| 70 | for (int i = 0; i < n; i++) |
| 71 | score[i] = midas(source[i], destination[i], timestamp[i]); |
| 72 | printf("Time = %lldms\t// Algorithm is finished\n", duration_cast<milliseconds>(high_resolution_clock::now() - time).count()); |
| 73 | |
| 74 | // Write output scores |
| 75 | // -------------------------------------------------------------------------------- |
| 76 | |
| 77 | const auto pathScore = SOLUTION_DIR"temp/Score.txt"; |
| 78 | const auto fileScore = fopen(pathScore, "w"); |
| 79 | for (int i = 0; i < n; i++) |
| 80 | fprintf(fileScore, "%f\n", score[i]); |
| 81 | fclose(fileScore); |
| 82 | printf("// Raw anomaly scores are exported to\n// " SOLUTION_DIR"temp/Score.txt\n"); |
nothing calls this directly
no outgoing calls
no test coverage detected