jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
lof.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2012 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 #ifndef JUBATUS_CORE_ANOMALY_LOF_HPP_
18 #define JUBATUS_CORE_ANOMALY_LOF_HPP_
19 
20 #include <string>
21 #include <vector>
22 #include "jubatus/util/lang/shared_ptr.h"
23 #include "../recommender/recommender_base.hpp"
24 #include "anomaly_base.hpp"
25 #include "lof_storage.hpp"
26 
27 namespace jubatus {
28 namespace core {
29 namespace anomaly {
30 
31 class lof : public anomaly_base {
32  public:
33  explicit lof(
34  const lof_storage::config& config,
35  jubatus::util::lang::shared_ptr<core::recommender::recommender_base>
36  nn_engine);
37  ~lof();
38 
39  // return anomaly score of query
40  float calc_anomaly_score(const common::sfv_t& query) const;
41  float calc_anomaly_score(const std::string& id) const;
42 
43  void clear();
44  void clear_row(const std::string& id);
45  void update_row(const std::string& id, const sfv_diff_t& diff);
46  void set_row(const std::string& id, const common::sfv_t& sfv);
47 
48  void get_all_row_ids(std::vector<std::string>& ids) const;
49  std::string type() const;
50  std::vector<framework::mixable*> get_mixables() const;
51 
52  void pack(framework::packer& packer) const;
53  void unpack(msgpack::object o);
54 
55  bool is_updatable() const {
56  return true;
57  }
58 
59  private:
60  jubatus::util::lang::shared_ptr<mixable_lof_storage> mixable_storage_;
61  jubatus::util::lang::shared_ptr<recommender::recommender_base> nn_engine_;
62 };
63 
64 } // namespace anomaly
65 } // core
66 } // namespace jubatus
67 
68 #endif // JUBATUS_CORE_ANOMALY_LOF_HPP_
float calc_anomaly_score(const common::sfv_t &query) const
Definition: lof.cpp:93
void clear_row(const std::string &id)
Definition: lof.cpp:112
std::vector< framework::mixable * > get_mixables() const
Definition: lof.cpp:132
bool is_updatable() const
Definition: lof.hpp:55
void set_row(const std::string &id, const common::sfv_t &sfv)
Definition: lof.cpp:120
void get_all_row_ids(std::vector< std::string > &ids) const
Definition: lof.cpp:124
void update_row(const std::string &id, const sfv_diff_t &diff)
Definition: lof.cpp:116
common::sfv_t sfv_diff_t
jubatus::util::lang::shared_ptr< recommender::recommender_base > nn_engine_
Definition: lof.hpp:61
void unpack(msgpack::object o)
Definition: lof.cpp:145
msgpack::packer< jubatus_packer > packer
Definition: bandit_base.hpp:31
void pack(framework::packer &packer) const
Definition: lof.cpp:139
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
lof(const lof_storage::config &config, jubatus::util::lang::shared_ptr< core::recommender::recommender_base > nn_engine)
Definition: lof.cpp:68
jubatus::util::lang::shared_ptr< mixable_lof_storage > mixable_storage_
Definition: lof.hpp:60
std::string type() const
Definition: lof.cpp:128