All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
lsh_nearest_neighbors_regression_efficient_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 #include "paal/utils/functors.hpp"
19 
20 #include <boost/range/adaptor/transformed.hpp>
21 #include <boost/range/algorithm/copy.hpp>
22 
23 #include <iostream>
24 #include <iterator>
25 #include <utility>
26 #include <vector>
27 
28 int main() {
29  using coordinate_t = int;
30  using result_t = double;
31  using point_coordinates_t = std::vector<coordinate_t>;
32  using training_point_t = std::tuple<point_coordinates_t, result_t>;
33 
34  constexpr paal::utils::tuple_get<0> get_coordinates{};
35  constexpr paal::utils::tuple_get<1> get_result{};
36 
37  const std::vector<training_point_t> training_points = {
38  training_point_t{{0, 0}, 0.0}, training_point_t{{0, 1}, 0.4},
39  training_point_t{{1, 0}, 0.6}, training_point_t{{1, 1}, 1.0}};
40  const std::vector<point_coordinates_t> test_points =
41  {{0, -1}, {2, 1}};
42 
43  auto const passes = 50;
44  auto const dimensions = std::get<0>(training_points.front()).size();
45  auto const hash_functions_per_point = 1;
46 
48  training_points | boost::adaptors::transformed(get_coordinates),
49  training_points | boost::adaptors::transformed(get_result),
50  passes,
52  hash_functions_per_point);
53 
54  std::vector<result_t> results;
55  results.reserve(test_points.size());
56  model.test(test_points, std::back_inserter(results));
57 
58  std::cout << "Solution:" << std::endl;
59  boost::copy(results, std::ostream_iterator<double>(std::cout, ","));
60  std::cout << std::endl;
61 
62  return 0;
63 }
65 
Factory class for projection_hash_function.
int main()
[LSH Nearest Neighbors Regression Efficient Example]
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 ...
This file contains set of simple useful functors or functor adapters.
functor for std::tuple::get&lt;I&gt;
Definition: functors.hpp:1002