jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
nearest_neighbor_recommender.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2013 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_RECOMMENDER_NEAREST_NEIGHBOR_RECOMMENDER_HPP_
18 #define JUBATUS_CORE_RECOMMENDER_NEAREST_NEIGHBOR_RECOMMENDER_HPP_
19 
20 #include <string>
21 #include <utility>
22 #include <vector>
23 #include "jubatus/util/lang/shared_ptr.h"
24 #include "recommender_base.hpp"
25 
26 namespace jubatus {
27 namespace core {
28 namespace storage {
29 class column_table;
30 } // namespace storage
31 namespace nearest_neighbor {
32 class nearest_neighbor_base;
33 } // namespace nearest_neighbor
34 namespace unlearner {
35 class unlearner_base;
36 } // unlearner
37 namespace recommender {
38 
39 // Recommender based on nearest_neighbor algorithms.
41  public:
43  jubatus::util::lang::shared_ptr<nearest_neighbor::nearest_neighbor_base>
44  nearest_neighbor_engine);
45 
47  jubatus::util::lang::shared_ptr<nearest_neighbor::nearest_neighbor_base>
48  nearest_neighbor_engine,
49  jubatus::util::lang::shared_ptr<unlearner::unlearner_base> unlearner);
50 
51  void similar_row(
52  const common::sfv_t& query,
53  std::vector<std::pair<std::string, float> >& ids,
54  size_t ret_num) const;
55  void neighbor_row(
56  const common::sfv_t& query,
57  std::vector<std::pair<std::string, float> >& ids,
58  size_t ret_num) const;
59  void clear();
60  void clear_row(const std::string& id);
61  void update_row(const std::string& id, const sfv_diff_t& diff);
62  void get_all_row_ids(std::vector<std::string>& ids) const;
63 
64  std::string type() const;
65 
67 
68  void pack(framework::packer& packer) const;
69  void unpack(msgpack::object o);
70 
71  private:
72  void unlearn_row(const std::string& id);
73  jubatus::util::lang::shared_ptr<storage::column_table> get_table();
74  jubatus::util::lang::shared_ptr<const storage::column_table>
75  get_const_table() const;
76 
77  jubatus::util::lang::shared_ptr<unlearner::unlearner_base> get_unlearner();
78 
79  private:
81 
82  jubatus::util::lang::shared_ptr<nearest_neighbor::nearest_neighbor_base>
84  jubatus::util::lang::shared_ptr<unlearner::unlearner_base> unlearner_;
85 };
86 
87 } // namespace recommender
88 } // namespace core
89 } // namespace jubatus
90 
91 #endif // JUBATUS_CORE_RECOMMENDER_NEAREST_NEIGHBOR_RECOMMENDER_HPP_
jubatus::util::lang::shared_ptr< unlearner::unlearner_base > get_unlearner()
jubatus::util::lang::shared_ptr< storage::column_table > get_table()
jubatus::util::lang::shared_ptr< unlearner::unlearner_base > unlearner_
void update_row(const std::string &id, const sfv_diff_t &diff)
void neighbor_row(const common::sfv_t &query, std::vector< std::pair< std::string, float > > &ids, size_t ret_num) const
core::common::sfv_t sfv_diff_t
jubatus::util::data::optional< std::string > unlearner
msgpack::packer< jubatus_packer > packer
Definition: bandit_base.hpp:31
void similar_row(const common::sfv_t &query, std::vector< std::pair< std::string, float > > &ids, size_t ret_num) const
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
nearest_neighbor_recommender(jubatus::util::lang::shared_ptr< nearest_neighbor::nearest_neighbor_base > nearest_neighbor_engine)
jubatus::util::lang::shared_ptr< const storage::column_table > get_const_table() const
jubatus::util::lang::shared_ptr< nearest_neighbor::nearest_neighbor_base > nearest_neighbor_engine_