SHOGUN  6.1.3
Labels.cpp
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-2012 Heiko Strathmann
10  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
11  */
12 
13 #include <shogun/labels/Labels.h>
14 #include <shogun/lib/common.h>
15 #include <shogun/io/SGIO.h>
16 
17 using namespace shogun;
18 
20  : CSGObject()
21 {
22  init();
23 }
24 
26 {
28 }
29 
30 void CLabels::init()
31 {
32  SG_ADD((CSGObject **)&m_subset_stack, "subset_stack",
33  "Current subset stack", MS_NOT_AVAILABLE);
34  SG_ADD(
35  &m_current_values, "current_values", "current active value vector",
39 }
40 
42 {
43  m_subset_stack->add_subset(subset);
44 }
45 
47 {
49 }
50 
52 {
54 }
55 
57 {
59 }
60 
62 {
64  return m_subset_stack;
65 }
66 
68 {
70  int32_t real_num = m_subset_stack->subset_idx_conversion(idx);
71  return m_current_values.vector[real_num];
72 }
73 
74 void CLabels::set_value(float64_t value, int32_t idx)
75 {
76 
77  REQUIRE(m_current_values.vector, "%s::set_value(%f, %d): No values vector"
78  " set!\n", get_name(), value, idx);
79  REQUIRE(get_num_labels(), "%s::set_value(%f, %d): Number of values is "
80  "zero!\n", get_name(), value, idx);
81 
82  int32_t real_num = m_subset_stack->subset_idx_conversion(idx);
83  m_current_values.vector[real_num] = value;
84 }
85 
87 {
89  {
90  SG_ERROR("length of value values should match number of labels or"
91  " have zero length (len(labels)=%d, len(values)=%d)\n",
92  get_num_labels(), values.vlen);
93  }
94 
95  m_current_values = values;
96 }
97 
99 {
100  return m_current_values;
101 }
virtual const char * get_name() const =0
virtual float64_t get_value(int32_t idx)
Definition: Labels.cpp:67
virtual void remove_all_subsets()
Definition: Labels.cpp:56
virtual int32_t get_num_labels() const =0
#define SG_ERROR(...)
Definition: SGIO.h:128
#define REQUIRE(x,...)
Definition: SGIO.h:181
CSubsetStack * m_subset_stack
Definition: Labels.h:145
#define SG_REF(x)
Definition: SGObject.h:52
class to add subset support to another class. A CSubsetStackStack instance should be added and wrappe...
Definition: SubsetStack.h:37
virtual void add_subset(SGVector< index_t > subset)
Definition: SubsetStack.cpp:84
#define ASSERT(x)
Definition: SGIO.h:176
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:124
virtual void remove_all_subsets()
Definition: SubsetStack.cpp:62
virtual void add_subset_in_place(SGVector< index_t > subset)
double float64_t
Definition: common.h:60
virtual void set_value(float64_t value, int32_t idx)
Definition: Labels.cpp:74
virtual void remove_subset()
Definition: Labels.cpp:51
virtual void add_subset(SGVector< index_t > subset)
Definition: Labels.cpp:41
index_t subset_idx_conversion(index_t idx) const
Definition: SubsetStack.h:105
virtual SGVector< float64_t > get_values()
Definition: Labels.cpp:98
#define SG_UNREF(x)
Definition: SGObject.h:53
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual CSubsetStack * get_subset_stack()
Definition: Labels.cpp:61
virtual void remove_subset()
SGVector< float64_t > m_current_values
Definition: Labels.h:148
virtual ~CLabels()
Definition: Labels.cpp:25
#define SG_ADD(...)
Definition: SGObject.h:93
virtual void add_subset_in_place(SGVector< index_t > subset)
Definition: Labels.cpp:46
virtual void set_values(SGVector< float64_t > values)
Definition: Labels.cpp:86
index_t vlen
Definition: SGVector.h:571

SHOGUN Machine Learning Toolbox - Documentation