strumpack::kernel::Kernel< scalar_t > Class Template Referenceabstract

Representation of a kernel matrix. More...

#include <Kernel.hpp>

Inheritance diagram for strumpack::kernel::Kernel< scalar_t >:

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_tdata () const
 
DenseM_tdata ()
 
std::vector< int > & permutation ()
 
const std::vector< int > & permutation () const
 
virtual void permute ()
 

Detailed Description

template<typename scalar_t>
class strumpack::kernel::Kernel< scalar_t >

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.

Template Parameters
scalar_tScalar type of the input data points and the kernel representation. Can be float, double, std::complex<float> or std::complex<double>.

Constructor & Destructor Documentation

◆ Kernel()

template<typename scalar_t >
strumpack::kernel::Kernel< scalar_t >::Kernel ( DenseM_t data,
scalar_t  lambda 
)
inline

Kernel matrix constructor.

Parameters
dataContains 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.
lambdaregularization parameter, added to the diagonal.

◆ ~Kernel()

template<typename scalar_t >
virtual strumpack::kernel::Kernel< scalar_t >::~Kernel ( )
virtualdefault

Default constructor.

Member Function Documentation

◆ d()

template<typename scalar_t >
std::size_t strumpack::kernel::Kernel< scalar_t >::d ( ) const
inline

Return the dimension of the datapoints defining the kernel.

Returns
dimension of the datapoints
See also
n(), data()

◆ data() [1/2]

template<typename scalar_t >
DenseM_t& strumpack::kernel::Kernel< scalar_t >::data ( )
inline

Returns a reference to the data used to define this kernel.

Returns
reference to the datapoint, a matrix of size d x n.

◆ data() [2/2]

template<typename scalar_t >
const DenseM_t& strumpack::kernel::Kernel< scalar_t >::data ( ) const
inline

Returns a (const) reference to the data used to define this kernel.

Returns
const reference to the datapoint, a matrix of size d x n.

◆ eval()

template<typename scalar_t >
virtual scalar_t strumpack::kernel::Kernel< scalar_t >::eval ( std::size_t  i,
std::size_t  j 
) const
inlinevirtual

Evaluate an entry of the kernel matrix.

Parameters
irow coordinate of entry to evaluate
jcolumn coordinate of entry to evaluate
Returns
the value K(i, j) of the kernel

Reimplemented in strumpack::kernel::DenseKernel< scalar_t >.

◆ fit_HODLR()

template<typename 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??

Parameters
cMPI communicator on which to perform the calculation
labelsBinary labels, supposed to be in {-1, 1}. Should be labels.size() == this->n().
optsHSS options
Returns
A vector with scalar weights, to be used in predict()
See also
predict, fit_HSS

◆ fit_HSS() [1/2]

template<typename scalar_t >
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??

Parameters
gridProcessor grid to use for the MPI distributed computations
labelsBinary labels, supposed to be in {-1, 1}. Should be labels.size() == this->n().
optsHSS options
Returns
A distributed vector with scalar weights, to be used in predict(), distributed on the BLACSGrid grid.
See also
predict, fit_HODLR

◆ fit_HSS() [2/2]

template<typename scalar_t >
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??

Parameters
labelsBinary labels, supposed to be in {-1, 1}. Should be labels.size() == this->n().
optsHSS options
Returns
A vector (1 column matrix) with scalar weights, to be used in predict
See also
predict, fit_HODLR

◆ n()

template<typename scalar_t >
std::size_t strumpack::kernel::Kernel< scalar_t >::n ( ) const
inline

Returns the size of the (square) kernel matrix. This is the number of datapoints in the set data().

See also
d(), data()

◆ operator()() [1/2]

template<typename scalar_t >
void strumpack::kernel::Kernel< scalar_t >::operator() ( const std::vector< std::size_t > &  I,
const std::vector< std::size_t > &  J,
DenseMatrix< real_t > &  B 
) const
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.

Parameters
Iset of row indices of elements to extract
Jset of col indices of elements to extract
BB will be set to K(I,J). Matrix B should be the correct size, ie., B.rows() == I.size() and B.cols() == J.size()

◆ operator()() [2/2]

template<typename scalar_t >
void strumpack::kernel::Kernel< scalar_t >::operator() ( const std::vector< std::size_t > &  I,
const std::vector< std::size_t > &  J,
DenseMatrix< std::complex< real_t >> &  B 
) const
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.

Parameters
Iset of row indices of elements to extract
Jset of col indices of elements to extract
BB will be set to K(I,J). Matrix B should be the correct size, ie., B.rows() == I.size() and B.cols() == J.size()

◆ predict() [1/2]

template<typename scalar_t >
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().

Parameters
testTest data set, should be test.rows() == this->d()
weightsWeights computed by fit_HSS() or fit_HODLR()
Returns
Vector with prediction scores. One can use the sign (threshold zero), to decide which of 2 classes each test point belongs to.
See also
fit_HSS, fit_HODLR

◆ predict() [2/2]

template<typename scalar_t >
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().

Parameters
testTest data set, should be test.rows() == this->d()
weightsWeights computed by fit_HSS() or fit_HODLR()
Returns
Vector with prediction scores. One can use the sign (threshold zero), to decide which of 2 classes each test point belongs to.
See also
fit_HSS, fit_HODLR

The documentation for this class was generated from the following file: