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 
00023 class CLabels : public CSGObject
00024 {
00025     public:
00027         CLabels();
00028 
00033         CLabels(int32_t num_labels);
00034 
00040         CLabels(float64_t* labels, int32_t len);
00041 
00046         CLabels(char* fname);
00047         ~CLabels();
00048 
00054         bool load(char* fname);
00055 
00061         bool save(char* fname);
00062 
00069         inline bool set_label(int32_t idx, float64_t label)
00070         { 
00071             if (labels && idx<num_labels)
00072             {
00073                 labels[idx]=label;
00074                 return true;
00075             }
00076             else 
00077                 return false;
00078         }
00079 
00086         inline bool set_int_label(int32_t idx, int32_t label)
00087         { 
00088             if (labels && idx<num_labels)
00089             {
00090                 labels[idx]= (float64_t) label;
00091                 return true;
00092             }
00093             else 
00094                 return false;
00095         }
00096 
00102         inline float64_t get_label(int32_t idx)
00103         {
00104             if (labels && idx<num_labels)
00105                 return labels[idx];
00106             else
00107                 return -1;
00108         }
00109 
00115         inline int32_t get_int_label(int32_t idx)
00116         {
00117             if (labels && idx<num_labels)
00118             {
00119                 ASSERT(labels[idx]== ((float64_t) ((int32_t) labels[idx])));
00120                 return ((int32_t) labels[idx]);
00121             }
00122             else
00123                 return -1;
00124         }
00125 
00130         bool is_two_class_labeling();
00131 
00138         int32_t get_num_classes();
00139 
00146         float64_t* get_labels(int32_t &len);
00147         
00153         void get_labels(float64_t** labels, int32_t* len);
00154 
00160         void set_labels(float64_t* labels, int32_t len);
00161 
00168         int32_t* get_int_labels(int32_t &len);
00169 
00176         void set_int_labels(int32_t *labels, int32_t len) ;
00177 
00182         inline int32_t get_num_labels() { return num_labels; }
00183     protected:
00185         int32_t num_labels;
00187         float64_t* labels;
00188 };
00189 #endif

SHOGUN Machine Learning Toolbox - Documentation