jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
euclid_lsh.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_NEAREST_NEIGHBOR_EUCLID_LSH_HPP_
18 #define JUBATUS_CORE_NEAREST_NEIGHBOR_EUCLID_LSH_HPP_
19 
20 #include <map>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 #include "jubatus/util/data/serialization.h"
25 #include "jubatus/util/lang/shared_ptr.h"
27 
28 namespace jubatus {
29 namespace core {
30 namespace storage {
31 class column_table;
32 }
33 namespace nearest_neighbor {
34 
36  public:
37  struct config {
39  : hash_num(64u) {
40  }
41 
42  // TODO(beam2d): make it uint32_t (by modifying pficommon)
43  int32_t hash_num;
44 
45  template <typename Ar>
46  void serialize(Ar& ar) {
47  ar & JUBA_MEMBER(hash_num);
48  }
49  };
50 
51  euclid_lsh(
52  const config& conf,
53  jubatus::util::lang::shared_ptr<storage::column_table> table,
54  const std::string& id);
55  euclid_lsh(
56  const config& conf,
57  jubatus::util::lang::shared_ptr<storage::column_table> table,
58  std::vector<storage::column_type>& schema,
59  const std::string& id);
60 
61  virtual std::string type() const {
62  return "euclid_lsh";
63  }
64 
65  virtual void set_row(const std::string& id, const common::sfv_t& sfv);
66  virtual void neighbor_row(
67  const common::sfv_t& query,
68  std::vector<std::pair<std::string, float> >& ids,
69  uint64_t ret_num) const;
70  virtual void neighbor_row(
71  const std::string& query,
72  std::vector<std::pair<std::string, float> >& ids,
73  uint64_t ret_num) const;
74 
75  virtual float calc_similarity(float distance) const {
76  return -distance;
77  }
78 
79  private:
80  void set_config(const config& conf);
81  void fill_schema(std::vector<storage::column_type>& schema);
84 
86  const storage::bit_vector& bv,
87  float norm,
88  std::vector<std::pair<std::string, float> >& ids,
89  uint64_t ret_num) const;
90 
91  uint64_t first_column_id_;
92  uint32_t hash_num_;
93 };
94 
95 } // namespace nearest_neighbor_base
96 } // namespace core
97 } // namespace jubatus
98 
99 #endif // JUBATUS_CORE_NEAREST_NEIGHBOR_EUCLID_LSH_HPP_
virtual void neighbor_row(const common::sfv_t &query, std::vector< std::pair< std::string, float > > &ids, uint64_t ret_num) const
storage::const_bit_vector_column & lsh_column() const
Definition: euclid_lsh.cpp:131
void fill_schema(std::vector< storage::column_type > &schema)
Definition: euclid_lsh.cpp:125
storage::const_float_column & norm_column() const
Definition: euclid_lsh.cpp:135
virtual float calc_similarity(float distance) const
Definition: euclid_lsh.hpp:75
void neighbor_row_from_hash(const storage::bit_vector &bv, float norm, std::vector< std::pair< std::string, float > > &ids, uint64_t ret_num) const
Definition: euclid_lsh.cpp:139
virtual std::string type() const
Definition: euclid_lsh.hpp:61
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
virtual void set_row(const std::string &id, const common::sfv_t &sfv)
Definition: euclid_lsh.cpp:83
euclid_lsh(const config &conf, jubatus::util::lang::shared_ptr< storage::column_table > table, const std::string &id)