28 using namespace shogun;
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 #endif // DOXYGEN_SHOULD_SKIP_THIS
46 :
CKernel(size), append_subkernel_weights(asw)
51 SG_INFO(
"(subkernel weights are appended)\n") ;
53 SG_INFO(
"Combined kernel created (%p)\n",
this) ;
64 SG_INFO(
"Combined kernel deleted (%p).\n",
this);
98 SG_ERROR(
"CombinedKernel: Number of features/kernels does not match - bailing out\n");
102 result=k->
init(lf,rf);
111 SG_DEBUG(
"Initializing 0x%p - \"%s\" (skipping init, this is a CUSTOM kernel)\n",
this, k->
get_name());
113 SG_ERROR(
"No kernel matrix was assigned to this Custom kernel\n");
126 SG_INFO(
"CombinedKernel: Initialising the following kernel failed\n");
134 if ((lf!=NULL) || (rf!=NULL) || (k!=NULL))
139 SG_ERROR(
"CombinedKernel: Number of features/kernels does not match - bailing out\n");
229 SG_INFO(
"BEGIN COMBINED KERNEL LIST - ");
240 SG_INFO(
"END COMBINED KERNEL LIST - ");
260 int32_t count, int32_t *IDX,
float64_t *weights)
262 SG_DEBUG(
"initializing CCombinedKernel optimization\n");
268 bool have_non_optimizable=
false;
278 SG_WARNING(
"non-optimizable kernel 0x%X in kernel-list\n", k);
279 have_non_optimizable=
true;
284 have_non_optimizable=
true;
285 SG_WARNING(
"init_optimization of kernel 0x%X failed\n", k);
292 if (have_non_optimizable)
294 SG_WARNING(
"some kernels in the kernel-list are not optimized\n");
299 for (int32_t i=0; i<count; i++)
337 int32_t num_vec, int32_t* vec_idx,
float64_t* result, int32_t num_suppvec,
372 S_THREAD_PARAM* params= (S_THREAD_PARAM*) p;
373 int32_t* vec_idx=params->vec_idx;
377 for (int32_t i=params->start; i<params->end; i++)
385 S_THREAD_PARAM* params= (S_THREAD_PARAM*) p;
386 int32_t* vec_idx=params->vec_idx;
390 int32_t* IDX=params->IDX;
391 int32_t num_suppvec=params->num_suppvec;
393 for (int32_t i=params->start; i<params->end; i++)
396 for (int32_t j=0; j<num_suppvec; j++)
397 sub_result += weights[j] * k->
kernel(IDX[j], vec_idx[i]);
407 int32_t num_suppvec, int32_t* IDX,
float64_t* weights)
423 S_THREAD_PARAM params;
425 params.result=result;
428 params.vec_idx = vec_idx;
434 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
435 S_THREAD_PARAM* params =
SG_MALLOC(S_THREAD_PARAM, num_threads);
436 int32_t step= num_vec/num_threads;
440 for (t=0; t<num_threads-1; t++)
442 params[t].kernel = k;
443 params[t].result = result;
444 params[t].start = t*step;
445 params[t].end = (t+1)*step;
446 params[t].vec_idx = vec_idx;
450 params[t].kernel = k;
451 params[t].result = result;
452 params[t].start = t*step;
453 params[t].end = num_vec;
454 params[t].vec_idx = vec_idx;
457 for (t=0; t<num_threads-1; t++)
458 pthread_join(threads[t], NULL);
470 ASSERT(IDX!=NULL || num_suppvec==0);
471 ASSERT(weights!=NULL || num_suppvec==0);
480 S_THREAD_PARAM params;
482 params.result=result;
485 params.vec_idx = vec_idx;
487 params.weights = weights;
488 params.num_suppvec = num_suppvec;
494 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
495 S_THREAD_PARAM* params =
SG_MALLOC(S_THREAD_PARAM, num_threads);
496 int32_t step= num_vec/num_threads;
500 for (t=0; t<num_threads-1; t++)
502 params[t].kernel = k;
503 params[t].result = result;
504 params[t].start = t*step;
505 params[t].end = (t+1)*step;
506 params[t].vec_idx = vec_idx;
508 params[t].weights = weights;
509 params[t].num_suppvec = num_suppvec;
513 params[t].kernel = k;
514 params[t].result = result;
515 params[t].start = t*step;
516 params[t].end = num_vec;
517 params[t].vec_idx = vec_idx;
519 params[t].weights = weights;
520 params[t].num_suppvec = num_suppvec;
523 for (t=0; t<num_threads-1; t++)
524 pthread_join(threads[t], NULL);
538 SG_ERROR(
"CCombinedKernel optimization not initialized\n");
608 int32_t idx,
float64_t * subkernel_contrib)
662 for (int32_t j=0; j<num; j++)
770 void CCombinedKernel::init()
786 "Support vector index.");
788 "Support vector weights.");
790 "append_subkernel_weights",
791 "If subkernel weights are appended.");
793 "Whether kernel is ready to be used.");
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 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 void compute_by_subkernel(int32_t vector_idx, float64_t *subkernel_contrib)
virtual void set_subkernel_weights(SGVector< float64_t > weights)
virtual EFeatureType get_feature_type()=0
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)
virtual void clear_normal()
void set_is_initialized(bool p_init)
virtual bool delete_optimization()
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)
virtual void remove_rhs()
takes all necessary steps if the rhs is removed from kernel
virtual int32_t get_num_vec_lhs()
bool get_is_initialized()
virtual void remove_lhs_and_rhs()
bool has_property(EKernelProperty p)
static void * compute_optimized_kernel_helper(void *p)
void add(bool *param, const char *name, const char *description="")
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.
virtual EFeatureClass get_feature_class()=0
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()
virtual const float64_t * get_subkernel_weights(int32_t &num_weights)
static void * compute_kernel_helper(void *p)
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="")
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)
virtual bool delete_optimization()
Class ListElement, defines how an element of the the list looks like.
The class Features is the base class of all feature objects.
bool append_element(CSGObject *data)
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)
CKernel * get_first_kernel()
CKernel * get_next_kernel()
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)
#define SG_MALLOC(type, len)
Class List implements a doubly connected list for low-level-objects.
CCombinedKernel(int32_t size=10, bool append_subkernel_weights=false)