Labels.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2009 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #ifndef _LABELS__H__
00013 #define _LABELS__H__
00014 
00015 #include "lib/common.h"
00016 #include "lib/io.h"
00017 #include "base/SGObject.h"
00018 
00024 class CLabels : public CSGObject
00025 {
00026     public:
00028         CLabels();
00029 
00034         CLabels(int32_t num_labels);
00035 
00041         CLabels(float64_t* src, int32_t len);
00042 
00047         CLabels(char* fname);
00048         virtual ~CLabels();
00049 
00055         bool load(char* fname);
00056 
00062         bool save(char* fname);
00063 
00070         inline bool set_label(int32_t idx, float64_t label)
00071         { 
00072             if (labels && idx<num_labels)
00073             {
00074                 labels[idx]=label;
00075                 return true;
00076             }
00077             else 
00078                 return false;
00079         }
00080 
00087         inline bool set_int_label(int32_t idx, int32_t label)
00088         { 
00089             if (labels && idx<num_labels)
00090             {
00091                 labels[idx]= (float64_t) label;
00092                 return true;
00093             }
00094             else 
00095                 return false;
00096         }
00097 
00103         inline float64_t get_label(int32_t idx)
00104         {
00105             if (labels && idx<num_labels)
00106                 return labels[idx];
00107             else
00108                 return -1;
00109         }
00110 
00116         inline int32_t get_int_label(int32_t idx)
00117         {
00118             if (labels && idx<num_labels)
00119             {
00120                 ASSERT(labels[idx]== ((float64_t) ((int32_t) labels[idx])));
00121                 return ((int32_t) labels[idx]);
00122             }
00123             else
00124                 return -1;
00125         }
00126 
00131         bool is_two_class_labeling();
00132 
00139         int32_t get_num_classes();
00140 
00147         float64_t* get_labels(int32_t &len);
00148         
00154         void get_labels(float64_t** dst, int32_t* len);
00155 
00161         void set_labels(float64_t* src, int32_t len);
00162 
00169         int32_t* get_int_labels(int32_t &len);
00170 
00177         void set_int_labels(int32_t *labels, int32_t len) ;
00178 
00183         inline int32_t get_num_labels() { return num_labels; }
00184 
00186         inline virtual const char* get_name() const { return "Labels"; }
00187 
00188     protected:
00190         int32_t num_labels;
00192         float64_t* labels;
00193 };
00194 #endif

SHOGUN Machine Learning Toolbox - Documentation