Representation of a kernel matrix. More...
#include <Kernel.hpp>
Public Member Functions | |
Kernel (DenseM_t &data, scalar_t lambda) | |
virtual | ~Kernel ()=default |
std::size_t | n () const |
std::size_t | d () const |
virtual scalar_t | eval (std::size_t i, std::size_t j) const |
void | operator() (const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DenseMatrix< real_t > &B) const |
void | operator() (const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DenseMatrix< std::complex< real_t > > &B) const |
DenseM_t | fit_HSS (std::vector< scalar_t > &labels, const HSS::HSSOptions< scalar_t > &opts) |
std::vector< scalar_t > | predict (const DenseM_t &test, const DenseM_t &weights) const |
DistM_t | fit_HSS (const BLACSGrid &grid, std::vector< scalar_t > &labels, const HSS::HSSOptions< scalar_t > &opts) |
std::vector< scalar_t > | predict (const DenseM_t &test, const DistM_t &weights) const |
DenseM_t | fit_HODLR (const MPIComm &c, std::vector< scalar_t > &labels, const HODLR::HODLROptions< scalar_t > &opts) |
const DenseM_t & | data () const |
DenseM_t & | data () |
std::vector< int > & | permutation () |
const std::vector< int > & | permutation () const |
virtual void | permute () |
Representation of a kernel matrix.
This is an abstract class. This class contains a reference to the datapoints representing the kernel: X. X is a d x n matrix (d features and n datapoints).
The actual kernel function is implemented in one of the subclasses of this class. Subclasses need to implement the purely virtual function eval_kernel_function.
scalar_t | Scalar type of the input data points and the kernel representation. Can be float, double, std::complex<float> or std::complex<double>. |
|
inline |
Kernel matrix constructor.
data | Contains the data points, 1 datapoint per column. So the number of rows of data is the number of features, the number of columns of data will be the size of the kernel matrix. |
lambda | regularization parameter, added to the diagonal. |
|
virtualdefault |
Default constructor.
|
inline |
|
inline |
Returns a reference to the data used to define this kernel.
|
inline |
Returns a (const) reference to the data used to define this kernel.
|
inlinevirtual |
Evaluate an entry of the kernel matrix.
i | row coordinate of entry to evaluate |
j | column coordinate of entry to evaluate |
Reimplemented in strumpack::kernel::DenseKernel< scalar_t >.
DenseM_t strumpack::kernel::Kernel< scalar_t >::fit_HODLR | ( | const MPIComm & | c, |
std::vector< scalar_t > & | labels, | ||
const HODLR::HODLROptions< scalar_t > & | opts | ||
) |
Compute weights for kernel ridge regression classification. This will build an approximate HODLR representation of the kernel matrix and use that to solve a linear system with the kernel matrix and the weights vector as the right-hand side. The weights can then later be used in the predict() method for prediction. The data associated to this kernel, and the labels, will get permuted.
TODO labels should be a vector of bool's or int's??
c | MPI communicator on which to perform the calculation |
labels | Binary labels, supposed to be in {-1, 1}. Should be labels.size() == this->n(). |
opts | HSS options |
DistM_t strumpack::kernel::Kernel< scalar_t >::fit_HSS | ( | const BLACSGrid & | grid, |
std::vector< scalar_t > & | labels, | ||
const HSS::HSSOptions< scalar_t > & | opts | ||
) |
Compute weights for kernel ridge regression classification. This will build an approximate HSS representation of the kernel matrix and use that to solve a linear system with the kernel matrix and the weights vector as the right-hand side. The weights can then later be used in the predict() method for prediction. The data associated to this kernel, and the labels, will get permuted.
TODO labels should be a vector of bool's or int's??
grid | Processor grid to use for the MPI distributed computations |
labels | Binary labels, supposed to be in {-1, 1}. Should be labels.size() == this->n(). |
opts | HSS options |
DenseM_t strumpack::kernel::Kernel< scalar_t >::fit_HSS | ( | std::vector< scalar_t > & | labels, |
const HSS::HSSOptions< scalar_t > & | opts | ||
) |
Compute weights for kernel ridge regression classification. This will build an approximate HSS representation of the kernel matrix and use that to solve a linear system with the kernel matrix and the weights vector as the right-hand side. The weights can then later be used in the predict method for prediction. The data associated to this kernel, and the labels, will get permuted.
TODO labels should be a vector of bool's or int's??
labels | Binary labels, supposed to be in {-1, 1}. Should be labels.size() == this->n(). |
opts | HSS options |
|
inline |
|
inline |
Evaluate multiple entries at once: evaluate the submatrix K(I,J) and put the result in matrix B. This is used in the HSS and HODLR construction algorithms for this kernel.
I | set of row indices of elements to extract |
J | set of col indices of elements to extract |
B | B will be set to K(I,J). Matrix B should be the correct size, ie., B.rows() == I.size() and B.cols() == J.size() |
|
inline |
Evaluate multiple entries at once: evaluate the submatrix K(I,J) and put the result in matrix B. This is used in the HSS and HODLR construction algorithms for this kernel.
I | set of row indices of elements to extract |
J | set of col indices of elements to extract |
B | B will be set to K(I,J). Matrix B should be the correct size, ie., B.rows() == I.size() and B.cols() == J.size() |
std::vector< scalar_t > strumpack::kernel::Kernel< scalar_t >::predict | ( | const DenseM_t & | test, |
const DenseM_t & | weights | ||
) | const |
Return prediction scores for the test points, using the weights computed in fit_HSS() or fit_HODLR().
test | Test data set, should be test.rows() == this->d() |
weights | Weights computed by fit_HSS() or fit_HODLR() |
std::vector< scalar_t > strumpack::kernel::Kernel< scalar_t >::predict | ( | const DenseM_t & | test, |
const DistM_t & | weights | ||
) | const |
Return prediction scores for the test points, using the weights computed in fit_HSS() or fit_HODLR().
test | Test data set, should be test.rows() == this->d() |
weights | Weights computed by fit_HSS() or fit_HODLR() |