27 using namespace shogun;
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
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);
97 SG_ERROR(
"CombinedKernel: Number of features/kernels does not match - bailing out\n");
101 result=k->
init(lf,rf);
110 SG_DEBUG(
"Initializing 0x%p - \"%s\" (skipping init, this is a CUSTOM kernel)\n",
this, k->
get_name());
112 SG_ERROR(
"No kernel matrix was assigned to this Custom kernel\n");
125 SG_INFO(
"CombinedKernel: Initialising the following kernel failed\n");
133 if ((lf!=NULL) || (rf!=NULL) || (k!=NULL))
138 SG_ERROR(
"CombinedKernel: Number of features/kernels does not match - bailing out\n");
228 SG_INFO(
"BEGIN COMBINED KERNEL LIST - ");
239 SG_INFO(
"END COMBINED KERNEL LIST - ");
259 int32_t count, int32_t *IDX,
float64_t *weights)
261 SG_DEBUG(
"initializing CCombinedKernel optimization\n");
267 bool have_non_optimizable=
false;
277 SG_WARNING(
"non-optimizable kernel 0x%X in kernel-list\n", k);
278 have_non_optimizable=
true;
283 have_non_optimizable=
true;
284 SG_WARNING(
"init_optimization of kernel 0x%X failed\n", k);
291 if (have_non_optimizable)
293 SG_WARNING(
"some kernels in the kernel-list are not optimized\n");
298 for (int32_t i=0; i<count; i++)
336 int32_t num_vec, int32_t* vec_idx,
float64_t* result, int32_t num_suppvec,
371 S_THREAD_PARAM* params= (S_THREAD_PARAM*) p;
372 int32_t* vec_idx=params->vec_idx;
376 for (int32_t i=params->start; i<params->end; i++)
384 S_THREAD_PARAM* params= (S_THREAD_PARAM*) p;
385 int32_t* vec_idx=params->vec_idx;
389 int32_t* IDX=params->IDX;
390 int32_t num_suppvec=params->num_suppvec;
392 for (int32_t i=params->start; i<params->end; i++)
395 for (int32_t j=0; j<num_suppvec; j++)
396 sub_result += weights[j] * k->
kernel(IDX[j], vec_idx[i]);
406 int32_t num_suppvec, int32_t* IDX,
float64_t* weights)
422 S_THREAD_PARAM params;
424 params.result=result;
427 params.vec_idx = vec_idx;
433 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
434 S_THREAD_PARAM* params =
SG_MALLOC(S_THREAD_PARAM, num_threads);
435 int32_t step= num_vec/num_threads;
439 for (t=0; t<num_threads-1; t++)
441 params[t].kernel = k;
442 params[t].result = result;
443 params[t].start = t*step;
444 params[t].end = (t+1)*step;
445 params[t].vec_idx = vec_idx;
449 params[t].kernel = k;
450 params[t].result = result;
451 params[t].start = t*step;
452 params[t].end = num_vec;
453 params[t].vec_idx = vec_idx;
456 for (t=0; t<num_threads-1; t++)
457 pthread_join(threads[t], NULL);
469 ASSERT(IDX!=NULL || num_suppvec==0);
470 ASSERT(weights!=NULL || num_suppvec==0);
479 S_THREAD_PARAM params;
481 params.result=result;
484 params.vec_idx = vec_idx;
486 params.weights = weights;
487 params.num_suppvec = num_suppvec;
493 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
494 S_THREAD_PARAM* params =
SG_MALLOC(S_THREAD_PARAM, num_threads);
495 int32_t step= num_vec/num_threads;
499 for (t=0; t<num_threads-1; t++)
501 params[t].kernel = k;
502 params[t].result = result;
503 params[t].start = t*step;
504 params[t].end = (t+1)*step;
505 params[t].vec_idx = vec_idx;
507 params[t].weights = weights;
508 params[t].num_suppvec = num_suppvec;
512 params[t].kernel = k;
513 params[t].result = result;
514 params[t].start = t*step;
515 params[t].end = num_vec;
516 params[t].vec_idx = vec_idx;
518 params[t].weights = weights;
519 params[t].num_suppvec = num_suppvec;
522 for (t=0; t<num_threads-1; t++)
523 pthread_join(threads[t], NULL);
537 SG_ERROR(
"CCombinedKernel optimization not initialized\n");
607 int32_t idx,
float64_t * subkernel_contrib)
647 SG_DEBUG(
"entering CCombinedKernel::get_subkernel_weights()\n");
655 SG_DEBUG(
"appending kernel weights\n");
665 for (int32_t j=0; j<num; j++)
675 SG_DEBUG(
"not appending kernel weights\n");
689 SG_DEBUG(
"leaving CCombinedKernel::get_subkernel_weights()\n");
699 for (int32_t i=0; i<num; i++)
779 void CCombinedKernel::init()
794 "Support vector index.");
796 "Support vector weights.");
808 if (strcmp(param->
m_name,
"combined_kernel_weight") == 0)
865 derivative(g,h) *= coeff;
878 result(g,h) += derivative(g,h);