26 using namespace shogun;
80 SG_ERROR(
"Number of training vectors does not match number of labels\n")
137 SG_PRINT(
"\nQuick sort query %d\n", i)
138 for (int32_t j=0; j<
m_k; j++)
144 for (int32_t j=0; j<
m_k; j++)
145 NN(j,i) = train_idxs[j];
168 ASSERT(m_k<=distance->get_num_vec_lhs())
173 int32_t* train_lab=SG_MALLOC(int32_t,
m_k);
175 SG_INFO(
"%d test examples\n", num_lab)
183 float64_t tfinish, tparsed, tcreated, tqueried;
195 for (int32_t j=0; j<
m_k; j++)
199 int32_t out_idx = choose_class(classes, train_lab);
205 SG_PRINT(
">>>> Quick sort applied in %9.4f\n",
215 SG_INFO(
"q != 1.0 not supported with cover tree, using q = 1\n")
225 SG_PRINT(
">>>> JL parsed in %9.4f\n",
237 SG_PRINT(
">>>> Cover trees created in %9.4f\n",
247 SG_PRINT(
">>>> Query finished in %9.4f\n",
253 for ( int32_t i = 0 ; i < res.
index ; ++i )
255 for ( int32_t j = 0 ; j < res[i].
index ; ++j )
257 printf(
"%d ", res[i][j].m_index);
264 for ( int32_t i = 0 ; i < res.
index ; ++i )
267 for ( int32_t j = 0; j <
m_k; ++j )
272 int32_t out_idx = choose_class(classes, train_lab);
300 SG_INFO(
"%d test examples\n", num_lab)
319 if (distances[j]<min_dist)
321 min_dist = distances[j];
343 int32_t* output=SG_MALLOC(int32_t,
m_k*num_lab);
346 int32_t* train_lab=SG_MALLOC(int32_t,
m_k);
351 SG_INFO(
"%d test examples\n", num_lab)
362 for (int32_t j=0; j<
m_k; j++)
365 choose_class_for_multiple_k(output+i, classes, train_lab, num_lab);
393 for ( int32_t i = 0 ; i < res.
index ; ++i )
398 for ( int32_t j = 0 ; j <
m_k ; ++j )
404 res[i][j+1].m_index ];
410 choose_class_for_multiple_k(output+res[i][0].m_index, classes,
431 SG_ERROR(
"No vectors on left hand side\n")
463 int32_t CKNN::choose_class(
float64_t* classes, int32_t* train_lab)
468 for (int32_t j=0; j<
m_k; j++)
470 classes[train_lab[j]]+= multiplier;
471 multiplier*= multiplier;
480 if (out_max< classes[j])
490 void CKNN::choose_class_for_multiple_k(int32_t* output, int32_t* classes, int32_t* train_lab, int32_t step)
493 memset(classes, 0,
sizeof(int32_t)*m_num_classes);
495 for (int32_t j=0; j<
m_k; j++)
497 classes[train_lab[j]]++;
505 if (out_max< classes[c])