vocabtree  0.0.1
numerics.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #include <vector>
5 #include <opencv2/opencv.hpp>
6 
7 /// Provides useful wrappers around many numerical functionality, such as dealing with sparse
8 /// and dense matrix / vector data.
9 namespace numerics {
10  typedef std::vector< std::pair<uint32_t, float > > sparse_vector_t;
11 
12  /// Converts the input 1D cv::Mat to a sparse format, where each pair in the vector
13  /// is index, value. This is useful for BoW features which are usually zero.
14  std::vector< std::pair<uint32_t, float> > sparsify(const cv::Mat &dense);
15 
16  /// Converts the cosine similarity between two sparse weight vectors, which are premultiplied
17  /// by the relevant entries in idfw. Sample usage would be weights0 and weights1 to represent
18  /// two BoW vectors, and idfw to represent a vector of inverse document frequencies.
19  float cos_sim(const std::vector<std::pair<uint32_t, float> > &weights0,
20  const std::vector<std::pair<uint32_t, float> > &weights1,
21  const std::vector<float> &idfw);
22 
23  /// Converts the histogram intersection (min) between two sparse weight vectors, which are premultiplied
24  /// by the relevant entries in idfw. Sample usage would be weights0 and weights1 to represent
25  /// two BoW vectors, and idfw to represent a vector of inverse document frequencies.
26  float min_hist(const std::vector<std::pair<uint32_t, float> > &weights0,
27  const std::vector<std::pair<uint32_t, float> > &weights1,
28  const std::vector<float> &idfw);
29 
30 }