SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DenseLabels.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Written (W) 1999-2008 Gunnar Raetsch
9  * Written (W) 2011 Heiko Strathmann
10  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
11  */
12 
13 #ifndef _DENSE_LABELS__H__
14 #define _DENSE_LABELS__H__
15 
16 #include <shogun/lib/config.h>
17 
18 #include <shogun/lib/common.h>
19 #include <shogun/io/File.h>
20 #include <shogun/labels/Labels.h>
22 
23 namespace shogun
24 {
25  class CFile;
26 
35 class CDenseLabels : public CLabels
36 {
37  public:
39  CDenseLabels();
40 
45  CDenseLabels(int32_t num_labels);
46 
51  CDenseLabels(CFile* loader);
52 
54  virtual ~CDenseLabels();
55 
62  virtual void ensure_valid(const char* context=NULL);
63 
70  virtual void load(CFile* loader);
71 
78  virtual void save(CFile* writer);
79 
88  bool set_label(int32_t idx, float64_t label);
89 
98  bool set_int_label(int32_t idx, int32_t label);
99 
105 
113  float64_t get_label(int32_t idx);
114 
122  template<typename ST>
123  ST get_label_t(int32_t idx)
124  {
125  int32_t real_num=m_subset_stack->subset_idx_conversion(idx);
127  return m_labels.vector[real_num];
128  }
129 
137  int32_t get_int_label(int32_t idx);
138 
146 
152  template<typename ST>
154  {
156  return get_labels_copy_t<ST>();
157 
158  SGVector<ST> labels_copy(m_labels.vlen);
159  for(int i = 0; i < m_labels.vlen; ++i)
160  labels_copy[i] = (ST) m_labels[i];
161 
162  return labels_copy;
163  }
164 
171  template<typename ST>
173  {
174  if (!m_subset_stack->has_subsets())
175  {
176  SGVector<ST> labels_copy(m_labels.vlen);
177  for(int i = 0; i < m_labels.vlen; ++i)
178  labels_copy[i] = (ST) m_labels[i];
179 
180  return labels_copy;
181  }
182 
183  index_t num_labels = get_num_labels();
184  SGVector<ST> result(num_labels);
185 
186  /* copy element wise because of possible subset */
187  for (index_t i=0; i<num_labels; i++)
188  result[i] = get_label_t<ST>(i);
189 
190  return result;
191  }
192 
200 
206  void set_to_one();
207 
213  void zero();
214 
222  void set_to_const(float64_t c);
223 
231 
238  void set_int_labels(SGVector<int32_t> labels);
239 
240 #if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
241 
247  void set_int_labels(SGVector<int64_t> labels);
248 #endif
249 
254  virtual int32_t get_num_labels() const;
255 
260  virtual ELabelType get_label_type() const=0;
261 
262  public:
264  static const int32_t REJECTION_LABEL = -2;
265 
266  private:
267  void init();
268 
269  protected:
272 };
273 
279  template<> inline
280  SGVector<float64_t> CDenseLabels::get_labels_t<float64_t>()
281  {
282  if (m_subset_stack->has_subsets())
283  return get_labels_copy_t<float64_t>();
284 
285  return m_labels;
286  }
287 }
288 #endif
SGVector< float64_t > m_labels
Definition: DenseLabels.h:271
void set_int_labels(SGVector< int32_t > labels)
virtual int32_t get_num_labels() const
int32_t index_t
Definition: common.h:62
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual ELabelType get_label_type() const =0
CSubsetStack * m_subset_stack
Definition: Labels.h:140
float64_t get_label(int32_t idx)
SGVector< float64_t > get_labels_copy()
Definition: DenseLabels.cpp:90
bool set_label(int32_t idx, float64_t label)
SGVector< float64_t > get_labels()
Definition: DenseLabels.cpp:82
index_t vlen
Definition: SGVector.h:492
#define ASSERT(x)
Definition: SGIO.h:201
int32_t get_int_label(int32_t idx)
double float64_t
Definition: common.h:50
static const int32_t REJECTION_LABEL
Definition: DenseLabels.h:264
A File access base class.
Definition: File.h:34
index_t subset_idx_conversion(index_t idx) const
Definition: SubsetStack.h:105
void set_to_const(float64_t c)
Definition: DenseLabels.cpp:63
SGVector< int32_t > get_int_labels()
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual void ensure_valid(const char *context=NULL)
bool set_int_label(int32_t idx, int32_t label)
virtual bool has_subsets() const
Definition: SubsetStack.h:89
Dense integer or floating point labels.
Definition: DenseLabels.h:35
ST get_label_t(int32_t idx)
Definition: DenseLabels.h:123
SGVector< ST > get_labels_copy_t()
Definition: DenseLabels.h:172
void set_labels(SGVector< float64_t > v)
Definition: DenseLabels.cpp:74
virtual void load(CFile *loader)
ELabelType
Definition: LabelTypes.h:15
virtual void save(CFile *writer)
SGVector< ST > get_labels_t()
Definition: DenseLabels.h:153

SHOGUN Machine Learning Toolbox - Documentation