SHOGUN  6.1.3
KNNSolver.h
Go to the documentation of this file.
1 /* This software is distributed under BSD 3-clause license (see LICENSE file).
2  *
3  * Copyright (c) 2012-2013 Sergey Lisitsyn
4  */
5 
6 #ifndef KNNSOLVER_H__
7 #define KNNSOLVER_H__
8 
9 #include <shogun/lib/config.h>
10 
11 #include <shogun/lib/common.h>
12 #include <shogun/io/SGIO.h>
15 
16 namespace shogun
17 {
18 /* Virtual base class for all KNN solvers */
19 
20 class CDistanceMachine;
22 {
23  public:
25  CKNNSolver(): CDistanceMachine() { init(); }
26 
28  virtual ~CKNNSolver() { /* nothing to do */ }
29 
38  CKNNSolver(const int32_t k, const float64_t q, const int32_t num_classes, const int32_t min_label, const SGVector<int32_t> train_labels);
39 
50  int32_t choose_class(float64_t* classes, const int32_t* train_lab) const;
51 
64  void choose_class_for_multiple_k(int32_t* output, int32_t* classes, const int32_t* train_lab, const int32_t step) const;
65 
74  virtual CMulticlassLabels* classify_objects(CDistance* d, const int32_t num_lab, SGVector<int32_t>& train_lab, SGVector<float64_t>& classes) const = 0;
75 
84  virtual SGVector<int32_t> classify_objects_k(CDistance* d, const int32_t num_lab, SGVector<int32_t>& train_lab, SGVector<int32_t>& classes) const = 0;
85 
87  virtual const char* get_name() const { return "KNNSolver"; }
88 
89  private:
90  void init();
91 
92  protected:
94  int32_t m_k;
95 
98 
100  int32_t m_num_classes;
101 
103  int32_t m_min_label;
104 
107 };
108 
109 }
110 #endif
int32_t m_k
the k parameter in KNN
Definition: KNNSolver.h:94
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:87
int32_t choose_class(float64_t *classes, const int32_t *train_lab) const
Definition: KNNSolver.cpp:35
SGVector< int32_t > m_train_labels
Definition: KNNSolver.h:106
A generic DistanceMachine interface.
Multiclass Labels for multi-class classification.
double float64_t
Definition: common.h:60
virtual const char * get_name() const
Definition: KNNSolver.h:87
int32_t m_num_classes
number of classes (i.e. number of values labels can take)
Definition: KNNSolver.h:100
virtual ~CKNNSolver()
Definition: KNNSolver.h:28
int32_t m_min_label
smallest label, i.e. -1
Definition: KNNSolver.h:103
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual SGVector< int32_t > classify_objects_k(CDistance *d, const int32_t num_lab, SGVector< int32_t > &train_lab, SGVector< int32_t > &classes) const =0
virtual CMulticlassLabels * classify_objects(CDistance *d, const int32_t num_lab, SGVector< int32_t > &train_lab, SGVector< float64_t > &classes) const =0
void choose_class_for_multiple_k(int32_t *output, int32_t *classes, const int32_t *train_lab, const int32_t step) const
Definition: KNNSolver.cpp:62
float64_t m_q
parameter q of rank weighting
Definition: KNNSolver.h:97

SHOGUN Machine Learning Toolbox - Documentation