yat  0.14.5pre
Public Member Functions | Protected Attributes | List of all members
theplu::yat::classifier::Kernel Class Referenceabstract

Interface Class for Kernels. More...

#include <yat/classifier/Kernel.h>

Inheritance diagram for theplu::yat::classifier::Kernel:
theplu::yat::classifier::Kernel_MEV theplu::yat::classifier::Kernel_SEV

Public Member Functions

 Kernel (const MatrixLookup &data, const KernelFunction &kf, const bool own=false)
 
 Kernel (const MatrixLookupWeighted &data, const KernelFunction &kf, const bool own=false)
 
 Kernel (const Kernel &kernel, const std::vector< size_t > &index)
 
virtual ~Kernel (void)
 Destructor. More...
 
virtual double operator() (const size_t row, const size_t column) const =0
 
const MatrixLookupdata (void) const
 
const MatrixLookupWeighteddata_weighted (void) const
 
double element (const DataLookup1D &vec, const size_t i) const
 
double element (const DataLookupWeighted1D &vec, const size_t i) const
 
virtual const Kernelmake_kernel (const MatrixLookup &, const bool) const =0
 
virtual const Kernelmake_kernel (const MatrixLookupWeighted &, const bool own=false) const =0
 
size_t size (void) const
 number of samples
 
bool weighted (void) const
 

Protected Attributes

const MatrixLookupml_
 underlying data
 
const MatrixLookupWeightedmlw_
 same as data_ if weifghted otherwise a NULL pointer
 
const KernelFunctionkf_
 type of Kernel Function e.g. Gaussian (aka RBF)
 
unsigned int * ref_count_
 
unsigned int * ref_count_w_
 

Detailed Description

Interface Class for Kernels.

Class taking care of the $ NxN $ kernel matrix, where $ N $ is number of samples. Each element in the Kernel corresponds to the scalar product of the corresponding pair of samples. At the time being there are two kinds of kernels. Kernel_SEV that is optimized to be fast and Kernel_MEV that is preferable when dealing with many samples and memory might be a bottleneck. A KernelFunction defines what kind of scalar product the Kernel represents, e.g. a Polynomial Kernel of degree 1 means we are dealing with the ordinary linear scalar product.

Note
If the KernelFunction is destroyed, the Kernel is no longer defined.

Constructor & Destructor Documentation

theplu::yat::classifier::Kernel::Kernel ( const MatrixLookup data,
const KernelFunction kf,
const bool  own = false 
)

Constructor taking the data matrix and KernelFunction as input. Each column in the data matrix corresponds to one sample and the Kernel matrix is built applying the KernelFunction on each pair of columns in the data matrix. If own is set to true, Kernel is owner of underlying data.

Note
Can not handle NaNs. To deal with missing values use constructor taking MatrixLookupWeighted.
theplu::yat::classifier::Kernel::Kernel ( const MatrixLookupWeighted data,
const KernelFunction kf,
const bool  own = false 
)

Constructor taking the data matrix (with weights) and KernelFunction as input. Each column in the data matrix corresponds to one sample and the Kernel matrix is built applying the KernelFunction on each pair of columns in the data matrix. If own is set to true, Kernel is owner of underlying data.

theplu::yat::classifier::Kernel::Kernel ( const Kernel kernel,
const std::vector< size_t > &  index 
)

The new kernel is created using selected features index. Kernel will own its underlying data

virtual theplu::yat::classifier::Kernel::~Kernel ( void  )
virtual

Destructor.

If Kernel is owner of underlying data and Kernel is the last owner, underlying data is deleted.

Member Function Documentation

const MatrixLookup& theplu::yat::classifier::Kernel::data ( void  ) const
Returns
const reference to the underlying data.
Exceptions
ifdata is weighted
const MatrixLookupWeighted& theplu::yat::classifier::Kernel::data_weighted ( void  ) const
Returns
const reference to the underlying data.
Exceptions
ifdata is unweighted
double theplu::yat::classifier::Kernel::element ( const DataLookup1D vec,
const size_t  i 
) const

Calculates the scalar product (using the KernelFunction) between vector vec and the $ i $ th column in the data matrix.

double theplu::yat::classifier::Kernel::element ( const DataLookupWeighted1D vec,
const size_t  i 
) const

Calculates the weighted scalar product (using the KernelFunction) between vector vec and the $ i $ th column in the data matrix. Using a weight vector with all elements equal to unity yields same result as the non-weighted version above.

virtual const Kernel* theplu::yat::classifier::Kernel::make_kernel ( const MatrixLookup ,
const bool   
) const
pure virtual

An interface for making new classifier objects. This function allows for specification at run-time of which kernel to instatiate (see 'Prototype' in Design Patterns).

Note
Returns a dynamically allocated Kernel, which has to be deleted by the caller to avoid memory leaks.

Implemented in theplu::yat::classifier::Kernel_MEV, and theplu::yat::classifier::Kernel_SEV.

virtual const Kernel* theplu::yat::classifier::Kernel::make_kernel ( const MatrixLookupWeighted ,
const bool  own = false 
) const
pure virtual

An interface for making new classifier objects. This function allows for specification at run-time of which kernel to instatiate (see 'Prototype' in Design Patterns).

Note
Returns a dynamically allocated Kernel, which has to be deleted by the caller to avoid memory leaks.

Implemented in theplu::yat::classifier::Kernel_MEV, and theplu::yat::classifier::Kernel_SEV.

virtual double theplu::yat::classifier::Kernel::operator() ( const size_t  row,
const size_t  column 
) const
pure virtual
Returns
element at position (row, column) of the Kernel matrix

Implemented in theplu::yat::classifier::Kernel_SEV, and theplu::yat::classifier::Kernel_MEV.

bool theplu::yat::classifier::Kernel::weighted ( void  ) const
Returns
true if kernel is calculated using weights

Member Data Documentation

unsigned int* theplu::yat::classifier::Kernel::ref_count_
protected

pointer telling how many owners to underlying data (data_). NULL if this is not an owner.

unsigned int* theplu::yat::classifier::Kernel::ref_count_w_
protected

pointer telling how many owners to underlying weights (data_w_). NULL if this is not an owner.


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

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5