|
|
| Gram () |
| | Default constructor.
|
| |
| template<typename... Ts> |
| | Gram (Ts &&... args) |
| | Construct and initialize kernel with arbitrary arguments. More...
|
| |
| arma::Mat< T > | GetMatrix2 (const arma::Mat< T > &input1, const arma::Mat< T > &input2) const |
| | Compute Gram matrix for row-major ordered data. More...
|
| |
| arma::Mat< T > | GetMatrix (const arma::Mat< T > &input1, const arma::Mat< T > &input2) const |
| | Compute Gram matrix for column-major ordered data. More...
|
| |
| arma::Mat< T > | GetApprox (const arma::Mat< T > &input1, const arma::Mat< T > &input2, size_t k) const |
| | Compute an approximate Gram matrix using the Nyström method. More...
|
| |
| arma::Mat< T > | GetMatrix (const arma::Mat< T > &input1) const |
| | Compute Gram matrix of a dataset with itself (column-major). More...
|
| |
| template<typename Archive > |
| void | serialize (Archive &ar, const unsigned int) |
| |
template<class KERNEL, class T = DTYPE>
struct data::Gram< KERNEL, T >
Definition at line 136 of file data.h.
◆ Gram()
template<class KERNEL , class T = DTYPE>
template<typename... Ts>
Construct and initialize kernel with arbitrary arguments.
- Template Parameters
-
| Ts | Argument types for the kernel constructor. |
- Parameters
-
| args | Arguments to forward to the kernel constructor. |
Definition at line 147 of file data.h.
147 : kernel_(args...) {}
◆ GetApprox()
template<class KERNEL , class T = DTYPE>
| arma::Mat<T> data::Gram< KERNEL, T >::GetApprox |
( |
const arma::Mat< T > & |
input1, |
|
|
const arma::Mat< T > & |
input2, |
|
|
size_t |
k |
|
) |
| const |
|
inline |
Compute an approximate Gram matrix using the Nyström method.
Selects k random landmark points, computes their kernel matrix W, and uses it to approximate the full kernel matrix: K_approx = C * pinv(W) * C^T
- Parameters
-
| input1 | First dataset (columns are samples). |
| input2 | Second dataset (columns are samples). |
| k | Number of landmark points to sample. |
- Returns
- Approximated Gram matrix.
Definition at line 204 of file data.h.
208 size_t n_samples = input1.n_rows;
209 arma::uvec indices = arma::randi<arma::uvec>(k, arma::distr_param(0, n_samples - 1));
210 arma::Mat<T> landmarks = input1.cols(indices);
212 arma::Mat<T> W = this->
GetMatrix(landmarks, landmarks);
213 arma::Mat<T> C = this->
GetMatrix(input1, landmarks);
214 arma::Mat<T> W_pinv = arma::pinv(W);
216 return C * W_pinv * C.t();
arma::Mat< T > GetMatrix(const arma::Mat< T > &input1, const arma::Mat< T > &input2) const
Compute Gram matrix for column-major ordered data.
References data::Gram< KERNEL, T >::GetMatrix().
◆ GetMatrix() [1/2]
template<class KERNEL , class T = DTYPE>
| arma::Mat<T> data::Gram< KERNEL, T >::GetMatrix |
( |
const arma::Mat< T > & |
input1 | ) |
const |
|
inline |
◆ GetMatrix() [2/2]
template<class KERNEL , class T = DTYPE>
| arma::Mat<T> data::Gram< KERNEL, T >::GetMatrix |
( |
const arma::Mat< T > & |
input1, |
|
|
const arma::Mat< T > & |
input2 |
|
) |
| const |
|
inline |
Compute Gram matrix for column-major ordered data.
- Parameters
-
| input1 | First dataset (columns are samples). |
| input2 | Second dataset (columns are samples). |
- Returns
- Gram matrix of size input1.n_cols × input2.n_cols.
Definition at line 178 of file data.h.
181 arma::Mat<T> matrix(input1.n_cols, input2.n_cols);
183 #pragma omp parallel for collapse(2)
184 for (
int i = 0; i < int(input1.n_cols); i++)
185 for (
int j = 0; j < int(input2.n_cols); j++)
186 matrix(i,j) = kernel_.Evaluate(input1.col(i).eval(),
187 input2.col(j).eval());
Referenced by data::Gram< KERNEL, T >::GetApprox(), and data::Gram< KERNEL, T >::GetMatrix().
◆ GetMatrix2()
template<class KERNEL , class T = DTYPE>
| arma::Mat<T> data::Gram< KERNEL, T >::GetMatrix2 |
( |
const arma::Mat< T > & |
input1, |
|
|
const arma::Mat< T > & |
input2 |
|
) |
| const |
|
inline |
Compute Gram matrix for row-major ordered data.
- Parameters
-
| input1 | First dataset (rows are samples). |
| input2 | Second dataset (rows are samples). |
- Returns
- Gram matrix of size input1.n_rows × input2.n_rows.
Definition at line 158 of file data.h.
161 arma::Mat<T> matrix(input1.n_rows, input2.n_rows);
163 #pragma omp parallel for collapse(2)
164 for (
int i = 0; i < int(input1.n_rows); i++)
165 for (
int j = 0; j < int(input2.n_rows); j++)
166 matrix(i,j) = kernel_.Evaluate(input1.row(i).eval(),
167 input2.row(j).eval());
◆ serialize()
template<class KERNEL , class T = DTYPE>
template<typename Archive >
| void data::Gram< KERNEL, T >::serialize |
( |
Archive & |
ar, |
|
|
const unsigned int |
|
|
) |
| |
|
inline |
Serialize the model.
Definition at line 232 of file data.h.
234 ar ( cereal::make_nvp(
"kernel",kernel_) );
The documentation for this struct was generated from the following file: