yat  0.16pre
Public Types | Public Member Functions | List of all members
theplu::yat::classifier::KernelLookup Class Reference

Lookup into Kernel. More...

#include <yat/classifier/KernelLookup.h>

Public Types

typedef double value_type
 
typedef const double const_reference
 
typedef utility::StrideIterator< utility::Container2DIterator< const KernelLookup, const double, const_reference > > const_iterator
 'Read Only' iterator
 
typedef const_iterator const_column_iterator
 
typedef const_iterator const_row_iterator
 

Public Member Functions

 KernelLookup (const Kernel &kernel, const bool owner=false)
 Constructor a Lookup into a Kernel. More...
 
 KernelLookup (const Kernel &kernel, const utility::Index &row, const utility::Index &column, const bool owner=false)
 Constructing a Lookup into a subKernel. More...
 
 KernelLookup (const KernelLookup &kl)
 Copy constructor. More...
 
 KernelLookup (const KernelLookup &kl, const utility::Index &row, const utility::Index &column)
 Contructing a sub-KernelLookup. More...
 
 KernelLookup (const KernelLookup &kl, const utility::Index &, const bool row=false)
 
virtual ~KernelLookup (void)
 Destructor. More...
 
const_iterator begin (void) const
 
const_column_iterator begin_column (size_t) const
 
const_row_iterator begin_row (size_t) const
 
size_t columns (void) const
 
MatrixLookup data (void) const
 
MatrixLookupWeighted data_weighted (void) const
 
double element (const DataLookup1D &vec, size_t i) const
 
double element (const DataLookupWeighted1D &vec, size_t i) const
 
const_iterator end (void) const
 
const_column_iterator end_column (size_t) const
 
const_row_iterator end_row (size_t) const
 
size_t rows (void) const
 
KernelLookup selected (const utility::Index &index) const
 
KernelLookup test_kernel (const MatrixLookup &data) const
 
KernelLookup test_kernel (const MatrixLookupWeighted &data) const
 
bool weighted (void) const
 
const_reference operator() (size_t row, size_t column) const
 

Detailed Description

Lookup into Kernel.

This is the KernelLookup class to be used together with kernel methods such as Support Vector Machines (SVM). The class does not contain any data or values, but rather is a lookup into a Kernel object. Each row and each column corresponds to a row and a column in the Kernel, respectively. This design allows for fast creation of sub-kernels, which is a common operation in most traning/validation procedures.

A KernelLookup can be created directly from a Kernel or from another KernelLookup. In the latter case, the resulting KernelLookup is looking directly into the underlying Kernel to avoid multiple lookups.

There is a possibility to set the KernelLookup as owner of the underlying kernel. This implies that underlying kernel is deleted in destructor of MatrixLookup, but only if there is no other owner of the underlying kernel. A reference counter is used to keep track of number of owners. Ownership is copied in copy constructors and assignments.

Member Typedef Documentation

'Read only' iterator intended to iterate over a column

const_reference type is const double

Since
New in yat 0.5

'Read only' iterator intended to iterate over a row

value_type is double

Since
New in yat 0.5

Constructor & Destructor Documentation

theplu::yat::classifier::KernelLookup::KernelLookup ( const Kernel kernel,
const bool  owner = false 
)

Constructor a Lookup into a Kernel.

Constructs a KernelLookup corresponding to the Kernel kernel. By default owner is set to false, which means KernelLookup does not own the underlying Kernel.

Note
If underlying Kernel goes out of scope or is deleted, the KernelLookup becomes invalid and the result of further use is undefined.
Do not construct two KernelLookups from the same kernel with owner set to true because that will cause multiple deletion of kernel.
theplu::yat::classifier::KernelLookup::KernelLookup ( const Kernel kernel,
const utility::Index row,
const utility::Index column,
const bool  owner = false 
)

Constructing a Lookup into a subKernel.

Creating a Lookup into parts of the Kernel. In the created Lookup the element in the $ i $ th row in the $ j $ th column is identical to the element in row row[i] and columns column[j] in the underlying kernel. If owner is set to true yhe underlying kernel is destroyed in the destructor.

Note
If kernel goes out of scope or is deleted, the returned pointer becomes invalid and the result of further use is undefined.
For training usage row index shall always be equal to column index.
theplu::yat::classifier::KernelLookup::KernelLookup ( const KernelLookup kl)

Copy constructor.

A Lookup is created looking into the same underlying Kernel as kl is looking into.

If kl is owner of underlying data, constructed KernelLookup will also be set as owner of underlying data.

theplu::yat::classifier::KernelLookup::KernelLookup ( const KernelLookup kl,
const utility::Index row,
const utility::Index column 
)

Contructing a sub-KernelLookup.

Contructor building a sub-KernelLookup from a KernelLookup defined by row index vector and column index vector. In the created Lookup the element in the $ i $ th row in the $ j $ th column is identical to the element in row row[i] and columns column[j] in the copied kl. The resulting KernelLookup is independent of the old KernelLookup, but is undefined in case underlying Kernel is destroyed.

If kl is owner of underlying data, constructed KernelLookup will also be set as owner of underlying data.

Note
For training usage row index shall always be equal to column index.
theplu::yat::classifier::KernelLookup::KernelLookup ( const KernelLookup kl,
const utility::Index ,
const bool  row = false 
)

Constructor taking the column (default) or row index as input. If row is false the created KernelLookup will have equally many rows as kernel.

If kl is owner of underlying data, constructed KernelLookup will also be set as owner of underlying data.

Note
If underlying kernel goes out of scope or is deleted, the KernelLookup becomes invalid and the result of further use is undefined.
virtual theplu::yat::classifier::KernelLookup::~KernelLookup ( void  )
virtual

Destructor.

Deletes underlying Kernel if KernelLookup owns it and there is no other owner.

Member Function Documentation

const_iterator theplu::yat::classifier::KernelLookup::begin ( void  ) const

Iterator iterates along a row. When end of row is reached it jumps to beginning of next row.

Returns
const_iterator pointing to upper-left element.
const_column_iterator theplu::yat::classifier::KernelLookup::begin_column ( size_t  ) const

Iterator iterates along a column.

Returns
iterator pointing to first element of column i.
const_row_iterator theplu::yat::classifier::KernelLookup::begin_row ( size_t  ) const

Iterator iterates along a column.

Returns
const_iterator pointing to first element of column i.
size_t theplu::yat::classifier::KernelLookup::columns ( void  ) const
Returns
number of columns
MatrixLookup theplu::yat::classifier::KernelLookup::data ( void  ) const

Each column in returned DataLookup corresponds to the column in KernelLookup.

Returns
data that KernelLookup is built upon.
Exceptions
ifKernelLookup is weighted
MatrixLookupWeighted theplu::yat::classifier::KernelLookup::data_weighted ( void  ) const

Each column in returned DataLookup corresponds to the column in KernelLookup.

Returns
data that KernelLookup is built upon.
Exceptions
ifKernelLookup is unweighted
double theplu::yat::classifier::KernelLookup::element ( const DataLookup1D vec,
size_t  i 
) const

Function to calculate a new Kernel element using the underlying KernelFunction. The value is calculated between vec and the data vector of the i th sample, in other words, the sample corresponding to the i th row.

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

Function to calculate a new Kernel element using the underlying KernelFunction. The value is calulated between vec and the data vector of the $ i $ th sample, in other words, the sample corresponding to the $ i $ th row or $ i $ th column. In case KernelLookup is a sub-Kernel and not symmetric, the kernel value is calculated between vec and the data vector corresponding to $ i $ th row.

const_iterator theplu::yat::classifier::KernelLookup::end ( void  ) const
Returns
const_iterator pointing to end of matrix
const_column_iterator theplu::yat::classifier::KernelLookup::end_column ( size_t  ) const
Returns
const_iterator pointing to end of column i
const_row_iterator theplu::yat::classifier::KernelLookup::end_row ( size_t  ) const
Returns
const_iterator pointing to end of row i
const_reference theplu::yat::classifier::KernelLookup::operator() ( size_t  row,
size_t  column 
) const
Returns
element at position (row, column) in the Kernel matrix
size_t theplu::yat::classifier::KernelLookup::rows ( void  ) const
Returns
number of rows
KernelLookup theplu::yat::classifier::KernelLookup::selected ( const utility::Index index) const

Each element in returned KernelLookup is calculated using only selected features (defined by index). Each element corresponds to the same pair of samples as in the original KernelLookup.

KernelLookup theplu::yat::classifier::KernelLookup::test_kernel ( const MatrixLookup data) const

This function is useful when predicting on an independent data set using a kernel-based classifier. In returned KernelLookup column $ i $ corresponds to column $ i $ in data. Row $ i $ in returned KernelLookup corresponds to same sample as row $ i $ in this. In other words, this function returns a KernelLookup containing the kernel elements between the passed data and the internal underlying data this was built from.

KernelLookup theplu::yat::classifier::KernelLookup::test_kernel ( const MatrixLookupWeighted data) const

This function is useful when predicting on an independent data set using a kernel-based classifier. In returned KernelLookup column $ i $ corresponds to column $ i $ in data. Row $ i $ in returned KernelLookup corresponds to same sample as row $ i $ in this. In other words, this function returns a KernelLookup containing the kernel elements between the passed data and the internal underlying data this was built from.

bool theplu::yat::classifier::KernelLookup::weighted ( void  ) const
Returns
true if underlying Kernel is weighted

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

Generated on Wed May 23 2018 02:32:35 for yat by  doxygen 1.8.11