29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 struct S_THREAD_PARAM_COMBINED_KERNEL
42 #endif // DOXYGEN_SHOULD_SKIP_THIS
45 :
CKernel(size), append_subkernel_weights(asw)
50 SG_INFO(
"(subkernel weights are appended)\n")
52 SG_INFO(
"Combined kernel created (%p)\n",
this)
63 SG_INFO(
"Combined kernel deleted (%p).\n",
this)
74 SG_DEBUG(
"Initialising combined kernel's combined features with the "
75 "same instance from parameters\n");
86 return init(combined_l, combined_r);
91 " of class %s but need to be combined features!\n",
94 " of class %s but need to be combined features!\n",
106 SG_DEBUG(
"Starting for loop for kernels\n")
112 SG_ERROR(
"Kernel at position %d is NULL\n", k_idx);
125 SG_ERROR(
"CombinedKernel: Number of features/kernels does not match - bailing out\n")
129 result=k->
init(lf,rf);
138 SG_DEBUG(
"Initializing 0x%p - \"%s\" (skipping init, this is a CUSTOM kernel)\n",
this, k->
get_name())
140 SG_ERROR(
"No kernel matrix was assigned to this Custom kernel\n")
152 SG_INFO(
"CombinedKernel: Initialising the following kernel failed\n")
165 SG_ERROR(
"CombinedKernel: Number of features/kernels does not match - bailing out\n")
244 SG_INFO(
"BEGIN COMBINED KERNEL LIST - ")
253 SG_INFO(
"END COMBINED KERNEL LIST - ")
271 int32_t count, int32_t *IDX,
float64_t *weights)
273 SG_DEBUG(
"initializing CCombinedKernel optimization\n")
277 bool have_non_optimizable=
false;
289 SG_WARNING(
"non-optimizable kernel 0x%X in kernel-list\n", k)
290 have_non_optimizable=
true;
295 have_non_optimizable=
true;
296 SG_WARNING(
"init_optimization of kernel 0x%X failed\n", k)
302 if (have_non_optimizable)
304 SG_WARNING(
"some kernels in the kernel-list are not optimized\n")
306 sv_idx=SG_MALLOC(int32_t, count);
309 for (int32_t i=0; i<count; i++)
344 int32_t num_vec, int32_t* vec_idx,
float64_t* result, int32_t num_suppvec,
376 S_THREAD_PARAM_COMBINED_KERNEL* params= (S_THREAD_PARAM_COMBINED_KERNEL*) p;
377 int32_t* vec_idx=params->vec_idx;
381 for (int32_t i=params->start; i<params->end; i++)
389 S_THREAD_PARAM_COMBINED_KERNEL* params= (S_THREAD_PARAM_COMBINED_KERNEL*) p;
390 int32_t* vec_idx=params->vec_idx;
394 int32_t* IDX=params->IDX;
395 int32_t num_suppvec=params->num_suppvec;
397 for (int32_t i=params->start; i<params->end; i++)
400 for (int32_t j=0; j<num_suppvec; j++)
401 sub_result += weights[j] * k->
kernel(IDX[j], vec_idx[i]);
411 int32_t num_suppvec, int32_t* IDX,
float64_t* weights)
427 S_THREAD_PARAM_COMBINED_KERNEL params;
429 params.result=result;
432 params.vec_idx = vec_idx;
438 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
439 S_THREAD_PARAM_COMBINED_KERNEL* params = SG_MALLOC(S_THREAD_PARAM_COMBINED_KERNEL, num_threads);
440 int32_t step= num_vec/num_threads;
444 for (t=0; t<num_threads-1; t++)
446 params[t].kernel = k;
447 params[t].result = result;
448 params[t].start = t*step;
449 params[t].end = (t+1)*step;
450 params[t].vec_idx = vec_idx;
454 params[t].kernel = k;
455 params[t].result = result;
456 params[t].start = t*step;
457 params[t].end = num_vec;
458 params[t].vec_idx = vec_idx;
461 for (t=0; t<num_threads-1; t++)
462 pthread_join(threads[t], NULL);
474 ASSERT(IDX!=NULL || num_suppvec==0)
475 ASSERT(weights!=NULL || num_suppvec==0)
484 S_THREAD_PARAM_COMBINED_KERNEL params;
486 params.result=result;
489 params.vec_idx = vec_idx;
491 params.weights = weights;
492 params.num_suppvec = num_suppvec;
498 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
499 S_THREAD_PARAM_COMBINED_KERNEL* params = SG_MALLOC(S_THREAD_PARAM_COMBINED_KERNEL, num_threads);
500 int32_t step= num_vec/num_threads;
504 for (t=0; t<num_threads-1; t++)
506 params[t].kernel = k;
507 params[t].result = result;
508 params[t].start = t*step;
509 params[t].end = (t+1)*step;
510 params[t].vec_idx = vec_idx;
512 params[t].weights = weights;
513 params[t].num_suppvec = num_suppvec;
517 params[t].kernel = k;
518 params[t].result = result;
519 params[t].start = t*step;
520 params[t].end = num_vec;
521 params[t].vec_idx = vec_idx;
523 params[t].weights = weights;
524 params[t].num_suppvec = num_suppvec;
527 for (t=0; t<num_threads-1; t++)
528 pthread_join(threads[t], NULL);
542 SG_ERROR(
"CCombinedKernel optimization not initialized\n")
604 int32_t idx,
float64_t * subkernel_contrib)
640 SG_DEBUG(
"entering CCombinedKernel::get_subkernel_weights()\n")
648 SG_DEBUG(
"appending kernel weights\n")
657 for (int32_t j=0; j<num; j++)
666 SG_DEBUG(
"not appending kernel weights\n")
678 SG_DEBUG(
"leaving CCombinedKernel::get_subkernel_weights()\n")
688 for (int32_t i=0; i<num; i++)
760 void CCombinedKernel::init()
775 "Support vector index.");
777 "Support vector weights.");
789 if (!strcmp(param->
m_name,
"combined_kernel_weight"))
834 derivative(g,h)*=coeff;
846 result(g,h)+=derivative(g,h);
862 SG_SERROR(
"CCombinedKernel::obtain_from_generic(): provided kernel is "
863 "not of type CGaussianKernel!\n");
882 int32_t num_combinations = 1;
883 int32_t list_index = 0;
892 SG_SERROR(
"CCombinedKernel::combine_kernels() : Failed to cast list of type "
893 "%s to type CList\n", list->
get_name());
898 SG_SERROR(
"CCombinedKernel::combine_kernels() : Sub-list in position %d "
899 "is empty.\n", list_index);
913 for (
index_t i=0; i<num_combinations; ++i)
931 bool first_kernel =
true;
937 first_kernel =
false;
940 SG_SERROR(
"CCombinedKernel::combine_kernels() : Sub-list in position "
941 "0 contains different types of kernels\n");
971 c_list =
dynamic_cast<CList*
>(list);
981 first_kernel =
false;
984 SG_SERROR(
"CCombinedKernel::combine_kernels() : Sub-list in position "
985 "%d contains different types of kernels\n", list_index);
994 for (
index_t index=0; index<freq; ++index)
virtual void clear_normal()
virtual const char * get_name() const =0
virtual void remove_lhs()
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual void remove_rhs()
virtual void compute_by_subkernel(int32_t idx, float64_t *subkernel_contrib)
virtual const char * get_name() const
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)
CSGObject * get_next_element()
virtual void compute_by_subkernel(int32_t vector_idx, float64_t *subkernel_contrib)
virtual void set_subkernel_weights(SGVector< float64_t > weights)
int32_t get_num_threads() const
int32_t num_rhs
number of feature vectors on right hand side
The Custom Kernel allows for custom user provided kernel matrices.
virtual bool init(CFeatures *lhs, CFeatures *rhs)
SGMatrix< float64_t > get_parameter_gradient(const TParameter *param, index_t index=-1)
virtual void clear_normal()
bool append_kernel(CKernel *k)
void set_is_initialized(bool p_init)
virtual bool delete_optimization()
CDynamicObjectArray * kernel_array
float64_t kernel(int32_t idx_a, int32_t idx_b)
virtual void set_optimization_type(EOptimizationType t)
int32_t get_num_subkernels()
virtual void set_optimization_type(EOptimizationType t)
int32_t get_num_kernels()
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()
bool get_is_initialized()
virtual void remove_lhs_and_rhs()
bool has_property(EKernelProperty p)
static void * compute_optimized_kernel_helper(void *p)
CSGObject * get_first_element()
virtual void remove_lhs_and_rhs()
virtual ~CCombinedKernel()
virtual SGVector< float64_t > get_subkernel_weights()
Class SGObject is the base class of all shogun objects.
CKernel * get_kernel(int32_t idx)
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *weights)
void set_combined_kernel_weight(float64_t nw)
virtual float64_t compute(int32_t x, int32_t y)
virtual float64_t compute_optimized(int32_t vector_idx)
float64_t get_combined_kernel_weight()
static CList * combine_kernels(CList *kernel_list)
virtual const float64_t * get_subkernel_weights(int32_t &num_weights)
virtual EFeatureClass get_feature_class() const =0
int32_t get_num_elements()
The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by lin...
static void * compute_kernel_helper(void *p)
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
int32_t num_lhs
number of feature vectors on left hand side
bool append_subkernel_weights
virtual int32_t get_num_vec_rhs()
virtual void set_subkernel_weights(SGVector< float64_t > weights)
virtual bool init_normalizer()
void add_vector(bool **param, index_t *length, const char *name, const char *description="")
all of classes and functions are contained in the shogun namespace
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)
static CCombinedKernel * obtain_from_generic(CKernel *kernel)
virtual EKernelType get_kernel_type()=0
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *weights)
virtual bool delete_optimization()
The class Features is the base class of all feature objects.
bool append_element(CSGObject *data)
virtual SGMatrix< float64_t > get_parameter_gradient(const TParameter *param, index_t index=-1)
virtual void add_to_normal(int32_t idx, float64_t weight)
void emulate_compute_batch(CKernel *k, int32_t num_vec, int32_t *vec_idx, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *weights)
virtual void remove_lhs()
virtual int32_t get_num_subkernels()
virtual float64_t compute_optimized(int32_t idx)
CSGObject * get_element(int32_t index) const
void push_back(CSGObject *e)
float64_t * subkernel_weights_buffer
bool precompute_subkernels()
virtual bool has_features()
The class CombinedFeatures is used to combine a number of of feature objects into a single CombinedFe...
virtual void add_to_normal(int32_t vector_idx, float64_t weight)
virtual EFeatureType get_feature_type() const =0
Class List implements a doubly connected list for low-level-objects.
bool append_feature_obj(CFeatures *obj)
CCombinedKernel(int32_t size=10, bool append_subkernel_weights=false)
bool append_element(CSGObject *e)