All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
lsh_nearest_neighbors_regression_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014 Andrzej Pacuk
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
18 
19 #include <boost/numeric/ublas/vector.hpp>
20 #include <boost/range/algorithm/copy.hpp>
21 
22 #include <iostream>
23 #include <iterator>
24 #include <vector>
25 
26 using coordinate_t = int;
27 using point_t = boost::numeric::ublas::vector<coordinate_t>;
28 
29 auto make_point(const std::initializer_list<int> &list) {
30  point_t point(list.size());
31  boost::copy(list, point.begin());
32  return point;
33 };
34 
35 int main() {
36  const std::vector<point_t> training_points =
37  {make_point({0, 0}), make_point({0, 1}),
38  make_point({1, 0}), make_point({1, 1})};
39  const std::vector<double> training_results = {0.0, 0.4, 0.6, 1.0};
40  const std::vector<point_t> test_points =
41  {make_point({0, -1}), make_point({2, 1})};
42 
43  auto const passes = 50;
44  auto const hash_functions_per_point = 10;
45  auto const dimensions = training_points.front().size();
46  auto const threads_count = 1;
47  //w_param should be essentially bigger than radius of expected test point neighborhood
48  auto const w_param = 3.0;
49 
50  auto lsh_function_generator =
51  paal::lsh::l_2_hash_function_generator<>{dimensions, w_param};
53  training_points, training_results,
54  passes,
55  std::move(lsh_function_generator),
56  hash_functions_per_point,
57  threads_count);
58 
59  std::vector<double> results;
60  model.test(test_points, std::back_inserter(results));
61 
62  std::cout << "Solution:" << std::endl;
63  boost::copy(results, std::ostream_iterator<double>(std::cout, ","));
64  std::cout << std::endl;
65 
66  return 0;
67 }
69 
Factory class for l_p_hash_function.
auto make_lsh_nearest_neighbors_regression_tuple_hash(TrainingPoints &&training_points, TrainingResults &&training_results, unsigned passes, FunctionGenerator &&function_generator, unsigned hash_functions_per_point, unsigned threads_count=std::thread::hardware_concurrency())
This is the special version of make_lsh_nearest_neighbors_regression. This version assumes that hash ...