jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
lsh.cpp
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 #include <map>
18 #include <string>
19 #include <vector>
20 #include "lsh.hpp"
21 #include "lsh_function.hpp"
22 #include "../storage/column_table.hpp"
23 
24 namespace jubatus {
25 namespace core {
26 namespace nearest_neighbor {
27 
29  const config& conf,
30  jubatus::util::lang::shared_ptr<storage::column_table> table,
31  const std::string& id)
32  : bit_vector_nearest_neighbor_base(conf.hash_num, table, id) {
33 
34  if (!(1 <= conf.hash_num)) {
35  throw JUBATUS_EXCEPTION(
36  common::invalid_parameter("1 <= hash_num"));
37  }
38 }
39 
41  const config& conf,
42  jubatus::util::lang::shared_ptr<storage::column_table> table,
43  std::vector<storage::column_type>& schema,
44  const std::string& id)
45  : bit_vector_nearest_neighbor_base(conf.hash_num, table, schema, id) {
46 
47  if (!(1 <= conf.hash_num)) {
48  throw JUBATUS_EXCEPTION(
49  common::invalid_parameter("1 <= hash_num"));
50  }
51 }
52 
54  return cosine_lsh(sfv, bitnum());
55 }
56 
57 } // namespace nearest_neighbor
58 } // namespace core
59 } // namespace jubatus
#define JUBATUS_EXCEPTION(e)
Definition: exception.hpp:79
virtual storage::bit_vector hash(const common::sfv_t &sfv) const
Definition: lsh.cpp:53
lsh(const config &conf, jubatus::util::lang::shared_ptr< storage::column_table > table, const std::string &id)
Definition: lsh.cpp:28
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
bit_vector cosine_lsh(const common::sfv_t &sfv, uint32_t hash_num)