SHOGUN  3.2.1
 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  // Call to init creates new preproc and preprocessed arrays.
36  SG_UNREF(preproc);
37  SG_UNREF(preprocessed);
38  preproc = orig.preproc;
39  preprocessed = orig.preprocessed;
40  SG_REF(preproc);
41  SG_REF(preprocessed);
42 }
43 
45 : CSGObject()
46 {
47  init();
48 
49  load(loader);
50  SG_INFO("Feature object loaded (%p)\n",this)
51 }
52 
54 {
57  SG_UNREF(preproc);
58  SG_UNREF(preprocessed);
59 }
60 
61 void CFeatures::init()
62 {
63  SG_ADD(&properties, "properties", "Feature properties", MS_NOT_AVAILABLE);
64  SG_ADD(&cache_size, "cache_size", "Size of cache in MB", MS_NOT_AVAILABLE);
65 
66  SG_ADD((CSGObject**) &preproc, "preproc", "Array of preprocessors.",
68  SG_ADD((CSGObject**) &preprocessed, "preprocessed", "Array of preprocessed.",
70 
71  SG_ADD((CSGObject**)&m_subset_stack, "subset_stack", "Stack of subsets",
73 
76 
77  properties = FP_NONE;
78  cache_size = 0;
79  preproc = new CDynamicObjectArray();
80  preprocessed = new CDynamicArray<bool>();
81  SG_REF(preproc);
82  SG_REF(preprocessed);
83 }
84 
86 {
87  ASSERT(p)
88 
89  preproc->push_back(p);
90  preprocessed->push_back(false);
91 }
92 
94 {
95  if (num<preproc->get_num_elements() && num>=0)
96  {
97  return (CPreprocessor*) preproc->get_element(num);
98  }
99  else
100  return NULL;
101 }
102 
104 {
105  int32_t num=0;
106 
107  for (int32_t i=0; i<preproc->get_num_elements(); i++)
108  {
109  if ((*preprocessed)[i])
110  num++;
111  }
112 
113  return num;
114 }
115 
117 {
118  preproc->reset_array();
119  preprocessed->reset_array();
120 }
121 
123 {
124  if (num<preproc->get_num_elements() && num>=0)
125  {
126  preproc->delete_element(num);
127  preprocessed->delete_element(num);
128  }
129 }
130 
132 {
133  int32_t num_preproc = preproc->get_num_elements();
134 
135  for (int32_t i=0; i<num_preproc; i++)
136  {
137  SG_INFO("preproc[%d]=%s applied=%s\n",i,
138  preproc->get_element(i)->get_name(),
139  preprocessed->get_element(i) ? "true" : "false");
140  }
141 }
142 
144 {
145  ASSERT(num<preprocessed->get_num_elements() && num>=0);
146  (*preprocessed)[num]=true;
147 }
148 
149 bool CFeatures::is_preprocessed(int32_t num) const
150 {
151  ASSERT(num<preprocessed->get_num_elements() && num>=0);
152  return (*preprocessed)[num];
153 }
154 
156 {
157  return preproc->get_num_elements();
158 }
159 
161 {
162  return cache_size;
163 }
164 
165 bool CFeatures::reshape(int32_t num_features, int32_t num_vectors)
166 {
168  return false;
169 }
170 
172 {
173  SG_INFO("%p - ", this)
174  switch (get_feature_class())
175  {
176  case C_UNKNOWN:
177  SG_INFO("C_UNKNOWN ")
178  break;
179  case C_DENSE:
180  SG_INFO("C_DENSE ")
181  break;
182  case C_SPARSE:
183  SG_INFO("C_SPARSE ")
184  break;
185  case C_STRING:
186  SG_INFO("C_STRING ")
187  break;
188  case C_COMBINED:
189  SG_INFO("C_COMBINED ")
190  break;
191  case C_COMBINED_DOT:
192  SG_INFO("C_COMBINED_DOT ")
193  break;
194  case C_WD:
195  SG_INFO("C_WD ")
196  break;
197  case C_SPEC:
198  SG_INFO("C_SPEC ")
199  break;
200  case C_WEIGHTEDSPEC:
201  SG_INFO("C_WEIGHTEDSPEC ")
202  break;
203  case C_STREAMING_DENSE:
204  SG_INFO("C_STREAMING_DENSE ")
205  break;
206  case C_STREAMING_SPARSE:
207  SG_INFO("C_STREAMING_SPARSE ")
208  break;
209  case C_STREAMING_STRING:
210  SG_INFO("C_STREAMING_STRING ")
211  break;
212  case C_STREAMING_VW:
213  SG_INFO("C_STREAMING_VW ")
214  break;
215  case C_ANY:
216  SG_INFO("C_ANY ")
217  break;
218  default:
219  SG_ERROR("ERROR UNKNOWN FEATURE CLASS")
220  }
221 
222  switch (get_feature_type())
223  {
224  case F_UNKNOWN:
225  SG_INFO("F_UNKNOWN \n")
226  break;
227  case F_CHAR:
228  SG_INFO("F_CHAR \n")
229  break;
230  case F_BYTE:
231  SG_INFO("F_BYTE \n")
232  break;
233  case F_SHORT:
234  SG_INFO("F_SHORT \n")
235  break;
236  case F_WORD:
237  SG_INFO("F_WORD \n")
238  break;
239  case F_INT:
240  SG_INFO("F_INT \n")
241  break;
242  case F_UINT:
243  SG_INFO("F_UINT \n")
244  break;
245  case F_LONG:
246  SG_INFO("F_LONG \n")
247  break;
248  case F_ULONG:
249  SG_INFO("F_ULONG \n")
250  break;
251  case F_SHORTREAL:
252  SG_INFO("F_SHORTEAL \n")
253  break;
254  case F_DREAL:
255  SG_INFO("F_DREAL \n")
256  break;
257  case F_LONGREAL:
258  SG_INFO("F_LONGREAL \n")
259  break;
260  case F_ANY:
261  SG_INFO("F_ANY \n")
262  break;
263  default:
264  SG_ERROR("ERROR UNKNOWN FEATURE TYPE\n")
265  }
266 }
267 
268 
269 void CFeatures::load(CFile* loader)
270 {
274 }
275 
276 void CFeatures::save(CFile* writer)
277 {
281 }
282 
284 {
285  bool result=false;
286 
287  if (f)
288  {
289  result= ( (this->get_feature_class() == f->get_feature_class()) &&
290  (this->get_feature_type() == f->get_feature_type()));
291  }
292  return result;
293 }
294 
296 {
297  return (properties & p) != 0;
298 }
299 
301 {
302  properties |= p;
303 }
304 
306 {
307  properties &= (properties | p) ^ p;
308 }
309 
311 {
312  m_subset_stack->add_subset(subset);
314 }
315 
317 {
320 }
321 
323 {
326 }
327 
329 {
332 }
333 
335 {
337  return m_subset_stack;
338 }
339 
341 {
342  SG_ERROR("%s::copy_subset(): copy_subset and therefore model storage of "
343  "CMachine (required for cross-validation and model-selection is "
344  "not yet implemented yet. Ask developers!\n", get_name());
345  return NULL;
346 }
347 
349 {
350  SG_WARNING("%s::copy_dimension_subset():: Is not yet implemented!\n",
351  get_name());
352  return NULL;
353 }

SHOGUN Machine Learning Toolbox - Documentation