SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Features.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 
15 #include <shogun/io/SGIO.h>
16 #include <shogun/base/Parameter.h>
18 
19 #include <string.h>
20 
21 using namespace shogun;
22 
23 CFeatures::CFeatures(int32_t size)
24 : CSGObject()
25 {
26  init();
27  cache_size = size;
28 }
29 
31 : CSGObject(orig)
32 {
33  init();
34 
35  preproc = orig.preproc;
36  preprocessed = orig.preprocessed;
37  SG_REF(preproc);
38  SG_REF(preprocessed);
39 }
40 
42 : CSGObject()
43 {
44  init();
45 
46  load(loader);
47  SG_INFO("Feature object loaded (%p)\n",this)
48 }
49 
51 {
54  SG_UNREF(preproc);
55  SG_UNREF(preprocessed);
56 }
57 
58 void CFeatures::init()
59 {
60  SG_ADD(&properties, "properties", "Feature properties", MS_NOT_AVAILABLE);
61  SG_ADD(&cache_size, "cache_size", "Size of cache in MB", MS_NOT_AVAILABLE);
62 
63  SG_ADD((CSGObject**) &preproc, "preproc", "Array of preprocessors.",
65  SG_ADD((CSGObject**) &preprocessed, "preprocessed", "Array of preprocessed.",
67 
68  SG_ADD((CSGObject**)&m_subset_stack, "subset_stack", "Stack of subsets",
70 
73 
74  properties = FP_NONE;
75  cache_size = 0;
76  preproc = new CDynamicObjectArray();
77  preprocessed = new CDynamicArray<bool>();
78  SG_REF(preproc);
79  SG_REF(preprocessed);
80 }
81 
83 {
84  ASSERT(p)
85 
86  preproc->push_back(p);
87  preprocessed->push_back(false);
88 }
89 
91 {
92  if (num<preproc->get_num_elements() && num>=0)
93  {
94  return (CPreprocessor*) preproc->get_element(num);
95  }
96  else
97  return NULL;
98 }
99 
101 {
102  int32_t num=0;
103 
104  for (int32_t i=0; i<preproc->get_num_elements(); i++)
105  {
106  if ((*preprocessed)[i])
107  num++;
108  }
109 
110  return num;
111 }
112 
114 {
115  preproc->reset_array();
116  preprocessed->reset_array();
117 }
118 
120 {
121  if (num<preproc->get_num_elements() && num>=0)
122  {
123  preproc->delete_element(num);
124  preprocessed->delete_element(num);
125  }
126 }
127 
129 {
130  int32_t num_preproc = preproc->get_num_elements();
131 
132  for (int32_t i=0; i<num_preproc; i++)
133  {
134  SG_INFO("preproc[%d]=%s applied=%s\n",i,
135  preproc->get_element(i)->get_name(),
136  preprocessed->get_element(i) ? "true" : "false");
137  }
138 }
139 
141 {
142  ASSERT(num<preprocessed->get_num_elements() && num>=0);
143  (*preprocessed)[num]=true;
144 }
145 
146 bool CFeatures::is_preprocessed(int32_t num) const
147 {
148  ASSERT(num<preprocessed->get_num_elements() && num>=0);
149  return (*preprocessed)[num];
150 }
151 
153 {
154  return preproc->get_num_elements();
155 }
156 
158 {
159  return cache_size;
160 }
161 
162 bool CFeatures::reshape(int32_t num_features, int32_t num_vectors)
163 {
165  return false;
166 }
167 
169 {
170  SG_INFO("%p - ", this)
171  switch (get_feature_class())
172  {
173  case C_UNKNOWN:
174  SG_INFO("C_UNKNOWN ")
175  break;
176  case C_DENSE:
177  SG_INFO("C_DENSE ")
178  break;
179  case C_SPARSE:
180  SG_INFO("C_SPARSE ")
181  break;
182  case C_STRING:
183  SG_INFO("C_STRING ")
184  break;
185  case C_COMBINED:
186  SG_INFO("C_COMBINED ")
187  break;
188  case C_COMBINED_DOT:
189  SG_INFO("C_COMBINED_DOT ")
190  break;
191  case C_WD:
192  SG_INFO("C_WD ")
193  break;
194  case C_SPEC:
195  SG_INFO("C_SPEC ")
196  break;
197  case C_WEIGHTEDSPEC:
198  SG_INFO("C_WEIGHTEDSPEC ")
199  break;
200  case C_STREAMING_DENSE:
201  SG_INFO("C_STREAMING_DENSE ")
202  break;
203  case C_STREAMING_SPARSE:
204  SG_INFO("C_STREAMING_SPARSE ")
205  break;
206  case C_STREAMING_STRING:
207  SG_INFO("C_STREAMING_STRING ")
208  break;
209  case C_STREAMING_VW:
210  SG_INFO("C_STREAMING_VW ")
211  break;
212  case C_ANY:
213  SG_INFO("C_ANY ")
214  break;
215  default:
216  SG_ERROR("ERROR UNKNOWN FEATURE CLASS")
217  }
218 
219  switch (get_feature_type())
220  {
221  case F_UNKNOWN:
222  SG_INFO("F_UNKNOWN \n")
223  break;
224  case F_CHAR:
225  SG_INFO("F_CHAR \n")
226  break;
227  case F_BYTE:
228  SG_INFO("F_BYTE \n")
229  break;
230  case F_SHORT:
231  SG_INFO("F_SHORT \n")
232  break;
233  case F_WORD:
234  SG_INFO("F_WORD \n")
235  break;
236  case F_INT:
237  SG_INFO("F_INT \n")
238  break;
239  case F_UINT:
240  SG_INFO("F_UINT \n")
241  break;
242  case F_LONG:
243  SG_INFO("F_LONG \n")
244  break;
245  case F_ULONG:
246  SG_INFO("F_ULONG \n")
247  break;
248  case F_SHORTREAL:
249  SG_INFO("F_SHORTEAL \n")
250  break;
251  case F_DREAL:
252  SG_INFO("F_DREAL \n")
253  break;
254  case F_LONGREAL:
255  SG_INFO("F_LONGREAL \n")
256  break;
257  case F_ANY:
258  SG_INFO("F_ANY \n")
259  break;
260  default:
261  SG_ERROR("ERROR UNKNOWN FEATURE TYPE\n")
262  }
263 }
264 
265 
266 void CFeatures::load(CFile* loader)
267 {
271 }
272 
273 void CFeatures::save(CFile* writer)
274 {
278 }
279 
281 {
282  bool result=false;
283 
284  if (f)
285  {
286  result= ( (this->get_feature_class() == f->get_feature_class()) &&
287  (this->get_feature_type() == f->get_feature_type()));
288  }
289  return result;
290 }
291 
293 {
294  return (properties & p) != 0;
295 }
296 
298 {
299  properties |= p;
300 }
301 
303 {
304  properties &= (properties | p) ^ p;
305 }
306 
308 {
309  m_subset_stack->add_subset(subset);
311 }
312 
314 {
317 }
318 
320 {
323 }
324 
326 {
327  return m_subset_stack;
328 }
329 
331 {
332  SG_ERROR("%s::copy_subset(): copy_subset and therefore model storage of "
333  "CMachine (required for cross-validation and model-selection is "
334  "not yet implemented yet. Ask developers!\n", get_name());
335  return NULL;
336 }

SHOGUN Machine Learning Toolbox - Documentation