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")
462 int32_t CKNN::choose_class(
float64_t* classes, int32_t* train_lab)
467 for (int32_t j=0; j<
m_k; j++)
469 classes[train_lab[j]]+= multiplier;
470 multiplier*= multiplier;
479 if (out_max< classes[j])
489 void CKNN::choose_class_for_multiple_k(int32_t* output, int32_t* classes, int32_t* train_lab, int32_t step)
492 memset(classes, 0,
sizeof(int32_t)*m_num_classes);
494 for (int32_t j=0; j<
m_k; j++)
496 classes[train_lab[j]]++;
504 if (out_max< classes[c])
Class Time that implements a stopwatch based on either cpu time or wall clock time.
virtual void store_model_features()
virtual bool save(FILE *dstfile)
Class Distance, a base class for all the distances used in the Shogun toolbox.
void init_distance(CFeatures *data)
The class Labels models labels, i.e. class assignments of objects.
virtual int32_t get_num_labels() const =0
static void qsort_index(T1 *output, T2 *index, uint32_t size)
node< P > batch_create(v_array< P > points)
CFeatures * replace_lhs(CFeatures *lhs)
SGMatrix< int32_t > classify_for_multiple_k()
Class v_array taken directly from JL's implementation.
virtual int32_t get_num_vectors() const =0
void distances_lhs(float64_t *result, int32_t idx_a1, int32_t idx_a2, int32_t idx_b)
virtual CFeatures * duplicate() const =0
int32_t m_min_label
smallest label, i.e. -1
virtual bool train_machine(CFeatures *data=NULL)
SGMatrix< index_t > nearest_neighbors()
A generic DistanceMachine interface.
bool set_label(int32_t idx, float64_t label)
virtual bool load(FILE *srcfile)
v_array< CJLCoverTreePoint > parse_points(CDistance *distance, EFeaturesContainer fc)
int32_t m_num_classes
number of classes (i.e. number of values labels can take)
Multiclass Labels for multi-class classification.
float64_t cur_time_diff(bool verbose=false)
int32_t m_k
the k parameter in KNN
virtual void set_store_model_features(bool store_model)
static void clear_cancel()
virtual int32_t get_num_vec_rhs()
static bool cancel_computations()
CFeatures * replace_rhs(CFeatures *rhs)
float64_t m_q
parameter q of rank weighting
SGVector< int32_t > m_train_labels
virtual float64_t distance(int32_t idx_a, int32_t idx_b)
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
void set_distance(CDistance *d)
SGVector< T > clone() const
virtual CMulticlassLabels * classify_NN()
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
void k_nearest_neighbor(const node< P > &top_node, const node< P > &query, v_array< v_array< P > > &results, int k)
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual void set_labels(CLabels *lab)
bool m_use_covertree
parameter to enable cover tree support