yat
0.14.5pre
|
#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 |
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.
'Read only' iterator intended to iterate over a column
typedef const double theplu::yat::classifier::KernelLookup::const_reference |
const_reference type is const double
'Read only' iterator intended to iterate over a row
typedef double theplu::yat::classifier::KernelLookup::value_type |
value_type is double
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.
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 th row in the 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.
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 th row in the 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.
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.
|
virtual |
Destructor.
Deletes underlying Kernel if KernelLookup owns it and there is no other owner.
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.
const_column_iterator theplu::yat::classifier::KernelLookup::begin_column | ( | size_t | ) | const |
Iterator iterates along a column.
const_row_iterator theplu::yat::classifier::KernelLookup::begin_row | ( | size_t | ) | const |
Iterator iterates along a column.
size_t theplu::yat::classifier::KernelLookup::columns | ( | void | ) | const |
MatrixLookup theplu::yat::classifier::KernelLookup::data | ( | void | ) | const |
Each column in returned DataLookup corresponds to the column in KernelLookup.
if | KernelLookup is weighted |
MatrixLookupWeighted theplu::yat::classifier::KernelLookup::data_weighted | ( | void | ) | const |
Each column in returned DataLookup corresponds to the column in KernelLookup.
if | KernelLookup 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 th sample, in other words, the sample corresponding to the th row or 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 th row.
const_iterator theplu::yat::classifier::KernelLookup::end | ( | void | ) | const |
const_column_iterator theplu::yat::classifier::KernelLookup::end_column | ( | size_t | ) | const |
const_row_iterator theplu::yat::classifier::KernelLookup::end_row | ( | size_t | ) | const |
const_reference theplu::yat::classifier::KernelLookup::operator() | ( | size_t | row, |
size_t | column | ||
) | const |
size_t theplu::yat::classifier::KernelLookup::rows | ( | void | ) | const |
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 corresponds to column in data. Row in returned KernelLookup corresponds to same sample as row 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 corresponds to column in data. Row in returned KernelLookup corresponds to same sample as row 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 |