Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _LABELS__H__
00013 #define _LABELS__H__
00014
00015 #include "lib/common.h"
00016 #include "lib/io.h"
00017 #include "lib/File.h"
00018 #include "base/SGObject.h"
00019
00020 namespace shogun
00021 {
00022
00023 class CFile;
00024
00030 class CLabels : public CSGObject
00031 {
00032 void init(int32_t num_labels_, int32_t num_classes);
00033
00034 public:
00036 CLabels();
00037
00042 CLabels(int32_t num_labels);
00043
00049 CLabels(float64_t* src, int32_t len);
00050
00056 CLabels(float64_t* in_confidences, int32_t in_num_labels, int32_t in_num_classes);
00057
00062 CLabels(CFile* loader);
00063 virtual ~CLabels();
00064
00069 virtual void load(CFile* loader);
00070
00075 virtual void save(CFile* writer);
00076
00083 inline bool set_label(int32_t idx, float64_t label)
00084 {
00085 if (labels && idx<num_labels)
00086 {
00087 labels[idx]=label;
00088 return true;
00089 }
00090 else
00091 return false;
00092 }
00093
00100 inline bool set_int_label(int32_t idx, int32_t label)
00101 {
00102 if (labels && idx<num_labels)
00103 {
00104 labels[idx]= (float64_t) label;
00105 return true;
00106 }
00107 else
00108 return false;
00109 }
00110
00116 inline float64_t get_label(int32_t idx)
00117 {
00118 if (labels && idx<num_labels)
00119 return labels[idx];
00120 else
00121 return -1;
00122 }
00123
00129 inline int32_t get_int_label(int32_t idx)
00130 {
00131 if (labels && idx<num_labels)
00132 {
00133 ASSERT(labels[idx]== ((float64_t) ((int32_t) labels[idx])));
00134 return ((int32_t) labels[idx]);
00135 }
00136 else
00137 return -1;
00138 }
00139
00144 bool is_two_class_labeling();
00145
00152 int32_t get_num_classes();
00153
00160 float64_t* get_labels(int32_t &len);
00161
00167 void get_labels(float64_t** dst, int32_t* len);
00168
00174 void set_labels(float64_t* src, int32_t len);
00175
00178 void set_to_one();
00179
00185 void set_confidences(float64_t* in_confidences, int32_t in_num_labels, int32_t in_num_classes);
00186
00192 float64_t* get_confidences(int32_t& out_num_labels, int32_t& out_num_classes);
00193
00199 void get_confidences(float64_t** dst, int32_t* out_num_labels, int32_t* out_num_classes);
00200
00206 float64_t* get_sample_confidences(const int32_t& in_sample_index, int32_t& out_num_classes);
00207
00214 int32_t* get_int_labels(int32_t &len);
00215
00222 void set_int_labels(int32_t *labels, int32_t len) ;
00223
00228 inline int32_t get_num_labels() { return num_labels; }
00229
00231 inline virtual const char* get_name() const { return "Labels"; }
00232
00233 protected:
00235 void find_labels();
00236
00237 protected:
00239 int32_t num_labels;
00241 float64_t* labels;
00242
00244 int32_t m_num_classes;
00245
00247 float64_t* m_confidences;
00248 int32_t m_confidence_classes;
00249 int32_t m_confidence_labels;
00250 };
00251 }
00252 #endif