/
precomputed_callbacks.hpp
44 lines (38 loc) · 1.24 KB
/
precomputed_callbacks.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
/* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Copyright (c) 2012-2013 Sergey Lisitsyn, Fernando Iglesias
*/
#ifndef TAPKEE_PRECOMPUTED_CALLBACKS_H_
#define TAPKEE_PRECOMPUTED_CALLBACKS_H_
namespace tapkee
{
// Here we provide basic but still full set of callbacks
// based on the Eigen3 template matrix library
// Kernel function callback that computes
// similarity function values on vectors
// given by their indices. This impl. computes
// linear kernel i.e. dot product between two vectors.
struct precomputed_kernel_callback
{
precomputed_kernel_callback(const tapkee::DenseMatrix& matrix) : kernel_matrix(matrix) {};
inline tapkee::ScalarType kernel(int a, int b) const
{
return kernel_matrix(a,b);
}
const tapkee::DenseMatrix& kernel_matrix;
};
// Distance function callback that provides
// dissimilarity function values on vectors
// given by their indices. This impl. computes
// euclidean distance between two vectors.
struct precomputed_distance_callback
{
precomputed_distance_callback(const tapkee::DenseMatrix& matrix) : distance_matrix(matrix) {};
inline tapkee::ScalarType distance(int a, int b) const
{
return distance_matrix(a,b);
}
const tapkee::DenseMatrix& distance_matrix;
};
}
#endif