SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIStructure.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) 2008 Soeren Sonnenburg
8  * Copyright (C) 2008 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 
12 #ifndef _GUISTRUCTURE_H__
13 #define _GUISTRUCTURE_H__
14 
15 #include <shogun/lib/config.h>
16 #include <shogun/base/SGObject.h>
17 #include <shogun/structure/Plif.h>
22 
23 namespace shogun
24 {
25 class CSGInterface;
26 
28 class CGUIStructure : public CSGObject
29 {
30  public:
36  CGUIStructure(CSGInterface* interface);
39 
43  inline bool set_dyn_prog(CDynProg* h)
44  {
45  SG_UNREF(m_dp);
46  m_dp = h;
47  return true;
48  }
49 
52  {
53  if (!m_dp)
54  SG_ERROR("no DynProg object found, use set_model first\n");
55  return m_dp;
56  }
57 
61  inline float64_t* get_feature_matrix(bool copy)
62  {
63  if (copy)
64  {
65  int32_t len = m_feature_dims[0]*m_feature_dims[1]*m_feature_dims[2];
66  float64_t* d_cpy = SG_MALLOC(float64_t, len);
67  memcpy(d_cpy, m_feature_matrix,len*sizeof(float64_t));
68  return d_cpy;
69  }
70  else
71  return m_feature_matrix;
72  }
73 
78  {
79  ASSERT(index>=0 && index<=1) ;
80  if (index==0)
82  if (index==1)
84  return NULL ;
85  }
86 
91  inline bool set_feature_matrix(float64_t* feat, int32_t* dims)
92  {
94  int32_t len = dims[0]*dims[1]*dims[2];
96  memcpy(m_feature_matrix, feat, len*sizeof(float64_t));
97  return true;
98  }
99 
106  {
109 
110  m_feature_matrix_sparse1 = new CSparseFeatures<float64_t>(f1, dims[0], dims[1], true) ;
111  m_feature_matrix_sparse2 = new CSparseFeatures<float64_t>(f2, dims[0], dims[1], true) ;
112 
113  return true;
114  }
115 
119  inline bool set_feature_dims(int32_t* dims)
120  {
122  m_feature_dims = SG_MALLOC(int32_t, 3);
123  memcpy(m_feature_dims, dims,3*sizeof(int32_t));
124  return true;
125  }
127  inline int32_t* get_feature_dims() { return m_feature_dims; }
128 
133  inline bool set_all_pos(int32_t* pos, int32_t Npos)
134  {
135  if (m_all_positions!=pos)
137  int32_t* cp_array = SG_MALLOC(int32_t, Npos);
138  memcpy(cp_array, pos, Npos*sizeof(int32_t));
139  m_num_positions = Npos;
140  m_all_positions = cp_array;
141  return true;
142  }
144  inline int32_t* get_all_positions() { return m_all_positions; }
146  inline int32_t get_num_positions() { return m_num_positions; }
147 
154  float64_t* weights, int32_t Nweights,
155  int32_t Mweights /* ==num_svms */)
156  {
157  if (m_content_svm_weights!=weights)
159  float64_t* cp_array = SG_MALLOC(float64_t, Nweights*Mweights);
160  memcpy(cp_array, weights,Nweights*Mweights*sizeof(float64_t));
161  m_content_svm_weights = cp_array;
162  m_num_svm_weights = Nweights;
163  return true;
164  }
168  inline int32_t get_num_svm_weights() { return m_num_svm_weights; }
169 
172 
178  inline bool set_orf_info(
179  int32_t* orf_info, int32_t Norf_info, int32_t Morf_info)
180  {
181  if (m_orf_info!=orf_info)
183  int32_t* cp_array = SG_MALLOC(int32_t, Norf_info*Morf_info);
184  memcpy(cp_array, orf_info,Norf_info*Morf_info*sizeof(int32_t));
185  m_orf_info = cp_array;
186  return true;
187  }
188 
190  inline int32_t* get_orf_info()
191  {
192  return m_orf_info;
193  }
194 
198  inline bool set_use_orf(bool use_orf)
199  {
200  m_use_orf = use_orf;
201  return true;
202  }
204  inline bool get_use_orf() { return m_use_orf; }
205 
211  inline bool set_mod_words(
212  int32_t* mod_words, int32_t Nmod_words, int32_t Mmod_words)
213  {
214  if (mod_words!=m_mod_words)
216  int32_t* cp_array = SG_MALLOC(int32_t, Nmod_words*Mmod_words);
217  memcpy(cp_array, mod_words, Nmod_words*Mmod_words*sizeof(int32_t));
218  m_mod_words = cp_array;
219  return true;
220  }
222  inline int32_t* get_mod_words() { return m_mod_words; }
224  inline int32_t get_num_states() { return m_num_states; }
228  inline bool set_num_states(int32_t num)
229  {
230  m_num_states = num;
231  return true;
232  }
234  inline bool cleanup()
235  {
236  delete m_dp;
237  //SG_FREE(m_feature_matrix);
238  //delete m_feature_matrix_sparse1;
239  //delete m_feature_matrix_sparse2;
240  //SG_FREE(m_feature_dims);
241  //SG_FREE(m_all_positions);
242  //SG_FREE(m_content_svm_weights);
243  //delete m_orf_info;
244  //delete m_mod_words;
245  //delete m_plif_matrix;
246 
247  return true;
248  }
249 
251  inline virtual const char* get_name() const { return "GUIStructure"; }
252 
253  protected:
255  CSGInterface* ui;
257  int32_t m_num_plifs;
259  int32_t m_num_limits;
261  int32_t m_num_states;
271  int32_t* m_feature_dims;
275  int32_t* m_all_positions;
281  int32_t* m_orf_info;
283  bool m_use_orf;
285  int32_t* m_mod_words;
288 };
289 }
290 #endif
291 

SHOGUN Machine Learning Toolbox - Documentation