jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
jubatus::core::storage::lsh_probe_generator Class Reference

#include <lsh_util.hpp>

Collaboration diagram for jubatus::core::storage::lsh_probe_generator:
Collaboration graph

Public Member Functions

const lsh_vectorbase (size_t i) const
 
lsh_vector base_all () const
 
std::pair< size_t, lsh_vectorget_next_table_and_vector ()
 
void init ()
 
 lsh_probe_generator (const std::vector< float > &hash, size_t num_hash_tables)
 

Private Types

typedef std::pair< float, std::pair< size_t, std::vector< int > > > diff_type
 
typedef std::priority_queue< diff_type, std::vector< diff_type >, std::greater< diff_type > > heap_type
 

Private Member Functions

void next_perturbations ()
 

Private Attributes

std::vector< lsh_vectorbase_
 
std::vector< std::vector< float > > hash_
 
heap_type heap_
 
std::vector< std::vector< std::pair< float, int > > > perturbation_sets_
 

Detailed Description

Definition at line 30 of file lsh_util.hpp.

Member Typedef Documentation

typedef std::pair<float, std::pair<size_t, std::vector<int> > > jubatus::core::storage::lsh_probe_generator::diff_type
private

Definition at line 43 of file lsh_util.hpp.

typedef std::priority_queue< diff_type, std::vector<diff_type>, std::greater<diff_type> > jubatus::core::storage::lsh_probe_generator::heap_type
private

Definition at line 47 of file lsh_util.hpp.

Constructor & Destructor Documentation

jubatus::core::storage::lsh_probe_generator::lsh_probe_generator ( const std::vector< float > &  hash,
size_t  num_hash_tables 
)

Definition at line 84 of file lsh_util.cpp.

References base_, and hash_.

86  {
87  partition(hash, num_hash_tables, hash_);
88  base_.resize(hash_.size());
89  for (size_t i = 0; i < hash_.size(); ++i) {
90  threshold(hash_[i], base_[i]);
91  }
92 }
std::vector< std::vector< float > > hash_
Definition: lsh_util.hpp:51

Member Function Documentation

const lsh_vector& jubatus::core::storage::lsh_probe_generator::base ( size_t  i) const
inline

Definition at line 37 of file lsh_util.hpp.

References base_.

Referenced by jubatus::core::storage::lsh_index_storage::make_entry().

37  {
38  return base_[i];
39  }

Here is the caller graph for this function:

lsh_vector jubatus::core::storage::lsh_probe_generator::base_all ( ) const

Definition at line 118 of file lsh_util.cpp.

References base_, and jubatus::core::storage::lsh_vector::set().

118  {
119  const size_t base_size = base_[0].size();
120  lsh_vector lv(base_size * base_.size());
121  for (size_t i = 0; i < base_.size(); ++i) {
122  for (size_t j = 0; j < base_size; ++j) {
123  lv.set(i * base_size + j, base_[i].get(j));
124  }
125  }
126  return lv;
127 }

Here is the call graph for this function:

pair< size_t, lsh_vector > jubatus::core::storage::lsh_probe_generator::get_next_table_and_vector ( )

Definition at line 129 of file lsh_util.cpp.

References base_, heap_, next_perturbations(), and perturbation_sets_.

129  {
130  if (heap_.empty()) {
131  return make_pair(-1ul, lsh_vector());
132  }
133  const size_t i = heap_.top().second.first;
134  pair<size_t, lsh_vector> ret(
135  i,
136  perturbe(base_[i], heap_.top().second.second, perturbation_sets_[i]));
138  return ret;
139 }
std::vector< std::vector< std::pair< float, int > > > perturbation_sets_
Definition: lsh_util.hpp:53

Here is the call graph for this function:

void jubatus::core::storage::lsh_probe_generator::init ( )

Definition at line 94 of file lsh_util.cpp.

References base_, jubatus::core::clustering::dist(), hash_, heap_, and perturbation_sets_.

94  {
95  const int base_size = base_[0].size();
96 
97  perturbation_sets_.resize(base_.size());
98  for (size_t i = 0; i < base_.size(); ++i) {
99  vector<pair<float, int> >& cands = perturbation_sets_[i];
100  cands.resize(2 * base_size);
101  for (int j = 0; j < base_size; ++j) {
102  const float dist = hash_[i][j] - base_[i].get(j);
103  cands[j * 2] = make_pair((1 - dist) * (1 - dist), j);
104  cands[j * 2 + 1] = make_pair(dist * dist, ~j);
105  }
106  sort(cands.begin(), cands.end());
107  }
108 
109  for (size_t i = 0; i < base_.size(); ++i) {
110  if (!perturbation_sets_[i].empty()) {
111  heap_.push(
112  make_pair(perturbation_sets_[i][0].first,
113  make_pair(i, vector<int>(1))));
114  }
115  }
116 }
double dist(const common::sfv_t &p1, const common::sfv_t &p2)
Definition: util.cpp:151
std::vector< std::vector< float > > hash_
Definition: lsh_util.hpp:51
std::vector< std::vector< std::pair< float, int > > > perturbation_sets_
Definition: lsh_util.hpp:53

Here is the call graph for this function:

void jubatus::core::storage::lsh_probe_generator::next_perturbations ( )
private

Definition at line 141 of file lsh_util.cpp.

References heap_, and perturbation_sets_.

Referenced by get_next_table_and_vector().

141  {
142  const int index = heap_.top().second.first;
143  const vector<pair<float, int> >& cands = perturbation_sets_[index];
144 
145  vector<int> shifted = heap_.top().second.second;
146  ++shifted.back();
147 
148  vector<int> expanded = heap_.top().second.second;
149  expanded.push_back(expanded.back() + 1);
150 
151  const float score_base = heap_.top().first;
152  heap_.pop();
153 
154  if ((size_t) shifted.back() < cands.size()) {
155  const float score_diff = cands[shifted.back()].first
156  - cands[shifted.back() - 1].first;
157  heap_.push(make_pair(score_base + score_diff, make_pair(index, shifted)));
158  }
159 
160  if ((size_t) expanded.back() < cands.size()) {
161  const float score_diff = cands[expanded.back()].first;
162  heap_.push(make_pair(score_base + score_diff, make_pair(index, expanded)));
163  }
164 }
std::vector< std::vector< std::pair< float, int > > > perturbation_sets_
Definition: lsh_util.hpp:53

Here is the caller graph for this function:

Member Data Documentation

std::vector<lsh_vector> jubatus::core::storage::lsh_probe_generator::base_
private

Definition at line 52 of file lsh_util.hpp.

Referenced by base(), base_all(), get_next_table_and_vector(), init(), and lsh_probe_generator().

std::vector<std::vector<float> > jubatus::core::storage::lsh_probe_generator::hash_
private

Definition at line 51 of file lsh_util.hpp.

Referenced by init(), and lsh_probe_generator().

heap_type jubatus::core::storage::lsh_probe_generator::heap_
private

Definition at line 54 of file lsh_util.hpp.

Referenced by get_next_table_and_vector(), init(), and next_perturbations().

std::vector<std::vector<std::pair<float, int> > > jubatus::core::storage::lsh_probe_generator::perturbation_sets_
private

Definition at line 53 of file lsh_util.hpp.

Referenced by get_next_table_and_vector(), init(), and next_perturbations().


The documentation for this class was generated from the following files: