/
nystroem_method.hpp
87 lines (76 loc) · 2.61 KB
/
nystroem_method.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @file methods/nystroem_method/nystroem_method.hpp
* @author Ryan Curtin
* @author Marcus Edel
*
* Implementation of the Nystroem method for approximating a kernel matrix.
* There are many variations on how to do this, so template parameters allow the
* selection of many different techniques.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_METHODS_NYSTROEM_METHOD_NYSTROEM_METHOD_HPP
#define MLPACK_METHODS_NYSTROEM_METHOD_NYSTROEM_METHOD_HPP
#include <mlpack/core.hpp>
#include "kmeans_selection.hpp"
#include "ordered_selection.hpp"
#include "random_selection.hpp"
namespace mlpack {
template<
typename KernelType,
typename PointSelectionPolicy = KMeansSelection<>
>
class NystroemMethod
{
public:
/**
* Create the NystroemMethod object. The constructor here does not really do
* anything.
*
* @param data Data matrix.
* @param kernel Kernel to be used for computation.
* @param rank Rank to be used for matrix approximation.
*/
NystroemMethod(const arma::mat& data, KernelType& kernel, const size_t rank);
/**
* Apply the low-rank factorization to obtain an output matrix G such that
* K' = G * G^T.
*
* @param output Matrix to store kernel approximation into.
*/
void Apply(arma::mat& output);
/**
* Construct the kernel matrix with matrix that contains the selected points.
*
* @param data Data matrix pointer.
* @param miniKernel to store the constructed mini-kernel matrix in.
* @param semiKernel to store the constructed semi-kernel matrix in.
*/
void GetKernelMatrix(const arma::mat* data,
arma::mat& miniKernel,
arma::mat& semiKernel);
/**
* Construct the kernel matrix with the selected points.
*
* @param selectedPoints Indices of selected points.
* @param miniKernel to store the constructed mini-kernel matrix in.
* @param semiKernel to store the constructed semi-kernel matrix in.
*/
void GetKernelMatrix(const arma::Col<size_t>& selectedPoints,
arma::mat& miniKernel,
arma::mat& semiKernel);
private:
//! The reference dataset.
const arma::mat& data;
//! The locally stored kernel, if it is necessary.
KernelType& kernel;
//! Rank used for matrix approximation.
const size_t rank;
};
} // namespace mlpack
// Include implementation.
#include "nystroem_method_impl.hpp"
#endif