All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
frequent_directions_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014
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/irange.hpp"
20 
21 #include <boost/numeric/ublas/matrix.hpp>
22 #include <boost/numeric/ublas/matrix_proxy.hpp>
23 
24 #include <iostream>
25 #include <vector>
26 
27 using coordinate_t = double;
28 using matrix_t = boost::numeric::ublas::matrix<coordinate_t>;
29 
30 int main() {
31  std::size_t const rows_count = 5;
32  std::size_t const columns_count = 3;
33  std::size_t const sketch_size = 4;
34 
35  auto fd_sketch = paal::make_frequent_directions<coordinate_t>(sketch_size, columns_count);
36 
37  matrix_t data(rows_count, columns_count);
38  for (auto i : paal::irange(rows_count)) {
39  for (auto j : paal::irange(columns_count)) {
40  data(i, j) = i + j;
41  }
42  }
43  fd_sketch.update(std::move(data));
44 
45  std::vector<std::vector<coordinate_t>> rows = {
46  {2, 1, 0},
47  {3, 2, 1},
48  {4, 3, 2},
49  {5, 4, 3},
50  {6, 5, 4}};
51  fd_sketch.update_range(std::move(rows));
52 
53  auto row = {7.0, 6.0, 5.0};
54  fd_sketch.update_row(std::move(row));
55 
56  fd_sketch.compress();
57 
58  auto actual_size = fd_sketch.get_sketch().second;
59  std::cout << "Actual sketch size: " << actual_size << std::endl;
60  auto sketch = fd_sketch.get_sketch().first;
61  boost::numeric::ublas::matrix_range<matrix_t> sketch_range (sketch,
62  boost::numeric::ublas::range(0, actual_size),
63  boost::numeric::ublas::range(0, columns_count));
64  std::cout << "Sketch data:" << std::endl;
65  paal::print_matrix(std::cout, sketch_range, " ");
66  std::cout << std::endl;
67 
68  return 0;
69 }
70 
void print_matrix(Stream &o, Matrix &&m, const std::string &del)
prints matrix with delimiters
auto irange(T begin, T end)
irange
Definition: irange.hpp:22