18 using namespace shogun;
20 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 #endif // DOXYGEN_SHOULD_SKIP_THIS
45 int32_t num_sv=svs.
vlen;
63 int32_t num_sv = svs.
vlen;
214 int32_t * sv_idx =
SG_MALLOC(int32_t, num_sv);
217 for(int32_t i=0; i<num_sv; i++)
229 SG_ERROR(
"initialization of kernel optimization failed\n");
234 SG_ERROR(
"initialization of kernel optimization failed\n");
253 SG_DEBUG(
"entering %s::apply_get_outputs(%s at %p)\n",
256 REQUIRE(
kernel,
"%s::apply_get_outputs(): No kernel assigned!\n");
260 SG_ERROR(
"%s: No vectors on left hand side (%s). This is probably due to"
261 " an implementation error in %s, where it was forgotten to set "
262 "the data (m_svs) indices\n",
get_name(),
269 REQUIRE(lhs,
"%s::apply_get_outputs(): No left hand side specified\n",
290 SG_DEBUG(
"computing output on %d test examples\n", num_vectors);
303 SG_DEBUG(
"Batch evaluation enabled\n");
308 int32_t* idx=
SG_MALLOC(int32_t, num_vectors);
311 for (int32_t i=0; i<num_vectors; i++)
321 output.
vector, get_num_support_vectors(), sv_idx, sv_weight);
327 for (int32_t i=0; i<num_vectors; i++)
338 S_THREAD_PARAM params;
339 params.kernel_machine=
this;
340 params.result = output.
vector;
342 params.end=num_vectors;
344 params.indices = NULL;
345 params.indices_len = 0;
351 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
352 S_THREAD_PARAM* params =
SG_MALLOC(S_THREAD_PARAM, num_threads);
353 int32_t step= num_vectors/num_threads;
357 for (t=0; t<num_threads-1; t++)
359 params[t].kernel_machine =
this;
360 params[t].result = output.
vector;
361 params[t].start = t*step;
362 params[t].end = (t+1)*step;
363 params[t].verbose =
false;
364 params[t].indices = NULL;
365 params[t].indices_len = 0;
366 pthread_create(&threads[t], NULL,
370 params[t].kernel_machine =
this;
371 params[t].result = output.
vector;
372 params[t].start = t*step;
373 params[t].end = num_vectors;
374 params[t].verbose =
true;
375 params[t].indices = NULL;
376 params[t].indices_len = 0;
379 for (t=0; t<num_threads-1; t++)
380 pthread_join(threads[t], NULL);
390 SG_INFO(
"prematurely stopped. \n");
396 SG_DEBUG(
"leaving %s::apply_get_outputs(%s at %p)\n",
423 S_THREAD_PARAM* params = (S_THREAD_PARAM*) p;
428 for (int32_t vec=params->start; vec<params->end; vec++)
430 for (int32_t vec=params->start; vec<params->end &&
436 int32_t num_vectors=params->end - params->start;
437 int32_t v=vec-params->start;
438 if ( (v% (num_vectors/100+1))== 0)
443 index_t idx=params->indices ? params->indices[vec] : vec;
444 result[vec] = kernel_machine->
apply_one(idx);
453 SG_ERROR(
"kernel is needed to store SV features.\n");
459 SG_ERROR(
"kernel lhs is needed to store SV features.\n");
483 SG_ERROR(
"CKernelMachine::train_locked() call data_lock() before!\n");
532 SG_ERROR(
"CKernelMachine::apply_locked() call data_lock() before!\n");
537 int32_t num_inds=indices.
vlen;
553 S_THREAD_PARAM params;
554 params.kernel_machine=
this;
555 params.result=output.
vector;
560 params.indices=indices.
vector;
561 params.indices_len=indices.
vlen;
569 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
570 S_THREAD_PARAM* params=
SG_MALLOC(S_THREAD_PARAM, num_threads);
571 int32_t step= num_inds/num_threads;
574 for (t=0; t<num_threads-1; t++)
576 params[t].kernel_machine=
this;
577 params[t].result=output.
vector;
580 params[t].start=t*step;
581 params[t].end=(t+1)*step;
582 params[t].indices=indices.
vector;
583 params[t].indices_len=indices.
vlen;
585 params[t].verbose=
false;
590 params[t].kernel_machine=
this;
591 params[t].result=output.
vector;
594 params[t].start=t*step;
595 params[t].end=num_inds;
596 params[t].indices=indices.
vector;
597 params[t].indices_len=indices.
vlen;
599 params[t].verbose=
true;
602 for (t=0; t<num_threads-1; t++)
603 pthread_join(threads[t], NULL);
612 SG_INFO(
"prematurely stopped.\n");
623 SG_ERROR(
"The kernel is not initialized\n");
669 void CKernelMachine::init()
694 new SGParamInfo(
"custom_kernel", CT_SCALAR, ST_NONE, PT_SGOBJECT, 1),
698 new SGParamInfo(
"kernel_backup", CT_SCALAR, ST_NONE, PT_SGOBJECT, 1),