jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
lsh.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_LSH_HPP_
18 #define JUBATUS_CORE_RECOMMENDER_LSH_HPP_
19 
20 #include <string>
21 #include <utility>
22 #include <vector>
23 #include "jubatus/util/data/serialization.h"
24 #include "jubatus/util/lang/shared_ptr.h"
25 #include "recommender_base.hpp"
26 
27 namespace jubatus {
28 namespace core {
29 namespace framework {
30 template <typename Model, typename Diff>
31 class linear_mixable_helper;
32 } // namespace framework
33 namespace storage {
37 } // namespace storage
38 namespace recommender {
39 
40 class lsh : public recommender_base {
41  public:
42  struct config {
43  config();
44 
45  int64_t hash_num;
46 
47  template<typename Ar>
48  void serialize(Ar& ar) {
49  ar & JUBA_MEMBER(hash_num);
50  }
51  };
52 
53  explicit lsh(uint64_t hash_num);
54  explicit lsh(const config& config);
55  lsh();
56  ~lsh();
57 
58  void similar_row(
59  const common::sfv_t& query,
60  std::vector<std::pair<std::string, float> >& ids,
61  size_t ret_num) const;
62  void neighbor_row(
63  const common::sfv_t& query,
64  std::vector<std::pair<std::string, float> >& ids,
65  size_t ret_num) const;
66  void clear();
67  void clear_row(const std::string& id);
68  void update_row(const std::string& id, const sfv_diff_t& diff);
69  void get_all_row_ids(std::vector<std::string>& ids) const;
70  std::string type() const;
71 
73 
74  void pack(framework::packer& packer) const;
75  void unpack(msgpack::object o);
76 
77  private:
78  void calc_lsh_values(const common::sfv_t& sfv, storage::bit_vector& bv) const;
79  void generate_column_base(const std::string& column);
81 
82  void initialize_model();
83 
84  // bases for lsh
85  jubatus::util::data::unordered_map<std::string, std::vector<float> >
87 
88  jubatus::util::lang::shared_ptr<storage::mixable_bit_index_storage>
90 
91  const uint64_t hash_num_;
92 };
93 
94 } // namespace recommender
95 } // namespace core
96 } // namespace jubatus
97 
98 #endif // JUBATUS_CORE_RECOMMENDER_LSH_HPP_
void similar_row(const common::sfv_t &query, std::vector< std::pair< std::string, float > > &ids, size_t ret_num) const
Definition: lsh.cpp:72
const uint64_t hash_num_
Definition: lsh.hpp:91
void pack(framework::packer &packer) const
Definition: lsh.cpp:159
void unpack(msgpack::object o)
Definition: lsh.cpp:165
void get_all_row_ids(std::vector< std::string > &ids) const
Definition: lsh.cpp:140
void update_row(const std::string &id, const sfv_diff_t &diff)
Definition: lsh.cpp:130
void neighbor_row(const common::sfv_t &query, std::vector< std::pair< std::string, float > > &ids, size_t ret_num) const
Definition: lsh.cpp:86
core::common::sfv_t sfv_diff_t
void generate_column_bases(const common::sfv_t &v)
Definition: lsh.cpp:116
std::string type() const
Definition: lsh.cpp:144
framework::linear_mixable_helper< bit_index_storage, bit_table_t > mixable_bit_index_storage
Definition: lsh.hpp:34
framework::mixable * get_mixable() const
Definition: lsh.cpp:148
void clear_row(const std::string &id)
Definition: lsh.cpp:103
void generate_column_base(const std::string &column)
Definition: lsh.cpp:122
msgpack::packer< jubatus_packer > packer
Definition: bandit_base.hpp:31
jubatus::util::data::unordered_map< std::string, std::vector< float > > column2baseval_
Definition: lsh.hpp:86
std::vector< T > v(size)
void calc_lsh_values(const common::sfv_t &sfv, storage::bit_vector &bv) const
Definition: lsh.cpp:108
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
jubatus::util::lang::shared_ptr< storage::mixable_bit_index_storage > mixable_storage_
Definition: lsh.hpp:89