26 using namespace shogun;
80 SG_ERROR(
"Number of training vectors does not match number of labels\n")
136 SG_PRINT(
"\nQuick sort query %d\n", i)
137 for (int32_t j=0; j<
m_k; j++)
143 for (int32_t j=0; j<
m_k; j++)
144 NN(j,i) = train_idxs[j];
167 ASSERT(m_k<=distance->get_num_vec_lhs())
172 int32_t* train_lab=SG_MALLOC(int32_t,
m_k);
174 SG_INFO(
"%d test examples\n", num_lab)
182 float64_t tfinish, tparsed, tcreated, tqueried;
194 for (int32_t j=0; j<
m_k; j++)
198 int32_t out_idx = choose_class(classes, train_lab);
204 SG_PRINT(
">>>> Quick sort applied in %9.4f\n",
214 SG_INFO(
"q != 1.0 not supported with cover tree, using q = 1\n")
224 SG_PRINT(
">>>> JL parsed in %9.4f\n",
236 SG_PRINT(
">>>> Cover trees created in %9.4f\n",
246 SG_PRINT(
">>>> Query finished in %9.4f\n",
252 for ( int32_t i = 0 ; i < res.
index ; ++i )
254 for ( int32_t j = 0 ; j < res[i].
index ; ++j )
256 printf(
"%d ", res[i][j].m_index);
263 for ( int32_t i = 0 ; i < res.
index ; ++i )
266 for ( int32_t j = 0; j <
m_k; ++j )
271 int32_t out_idx = choose_class(classes, train_lab);
299 SG_INFO(
"%d test examples\n", num_lab)
318 if (distances[j]<min_dist)
320 min_dist = distances[j];
342 int32_t* output=SG_MALLOC(int32_t,
m_k*num_lab);
345 int32_t* train_lab=SG_MALLOC(int32_t,
m_k);
350 SG_INFO(
"%d test examples\n", num_lab)
361 for (int32_t j=0; j<
m_k; j++)
364 choose_class_for_multiple_k(output+i, classes, train_lab, num_lab);
392 for ( int32_t i = 0 ; i < res.
index ; ++i )
397 for ( int32_t j = 0 ; j <
m_k ; ++j )
403 res[i][j+1].m_index ];
409 choose_class_for_multiple_k(output+res[i][0].m_index, classes,
430 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])