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-2008 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Copyright (C) 1999-2008 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 
00020 class CLabels : public CSGObject
00021 {
00022     public:
00024         CLabels();
00025 
00030         CLabels(INT num_labels);
00031 
00037         CLabels(DREAL* labels, INT len);
00038 
00043         CLabels(CHAR* fname);
00044         ~CLabels();
00045 
00051         bool load(CHAR* fname);
00052 
00058         bool save(CHAR* fname);
00059 
00066         inline bool set_label(INT idx, DREAL label)
00067         { 
00068             if (labels && idx<num_labels)
00069             {
00070                 labels[idx]=label;
00071                 return true;
00072             }
00073             else 
00074                 return false;
00075         }
00076 
00083         inline bool set_int_label(INT idx, INT label)
00084         { 
00085             if (labels && idx<num_labels)
00086             {
00087                 labels[idx]= (DREAL) label;
00088                 return true;
00089             }
00090             else 
00091                 return false;
00092         }
00093 
00099         inline DREAL get_label(INT idx)
00100         {
00101             if (labels && idx<num_labels)
00102                 return labels[idx];
00103             else
00104                 return -1;
00105         }
00106 
00112         inline INT get_int_label(INT idx)
00113         {
00114             if (labels && idx<num_labels)
00115             {
00116                 ASSERT(labels[idx]== ((DREAL) ((INT) labels[idx])));
00117                 return ((INT) labels[idx]);
00118             }
00119             else
00120                 return -1;
00121         }
00122 
00127         bool is_two_class_labeling();
00128 
00135         INT get_num_classes();
00136 
00143         DREAL* get_labels(INT &len);
00144         
00150         void get_labels(DREAL** labels, INT* len);
00151 
00157         void set_labels(DREAL* labels, INT len);
00158 
00165         INT* get_int_labels(INT &len);
00166 
00173         void set_int_labels(INT *labels, INT len) ;
00174 
00179         inline INT get_num_labels() { return num_labels; }
00180     protected:
00182         INT num_labels;
00184         DREAL* labels;
00185 };
00186 #endif

SHOGUN Machine Learning Toolbox - Documentation