Tapkee
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
eigen_callbacks.hpp
Go to the documentation of this file.
1
/* This software is distributed under BSD 3-clause license (see LICENSE file).
2
*
3
* Copyright (c) 2012-2013 Sergey Lisitsyn, Fernando Iglesias
4
*/
5
6
#ifndef TAPKEE_EIGEN_CALLBACKS_H_
7
#define TAPKEE_EIGEN_CALLBACKS_H_
8
9
namespace
tapkee
10
{
11
// Features callback that provides operation that
12
// puts contents of the specified feature
13
// vector to given DenseVector instance.
14
struct
eigen_features_callback
15
{
16
eigen_features_callback
(
const
tapkee::DenseMatrix
& matrix) :
feature_matrix
(matrix) {};
17
inline
tapkee::IndexType
dimension
()
const
18
{
19
return
feature_matrix
.rows();
20
}
21
inline
void
vector
(
tapkee::IndexType
i,
tapkee::DenseVector
& v)
const
22
{
23
v =
feature_matrix
.col(i);
24
}
25
const
tapkee::DenseMatrix
&
feature_matrix
;
26
};
27
28
// Kernel function callback that computes
29
// similarity function values on vectors
30
// given by their indices. This impl. computes
31
// linear kernel i.e. dot product between two vectors.
32
struct
eigen_kernel_callback
33
{
34
eigen_kernel_callback
(
const
tapkee::DenseMatrix
& matrix) :
feature_matrix
(matrix) {};
35
inline
tapkee::ScalarType
kernel
(
tapkee::IndexType
a,
tapkee::IndexType
b)
const
36
{
37
return
feature_matrix
.col(a).dot(
feature_matrix
.col(b));
38
}
39
inline
tapkee::ScalarType
operator()
(
tapkee::IndexType
a,
tapkee::IndexType
b)
const
40
{
41
return
kernel
(a,b);
42
}
43
const
tapkee::DenseMatrix
&
feature_matrix
;
44
};
45
46
// Distance function callback that provides
47
// dissimilarity function values on vectors
48
// given by their indices. This impl. computes
49
// euclidean distance between two vectors.
50
struct
eigen_distance_callback
51
{
52
eigen_distance_callback
(
const
tapkee::DenseMatrix
& matrix) :
feature_matrix
(matrix) {};
53
inline
tapkee::ScalarType
distance
(
tapkee::IndexType
a,
tapkee::IndexType
b)
const
54
{
55
return
(
feature_matrix
.col(a)-
feature_matrix
.col(b)).norm();
56
}
57
inline
tapkee::ScalarType
operator()
(
tapkee::IndexType
a,
tapkee::IndexType
b)
const
58
{
59
return
distance
(a,b);
60
}
61
const
tapkee::DenseMatrix
&
feature_matrix
;
62
};
63
64
}
65
66
#endif
include
tapkee
callbacks
eigen_callbacks.hpp
Generated by
1.8.3.1