jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
bit_vector_ranking.cpp
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 #include <functional>
18 #include <utility>
19 #include <vector>
20 #include "bit_vector_ranking.hpp"
21 #include "../storage/abstract_column.hpp"
22 #include "../storage/fixed_size_heap.hpp"
23 
24 using std::make_pair;
25 using std::pair;
26 using std::vector;
29 
30 namespace jubatus {
31 namespace core {
32 namespace nearest_neighbor {
33 
35  const bit_vector& query,
36  const const_bit_vector_column& bvs,
37  vector<pair<uint64_t, float> >& ret,
38  uint64_t ret_num) {
40  for (uint64_t i = 0; i < bvs.size(); ++i) {
41  const size_t dist = query.calc_hamming_distance(bvs[i]);
42  heap.push(make_pair(dist, i));
43  }
44 
45  vector<pair<uint32_t, uint64_t> > sorted;
46  heap.get_sorted(sorted);
47 
48  ret.clear();
49  const float denom = query.bit_num();
50  for (size_t i = 0; i < sorted.size(); ++i) {
51  ret.push_back(make_pair(sorted[i].second, sorted[i].first / denom));
52  }
53 }
54 
55 } // namespace nearest_neighbor
56 } // namespace core
57 } // namespace jubatus
void get_sorted(std::vector< T > &v) const
double dist(const common::sfv_t &p1, const common::sfv_t &p2)
Definition: util.cpp:151
void ranking_hamming_bit_vectors(const bit_vector &query, const const_bit_vector_column &bvs, vector< pair< uint64_t, float > > &ret, uint64_t ret_num)
const bit_vector_column const_bit_vector_column
bit_vector_base< uint64_t > bit_vector