Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <shogun/lib/common.h>
00012 #include <shogun/kernel/CustomKernel.h>
00013 #include <shogun/features/Features.h>
00014 #include <shogun/features/DummyFeatures.h>
00015 #include <shogun/io/SGIO.h>
00016
00017 using namespace shogun;
00018
00019 void
00020 CCustomKernel::init(void)
00021 {
00022 m_parameters->add(&kmatrix, "kmatrix", "Kernel matrix.");
00023 m_parameters->add(&upper_diagonal, "upper_diagonal");
00024 }
00025
00026 CCustomKernel::CCustomKernel()
00027 : CKernel(10), kmatrix(), upper_diagonal(false)
00028 {
00029 init();
00030 }
00031
00032 CCustomKernel::CCustomKernel(CKernel* k)
00033 : CKernel(10)
00034 {
00035 set_full_kernel_matrix_from_full(k->get_kernel_matrix());
00036 }
00037
00038 CCustomKernel::CCustomKernel(SGMatrix<float64_t> km)
00039 : CKernel(10), upper_diagonal(false)
00040 {
00041 init();
00042 set_full_kernel_matrix_from_full(km);
00043 }
00044
00045 CCustomKernel::~CCustomKernel()
00046 {
00047 cleanup();
00048 }
00049
00050 bool CCustomKernel::dummy_init(int32_t rows, int32_t cols)
00051 {
00052 return init(new CDummyFeatures(rows), new CDummyFeatures(cols));
00053 }
00054
00055 bool CCustomKernel::init(CFeatures* l, CFeatures* r)
00056 {
00057 CKernel::init(l, r);
00058
00059 SG_DEBUG( "num_vec_lhs: %d vs num_rows %d\n", l->get_num_vectors(), kmatrix.num_rows);
00060 SG_DEBUG( "num_vec_rhs: %d vs num_cols %d\n", r->get_num_vectors(), kmatrix.num_cols);
00061 ASSERT(l->get_num_vectors()==kmatrix.num_rows);
00062 ASSERT(r->get_num_vectors()==kmatrix.num_cols);
00063 return init_normalizer();
00064 }
00065
00066 void CCustomKernel::cleanup_custom()
00067 {
00068 SG_DEBUG("cleanup up custom kernel\n");
00069 SG_FREE(kmatrix.matrix);
00070 kmatrix.matrix=NULL;
00071 upper_diagonal=false;
00072 kmatrix.num_cols=0;
00073 kmatrix.num_rows=0;
00074 }
00075
00076 void CCustomKernel::cleanup()
00077 {
00078 cleanup_custom();
00079 CKernel::cleanup();
00080 }
00081