24 #include "jubatus/util/lang/cast.h"
25 #include "jubatus/util/math/random.h"
27 #include "../common/hash.hpp"
28 #include "../storage/lsh_util.hpp"
29 #include "../storage/lsh_vector.hpp"
32 using jubatus::util::data::unordered_map;
33 using jubatus::util::math::random::mtrand;
36 using std::numeric_limits;
48 const unordered_map<string, float>& neighbor_lrd) {
49 if (neighbor_lrd.empty()) {
50 return lrd == 0 ? 1 : numeric_limits<float>::infinity();
53 float sum_neighbor_lrd = 0;
54 for (unordered_map<string, float>::const_iterator it = neighbor_lrd.begin();
55 it != neighbor_lrd.end(); ++it) {
56 sum_neighbor_lrd += it->second;
59 if (std::isinf(sum_neighbor_lrd) && std::isinf(lrd)) {
63 return sum_neighbor_lrd / (neighbor_lrd.size() * lrd);
70 jubatus::util::lang::shared_ptr<recommender::recommender_base> nn_engine)
72 nn_engine_(nn_engine) {
83 "nearest_neighbor_num <= reverse_nearest_neighbor_num"));
94 unordered_map<string, float> neighbor_lrd;
97 return calculate_lof(lrd, neighbor_lrd);
101 unordered_map<string, float> neighbor_lrd;
105 return calculate_lof(lrd, neighbor_lrd);
133 std::vector<framework::mixable*> mixables;
135 mixables.push_back(
nn_engine_->get_mixable());
140 packer.pack_array(2);
146 if (o.type != msgpack::type::ARRAY || o.via.array.size != 2) {
147 throw msgpack::type_error();
float calc_anomaly_score(const common::sfv_t &query) const
void clear_row(const std::string &id)
std::vector< framework::mixable * > get_mixables() const
void set_row(const std::string &id, const common::sfv_t &sfv)
void get_all_row_ids(std::vector< std::string > &ids) const
jubatus::util::lang::shared_ptr< Model > model_ptr
void update_row(const std::string &id, const sfv_diff_t &diff)
#define JUBATUS_EXCEPTION(e)
int reverse_nearest_neighbor_num
jubatus::util::lang::shared_ptr< recommender::recommender_base > nn_engine_
void unpack(msgpack::object o)
msgpack::packer< jubatus_packer > packer
framework::linear_mixable_helper< lof_storage, lof_table_t > mixable_lof_storage
void pack(framework::packer &packer) const
std::vector< std::pair< std::string, float > > sfv_t
lof(const lof_storage::config &config, jubatus::util::lang::shared_ptr< core::recommender::recommender_base > nn_engine)
jubatus::util::lang::shared_ptr< mixable_lof_storage > mixable_storage_