|
10 | 10 | #include <boost/math/distributions/normal.hpp> |
11 | 11 | #include <boost/math/distributions/empirical_cumulative_distribution_function.hpp> |
12 | 12 | #include <limits> |
13 | | - |
| 13 | +#include <fstream> |
14 | 14 | using namespace chimbuko; |
15 | 15 |
|
16 | 16 |
|
17 | | -ADOutlier::AlgoParams::AlgoParams(): sstd_sigma(6.0), hbos_thres(0.99), glob_thres(true), hbos_max_bins(200){} //, func_threshold_file("") |
| 17 | +ADOutlier::AlgoParams::AlgoParams(): algorithm("hbos"), sstd_sigma(6.0), hbos_thres(0.99), glob_thres(true), hbos_max_bins(200){} //, func_threshold_file("") |
| 18 | + |
| 19 | +bool ADOutlier::AlgoParams::operator==(const AlgoParams &r) const{ return algorithm == r.algorithm && sstd_sigma == r.sstd_sigma && hbos_thres == r.hbos_thres && glob_thres == r.glob_thres && hbos_max_bins == r.hbos_max_bins; } |
| 20 | + |
| 21 | +void ADOutlier::AlgoParams::setJson(const nlohmann::json &in){ |
| 22 | +#define JSON_CHECK(to) if(!in.contains(#to)) fatal_error("Expected key " #to); |
| 23 | +#define JSON_GET(to) if(in.contains(#to)) to = in[#to].template get<decltype(to)>() |
| 24 | + //Check for required |
| 25 | + JSON_CHECK(algorithm); |
| 26 | + if(algorithm == "sstd"){ |
| 27 | + JSON_CHECK(sstd_sigma); |
| 28 | + }else if(algorithm == "hbos"){ |
| 29 | + JSON_CHECK(glob_thres); |
| 30 | + JSON_CHECK(hbos_max_bins); |
| 31 | + } |
| 32 | + if(algorithm == "hbos" || algorithm == "copod"){ |
| 33 | + JSON_CHECK(hbos_thres); |
| 34 | + } |
| 35 | + //Get all available |
| 36 | + JSON_GET(algorithm); |
| 37 | + JSON_GET(sstd_sigma); |
| 38 | + JSON_GET(glob_thres); |
| 39 | + JSON_GET(hbos_max_bins); |
| 40 | + JSON_GET(hbos_thres); |
| 41 | +#undef JSON_CHECK |
| 42 | +#undef JSON_GET |
| 43 | + |
| 44 | +} |
| 45 | + |
| 46 | +void ADOutlier::AlgoParams::loadJsonFile(const std::string &filename){ |
| 47 | + std::ifstream f(filename); |
| 48 | + nlohmann::json j; f >> j; |
| 49 | + setJson(j); |
| 50 | +} |
| 51 | + |
| 52 | +nlohmann::json ADOutlier::AlgoParams::getJson() const{ |
| 53 | + nlohmann::json out; |
| 54 | +#define JSON_SET(key) out[#key] = key |
| 55 | + JSON_SET(algorithm); |
| 56 | + JSON_SET(sstd_sigma); |
| 57 | + JSON_SET(hbos_thres); |
| 58 | + JSON_SET(glob_thres); |
| 59 | + JSON_SET(hbos_max_bins); |
| 60 | + return out; |
| 61 | +#undef JSON_SET |
| 62 | +} |
| 63 | + |
18 | 64 |
|
19 | 65 |
|
20 | 66 | /* --------------------------------------------------------------------------- |
@@ -50,22 +96,22 @@ ADOutlier::~ADOutlier() { |
50 | 96 | // } |
51 | 97 |
|
52 | 98 |
|
53 | | -ADOutlier *ADOutlier::set_algorithm(int rank, const std::string & algorithm, const AlgoParams ¶ms) { |
54 | | - if (algorithm == "sstd" || algorithm == "SSTD") { |
| 99 | +ADOutlier *ADOutlier::set_algorithm(int rank, const AlgoParams ¶ms) { |
| 100 | + if (params.algorithm == "sstd" || params.algorithm == "SSTD") { |
55 | 101 | return new ADOutlierSSTD(rank,params.sstd_sigma); |
56 | 102 | } |
57 | | - else if (algorithm == "hbos" || algorithm == "HBOS") { |
| 103 | + else if (params.algorithm == "hbos" || params.algorithm == "HBOS") { |
58 | 104 | ADOutlierHBOS* alg = new ADOutlierHBOS(rank,params.hbos_thres, params.glob_thres, params.hbos_max_bins); |
59 | 105 | //loadPerFunctionThresholds(alg,params.func_threshold_file); |
60 | 106 | return alg; |
61 | 107 | } |
62 | | - else if (algorithm == "copod" || algorithm == "COPOD") { |
| 108 | + else if (params.algorithm == "copod" || params.algorithm == "COPOD") { |
63 | 109 | ADOutlierCOPOD* alg = new ADOutlierCOPOD(rank,params.hbos_thres); |
64 | 110 | //loadPerFunctionThresholds(alg,params.func_threshold_file); |
65 | 111 | return alg; |
66 | 112 | } |
67 | 113 | else{ |
68 | | - fatal_error("Invalid algorithm: " + algorithm); |
| 114 | + fatal_error("Invalid algorithm: " + params.algorithm); |
69 | 115 | } |
70 | 116 | } |
71 | 117 |
|
|
0 commit comments