jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
recommender_base.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011 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_RECOMMENDER_BASE_HPP_
18 #define JUBATUS_CORE_RECOMMENDER_RECOMMENDER_BASE_HPP_
19 
20 #include <vector>
21 #include <string>
22 #include <utility>
23 #include "jubatus/util/data/unordered_map.h"
24 #include "jubatus/util/lang/shared_ptr.h"
25 #include "../common/type.hpp"
26 #include "../framework/mixable.hpp"
27 #include "../framework/model.hpp"
28 #include "../storage/sparse_matrix_storage.hpp"
29 #include "../storage/recommender_storage_base.hpp"
30 #include "../unlearner/unlearner_base.hpp"
31 #include "recommender_type.hpp"
32 
33 namespace jubatus {
34 namespace core {
35 namespace storage {
36 class column_table;
37 } // namespace storage
38 namespace recommender {
39 
41  public:
43  virtual ~recommender_base();
44 
45  // return similar row for query with similarity scores.
46  virtual void similar_row(
47  const common::sfv_t& query,
48  std::vector<std::pair<std::string, float> >& ids,
49  size_t ret_num) const = 0;
50  // return similar row for query with distance scores.
51  virtual void neighbor_row(
52  const common::sfv_t& query,
53  std::vector<std::pair<std::string, float> >& ids,
54  size_t ret_num) const = 0;
55  virtual void clear() = 0;
56  virtual void clear_row(const std::string& id) = 0;
57  virtual void update_row(const std::string& id, const sfv_diff_t& diff) = 0;
58  virtual void get_all_row_ids(std::vector<std::string>& ids) const = 0;
59 
60  virtual std::string type() const = 0;
61 
62  // Either get_(const)_storage or get_(const)_table should return non-null
63  // pointer.
65  const {
66  return NULL;
67  }
68 
69  virtual jubatus::util::lang::shared_ptr<storage::column_table> get_table() {
70  return jubatus::util::lang::shared_ptr<storage::column_table>();
71  }
72  virtual jubatus::util::lang::shared_ptr<const storage::column_table>
73  get_const_table() const {
74  return jubatus::util::lang::shared_ptr<const storage::column_table>();
75  }
76 
77  virtual jubatus::util::lang::shared_ptr<unlearner::unlearner_base>
79  return jubatus::util::lang::shared_ptr<unlearner::unlearner_base>();
80  }
81 
82  virtual void similar_row(
83  const std::string& id,
84  std::vector<std::pair<std::string, float> >& ids,
85  size_t ret_num) const;
86  virtual void neighbor_row(
87  const std::string& id,
88  std::vector<std::pair<std::string, float> >& ids,
89  size_t ret_num) const;
90  void complete_row(const std::string& id, common::sfv_t& ret) const;
91  void complete_row(const common::sfv_t& query, common::sfv_t& ret) const;
92  void decode_row(const std::string& id, common::sfv_t& ret) const;
93 
94  virtual framework::mixable* get_mixable() const = 0;
95 
96  static float calc_similality(common::sfv_t& q1, common::sfv_t& q2);
97  static float calc_l2norm(const common::sfv_t& query);
98 
99  protected:
100  static const uint64_t complete_row_similar_num_;
101 
102  // TODO(beam2d): Workaround to correctly store the storage on save.
104 };
105 
106 } // namespace recommender
107 } // namespace core
108 } // namespace jubatus
109 
110 #endif // JUBATUS_CORE_RECOMMENDER_RECOMMENDER_BASE_HPP_
static float calc_l2norm(const common::sfv_t &query)
virtual void clear_row(const std::string &id)=0
virtual jubatus::util::lang::shared_ptr< unlearner::unlearner_base > get_unlearner()
virtual const core::storage::recommender_storage_base * get_const_storage() const
void decode_row(const std::string &id, common::sfv_t &ret) const
virtual void similar_row(const common::sfv_t &query, std::vector< std::pair< std::string, float > > &ids, size_t ret_num) const =0
virtual std::string type() const =0
virtual jubatus::util::lang::shared_ptr< storage::column_table > get_table()
core::common::sfv_t sfv_diff_t
virtual void get_all_row_ids(std::vector< std::string > &ids) const =0
void complete_row(const std::string &id, common::sfv_t &ret) const
virtual void neighbor_row(const common::sfv_t &query, std::vector< std::pair< std::string, float > > &ids, size_t ret_num) const =0
core::storage::sparse_matrix_storage orig_
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
virtual jubatus::util::lang::shared_ptr< const storage::column_table > get_const_table() const
static float calc_similality(common::sfv_t &q1, common::sfv_t &q2)
virtual framework::mixable * get_mixable() const =0
virtual void update_row(const std::string &id, const sfv_diff_t &diff)=0