SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIFeatures.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-2008 Soeren Sonnenburg
8  * Written (W) 1999-2008 Gunnar Raetsch
9  * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #ifndef __GUIFEATURES__H
13 #define __GUIFEATURES__H
14 
15 #include <shogun/lib/config.h>
16 #include <shogun/base/SGObject.h>
17 #include <shogun/labels/Labels.h>
30 
31 namespace shogun
32 {
33 class CSGInterface;
34 
36 class CGUIFeatures : public CSGObject
37 {
39  enum EFeatureType
40  {
41  Simple,
42  Sparse
43  };
44 
45  public:
51  CGUIFeatures(CSGInterface* interface);
53  ~CGUIFeatures();
54 
59 
63  inline bool set_train_features(CFeatures* f)
64  {
65  //invalidate_train();
66  SG_REF(f);
69  return true;
70  }
71 
75  inline bool set_test_features(CFeatures* f)
76  {
77  //invalidate_test();
78  SG_REF(f);
80  test_features=f;
81  return true;
82  }
83 
100 
102  bool del_last_feature_obj(char* target);
103 
105  void invalidate_train();
107  void invalidate_test();
108 
110  bool load(
111  char* filename, char* fclass, char* type, char* target,
112  int32_t size, int32_t comp_features);
114  bool save(char* filename, char* type, char* target);
116  bool clean(char* target);
118  bool reshape(char* target, int32_t num_feat, int32_t num_vec);
119 
121  CFeatures* get_convert_features(char* target);
123  bool set_convert_features(CFeatures* features, char* target);
124 
134  CDenseFeatures<char>* src);
141  float64_t gap_cost=0);
147 
168  CStringFeatures<uint16_t>* src, bool use_norm);
169 
178  template <class CT, class ST>
180  CStringFeatures<CT>* src,
181  int32_t order=1, int32_t start=0, int32_t gap=0, char rev='f', CAlphabet* alpha=NULL)
182  {
183  if (src && src->get_feature_class()==C_STRING)
184  {
185  //create dense features with 0 cache
186  SG_INFO("Converting CT STRING features to ST STRING ones (order=%i).\n",order)
187  bool free_alpha=false;
188 
189  if (!alpha)
190  {
191  CAlphabet* a = src->get_alphabet();
192 
193  if ( a && a->get_alphabet() == DNA )
194  alpha=new CAlphabet(RAWDNA);
195  else
196  alpha=new CAlphabet(a);
197 
198  free_alpha=true;
199  SG_UNREF(a);
200  }
201 
203  if (sf && sf->obtain_from_char_features(src, start, order, gap, rev=='r'))
204  {
205  SG_INFO("Conversion was successful.\n")
206  return sf;
207  }
208 
209  if (free_alpha)
210  SG_UNREF(alpha);
211  SG_UNREF(sf);
212  }
213  else
214  SG_ERROR("No features of class/type STRING/CT available.\n")
215 
216  return NULL;
217  }
218 
219 
221  bool set_reference_features(char* target);
222 
224  virtual const char* get_name() const { return "GUIFeatures"; }
225 
226  protected:
228  CSGInterface* ui;
235 };
236 }
237 #endif

SHOGUN Machine Learning Toolbox - Documentation