36 using namespace shogun;
73 SG_ERROR(
"Kernel still initialized on destruction.\n")
78 SG_INFO(
"Kernel deleted (%p).\n",
this)
90 REQUIRE(l,
"CKernel::init(%p, %p): Left hand side features required!\n", l, r)
91 REQUIRE(r,
"CKernel::init(%p, %p): Right hand side features required!\n", l, r)
120 SG_DEBUG(
"leaving CKernel::init(%p, %p)\n", l, r)
170 SG_DEBUG(
"entering CKernel::remove_lhs_and_rhs\n")
182 SG_DEBUG(
"leaving CKernel::remove_lhs_and_rhs\n")
208 #define ENUM_CASE(n) case n: SG_INFO(#n " ") break;
215 "SLOWBUTMEMEFFICIENT");
327 int32_t count, int32_t *IDX,
float64_t * weights)
329 SG_ERROR(
"kernel does not support linadd optimization\n")
335 SG_ERROR(
"kernel does not support linadd optimization\n")
341 SG_ERROR(
"kernel does not support linadd optimization\n")
346 int32_t num_vec, int32_t* vec_idx,
float64_t* target, int32_t num_suppvec,
349 SG_ERROR(
"kernel does not support batch computation\n")
354 SG_ERROR(
"kernel does not support linadd optimization, add_to_normal not implemented\n")
359 SG_ERROR(
"kernel does not support linadd optimization, clear_normal not implemented\n")
368 int32_t vector_idx,
float64_t * subkernel_contrib)
370 SG_ERROR(
"kernel compute_by_subkernel not implemented\n")
390 SG_ERROR(
"number of subkernel weights should be one ...\n")
400 REQUIRE(casted,
"CKernel::obtain_from_generic(): Error, provided object"
401 " of class \"%s\" is not a subclass of CKernel!\n",
412 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
415 for (int32_t i=0; i<num_suppvec; i++)
459 SG_ADD(&
num_lhs,
"num_lhs",
"Number of feature vectors on left hand side.",
461 SG_ADD(&
num_rhs,
"num_rhs",
"Number of feature vectors on right hand side.",
531 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
533 "Invalid block size (%d) at starting index (%d, %d)! "
534 "Please use smaller blocks!", block_size, block_begin, block_begin)
535 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
542 #pragma omp parallel for
543 for (
index_t i=0; i<block_size; ++i)
547 for (
index_t j=i+1; j<block_size; ++j)
562 #pragma omp parallel for
563 for (
index_t i=0; i<block_size; ++i)
583 block_begin_col>=0 && block_begin_col<
num_rhs,
584 "Invalid block begin index (%d, %d)!\n",
585 block_begin_row, block_begin_col)
587 block_begin_col+block_size_col<=
num_rhs,
588 "Invalid block size (%d, %d) at starting index (%d, %d)! "
589 "Please use smaller blocks!", block_size_row, block_size_col,
590 block_begin_row, block_begin_col)
591 REQUIRE(block_size_row>=1 && block_size_col>=1,
592 "Invalid block size (%d, %d)!\n", block_size_row, block_size_col)
595 if (no_diag && block_size_row!=block_size_col)
597 SG_WARNING(
"Not removing the main diagonal since block is not square!\n");
604 #pragma omp parallel for
605 for (
index_t i=0; i<block_size_row; ++i)
608 for (
index_t j=0; j<block_size_col; ++j)
611 kernel(i+block_begin_row, j+block_begin_col);
623 index_t block_size,
bool no_diag)
630 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
632 "Invalid block size (%d) at starting index (%d, %d)! "
633 "Please use smaller blocks!", block_size, block_begin, block_begin)
634 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
643 #pragma omp parallel for
644 for (
index_t i=0; i<block_size; ++i)
648 for (
index_t j=i+1; j<block_size; ++j)
663 #pragma omp parallel for
664 for (
index_t i=0; i<block_size; ++i)
677 block_begin,
index_t block_size,
bool no_diag)
684 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
686 "Invalid block size (%d) at starting index (%d, %d)! "
687 "Please use smaller blocks!", block_size, block_begin, block_begin)
688 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
699 #pragma omp parallel for
700 for (
index_t i=0; i<block_size; ++i)
704 for (
index_t j=i+1; j<block_size; ++j)
721 #pragma omp parallel for
722 for (
index_t i=0; i<block_size; ++i)
726 row_sum(i, 1)+=diag*diag;
737 index_t block_size_col,
bool no_diag)
743 block_begin_col>=0 && block_begin_col<
num_rhs,
744 "Invalid block begin index (%d, %d)!\n",
745 block_begin_row, block_begin_col)
747 block_begin_col+block_size_col<=
num_rhs,
748 "Invalid block size (%d, %d) at starting index (%d, %d)! "
749 "Please use smaller blocks!", block_size_row, block_size_col,
750 block_begin_row, block_begin_col)
751 REQUIRE(block_size_row>=1 && block_size_col>=1,
752 "Invalid block size (%d, %d)!\n", block_size_row, block_size_col)
755 if (no_diag && block_size_row!=block_size_col)
757 SG_WARNING(
"Not removing the main diagonal since block is not square!\n");
768 #pragma omp parallel for
769 for (
index_t i=0; i<block_size_row; ++i)
772 for (
index_t j=0; j<block_size_col; ++j)
775 kernel(i+block_begin_row, j+block_begin_col);
779 sum[j+block_size_row]+=k;
792 int32_t i_start=params->
start;
793 int32_t i_end=params->
end;
802 int64_t total=total_start;
804 for (int32_t i=i_start; i<i_end; i++)
811 for (int32_t j=j_start; j<n; j++)
816 if (symmetric && i!=j)
823 if (symmetric && i!=j)
849 int64_t total_num = int64_t(m)*n;
852 bool symmetric= (
lhs &&
lhs==
rhs && m==n);
854 SG_DEBUG(
"returning kernel matrix of size %dx%d\n", m, n)
856 result=SG_MALLOC(T, total_num);
872 get_kernel_matrix_helper<T>((
void*) ¶ms);
876 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
878 int64_t step= total_num/num_threads;
883 for (t=0; t<num_threads; t++)
886 params[t].
result = result;
896 int code=pthread_create(&threads[t], NULL,
897 CKernel::get_kernel_matrix_helper<T>, (
void*)¶ms[t]);
901 SG_WARNING(
"Thread creation failed (thread %d of %d) "
902 "with error:'%s'\n",t, num_threads, strerror(code));
909 params[t].
result = result;
918 get_kernel_matrix_helper<T>(¶ms[t]);
920 for (t=0; t<num_threads; t++)
922 if (pthread_join(threads[t], NULL) != 0)
923 SG_WARNING(
"pthread_join of thread %d/%d failed\n", t, num_threads)
938 template void* CKernel::get_kernel_matrix_helper<float64_t>(
void* p);
939 template void* CKernel::get_kernel_matrix_helper<float32_t>(
void* p);
virtual void clear_normal()
virtual const char * get_name() const =0
virtual void load_serializable_post()
virtual bool init(CFeatures *lhs, CFeatures *rhs)
int32_t get_num_support_vectors()
int32_t compute_row_start(int64_t offs, int32_t n, bool symmetric)
virtual void set_matrix(const bool *matrix, int32_t num_feat, int32_t num_vec)
virtual void compute_by_subkernel(int32_t vector_idx, float64_t *subkernel_contrib)
int32_t get_num_threads() const
int32_t num_rhs
number of feature vectors on right hand side
static void * get_kernel_matrix_helper(void *p)
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
virtual bool set_normalizer(CKernelNormalizer *normalizer)
virtual float64_t sum_block(index_t block_begin_row, index_t block_begin_col, index_t block_size_row, index_t block_size_col, bool no_diag=false)
virtual int32_t get_num_vectors() const =0
virtual void save_serializable_pre()
virtual bool delete_optimization()
float64_t kernel(int32_t idx_a, int32_t idx_b)
virtual void remove_rhs()
takes all necessary steps if the rhs is removed from kernel
virtual int32_t get_num_vec_lhs()
SGMatrix< float64_t > get_kernel_matrix()
int32_t cache_size
cache_size in MB
bool get_is_initialized()
virtual SGMatrix< float64_t > row_wise_sum_squared_sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
float64_t combined_kernel_weight
virtual void register_params()
virtual void remove_lhs_and_rhs()
virtual CKernelNormalizer * get_normalizer()
Class SGObject is the base class of all shogun objects.
virtual SGVector< float64_t > row_col_wise_sum_block(index_t block_begin_row, index_t block_begin_col, index_t block_size_row, index_t block_size_col, bool no_diag=false)
#define SG_OBJ_PROGRESS(o,...)
virtual float64_t sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
virtual SGVector< float64_t > get_subkernel_weights()
virtual EFeatureType get_feature_type()=0
KERNELCACHE_ELEM * kernel_matrix
A File access base class.
virtual void save_serializable_post()
virtual float64_t compute_optimized(int32_t vector_idx)
EOptimizationType get_optimization_type()
virtual void save_serializable_post()
float64_t get_alpha(int32_t idx)
float64_t get_combined_kernel_weight()
virtual SGVector< float64_t > row_wise_sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
virtual EFeatureClass get_feature_class() const =0
Identity Kernel Normalization, i.e. no normalization is applied.
int32_t num_lhs
number of feature vectors on left hand side
The class Kernel Normalizer defines a function to post-process kernel values.
int32_t get_support_vector(int32_t idx)
static bool cancel_computations()
virtual int32_t get_num_vec_rhs()
virtual void set_subkernel_weights(SGVector< float64_t > weights)
void set_const(T const_elem)
virtual bool init_normalizer()
bool optimization_initialized
EOptimizationType opt_type
virtual void load_serializable_post()
CFeatures * rhs
feature vectors to occur on right hand side
static CKernel * obtain_from_generic(CSGObject *kernel)
virtual bool init(CKernel *k)=0
virtual void compute_batch(int32_t num_vec, int32_t *vec_idx, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *alphas, float64_t factor=1.0)
virtual EKernelType get_kernel_type()=0
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *weights)
CFeatures * lhs
feature vectors to occur on left hand side
The class Features is the base class of all feature objects.
virtual void save_serializable_pre()
virtual void remove_lhs()
virtual int32_t get_num_subkernels()
bool init_optimization_svm(CSVM *svm)
A generic Support Vector Machine Interface.
CKernelNormalizer * normalizer
void set_const(T const_elem)
virtual bool has_features()
virtual void add_to_normal(int32_t vector_idx, float64_t weight)
virtual EFeatureType get_feature_type() const =0
virtual EFeatureClass get_feature_class()=0