-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre_processing.hpp
61 lines (48 loc) · 2.16 KB
/
pre_processing.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef _CERTIFIEDCOSINE_PRE_PROCESSING
#define _CERTIFIEDCOSINE_PRE_PROCESSING
#include <Eigen/Dense>
#include "constants.hpp"
#include "storage.hpp"
namespace certified_cosine {
template <typename float_t>
using PMatrix = Eigen::Ref<Eigen::Matrix<float_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>;
template <typename float_t>
void exact_neighbors(const PMatrix<float_t> &matrix, dynamic_storage<float_t> &storage, uint num_neighbors = 10);
template <typename float_t>
void reverse_edges(dynamic_storage<float_t> &storage);
template <typename float_t>
void build_all_edges(dynamic_storage<float_t> &storage);
template <typename float_t>
void starting_approximations(const PMatrix<float_t> &matrix, dynamic_storage<float_t> &storage, uint starting_points);
template <typename float_t>
void shuffle_all_edges(const PMatrix<float_t> &matrix, dynamic_storage<float_t> &storage, int num_incoming_edges);
// redo the exact neighbors
template <typename float_t>
void make_smaller(const dynamic_storage<float_t> &input_storage, dynamic_storage<float_t> &output_storage,
uint new_num_neighbors);
/**
* Do everything required
*/
template <typename float_t>
void preprocess(const PMatrix<float_t> &matrix, dynamic_storage<float_t> &storage, uint num_neighbors = 10,
uint starting_points = 1 << 16) {
exact_neighbors(matrix, storage, num_neighbors);
reverse_edges(storage);
//#ifndef CERTIFIEDCOSINE_WEIGHT_DIST
shuffle_all_edges(matrix, storage, num_neighbors / 3);
//#endif
build_all_edges(storage);
starting_approximations(matrix, storage, starting_points);
}
template <typename float_t>
void make_smaller_all(const PMatrix<float_t> &matrix, const dynamic_storage<float_t> &input_storage,
dynamic_storage<float_t> &output_storage, uint new_num_neighbors = 10,
uint starting_points = 1 << 16) {
make_smaller(input_storage, output_storage, new_num_neighbors);
reverse_edges(output_storage);
shuffle_all_edges(matrix, output_storage, new_num_neighbors / 3);
build_all_edges(output_storage);
starting_approximations(matrix, output_storage, starting_points);
}
} // namespace certified_cosine
#endif