Created
September 14, 2015 02:16
-
-
Save TkrUdagawa/c1bbe85f4b44450dc6e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <utility> | |
#include <vector> | |
#include <iostream> | |
#include <sstream> | |
#include <jubatus/core/anomaly/light_lof.hpp> | |
#include <jubatus/util/lang/shared_ptr.h> | |
#include <jubatus/core/nearest_neighbor/euclid_lsh.hpp> | |
#include <jubatus/core/storage/column_table.hpp> | |
#include <jubatus/core/driver/anomaly.hpp> | |
#include <jubatus/core/fv_converter/datum_to_fv_converter.hpp> | |
#include <jubatus/core/fv_converter/datum.hpp> | |
#include <jubatus/core/fv_converter/converter_config.hpp> | |
using jubatus::util::lang::shared_ptr; | |
const bool ignore_kth = false; | |
int main(int argc, char* argv[]){ | |
jubatus::core::anomaly::light_lof::config conf; | |
conf.nearest_neighbor_num = 20; | |
conf.reverse_nearest_neighbor_num = 30; | |
conf.ignore_kth_same_point = ignore_kth; | |
jubatus::core::nearest_neighbor::euclid_lsh::config nn_config; | |
nn_config.hash_num = 256; | |
shared_ptr<jubatus::core::storage::column_table> table(new jubatus::core::storage::column_table); | |
shared_ptr<jubatus::core::nearest_neighbor::nearest_neighbor_base> nn_engine(new jubatus::core::nearest_neighbor::euclid_lsh(nn_config, table, "nn")); | |
shared_ptr<jubatus::core::anomaly::anomaly_base> light_lof_(new jubatus::core::anomaly::light_lof(conf, "lof", nn_engine)); | |
shared_ptr<jubatus::core::fv_converter::datum_to_fv_converter> converter_(new jubatus::core::fv_converter::datum_to_fv_converter); | |
jubatus::core::fv_converter::string_rule str_rule; | |
str_rule.key = "*"; | |
str_rule.type = "str"; | |
str_rule.sample_weight = "bin"; | |
str_rule.global_weight = "bin"; | |
jubatus::core::fv_converter::num_rule num_rule; | |
num_rule.key = "*"; | |
num_rule.type = "num"; | |
jubatus::core::fv_converter::converter_config c; | |
c.string_rules = std::vector<jubatus::core::fv_converter::string_rule>(); | |
c.string_rules->push_back(str_rule); | |
c.num_rules = std::vector<jubatus::core::fv_converter::num_rule>(); | |
c.num_rules->push_back(num_rule); | |
jubatus::core::fv_converter::initialize_converter(c, *converter_); | |
shared_ptr<jubatus::core::driver::anomaly> anomaly_(new jubatus::core::driver::anomaly(light_lof_, converter_)); | |
int i; | |
jubatus::core::fv_converter::datum d; | |
std::pair<std::string, float> score; | |
for(i = 0; i < 100; i++){ | |
d.num_values_.push_back(std::make_pair("x", (float) 1.0)); | |
d.num_values_.push_back(std::make_pair("y", (float) 1.5)); | |
d.num_values_.push_back(std::make_pair("z", (float) 2.0)); | |
std::stringstream int_string; | |
int_string << "id" << i; | |
std::string point_id(int_string.str()); | |
score = anomaly_->add(point_id, d); | |
std::cout << score.first << "score " << score.second << std::endl; | |
d.num_values_.clear(); | |
} | |
for(i = 0; i < 5; i++){ | |
d.num_values_.push_back(std::make_pair("x", (float) 0.1)); | |
d.num_values_.push_back(std::make_pair("y", (float) 0.1)); | |
d.num_values_.push_back(std::make_pair("z", (float) 0.1)); | |
std::stringstream int_string; | |
int_string << "id_anom" << i; | |
std::string point_id(int_string.str()); | |
score = anomaly_->add(point_id, d); | |
std::cout << score.first << "score " << score.second << std::endl; | |
d.num_values_.clear(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment