GUIStructure.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2008 Soeren Sonnenburg
00008  * Copyright (C) 2008 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 
00012 #ifndef _GUISTRUCTURE_H__
00013 #define _GUISTRUCTURE_H__
00014 
00015 #include <shogun/lib/config.h>
00016 #include <shogun/base/SGObject.h>
00017 #include <shogun/structure/Plif.h>
00018 #include <shogun/structure/PlifArray.h>
00019 #include <shogun/structure/PlifBase.h>
00020 #include <shogun/structure/DynProg.h>
00021 #include <shogun/structure/PlifMatrix.h>
00022 
00023 namespace shogun
00024 {
00025 class CSGInterface;
00026 
00028 class CGUIStructure : public CSGObject
00029 {
00030     public:
00032         CGUIStructure() {};
00036         CGUIStructure(CSGInterface* interface);
00038         ~CGUIStructure();
00039 
00043         inline bool set_dyn_prog(CDynProg* h)
00044         {
00045             SG_UNREF(m_dp);
00046             m_dp = h;
00047             return true;
00048         }
00049 
00051         inline CDynProg* get_dyn_prog()
00052         {
00053             if (!m_dp)
00054                 SG_ERROR("no DynProg object found, use set_model first\n");
00055             return m_dp;
00056         }
00057 
00061         inline float64_t* get_feature_matrix(bool copy)
00062         {
00063             if (copy)
00064             {
00065                 int32_t len = m_feature_dims[0]*m_feature_dims[1]*m_feature_dims[2];
00066                 float64_t* d_cpy = SG_MALLOC(float64_t, len);
00067                 memcpy(d_cpy, m_feature_matrix,len*sizeof(float64_t));
00068                 return d_cpy;
00069             }
00070             else
00071                 return m_feature_matrix;
00072         }
00073 
00077         inline CSparseFeatures<float64_t>* get_feature_matrix_sparse(int32_t index)
00078         {
00079             ASSERT(index>=0 && index<=1) ;
00080             if (index==0)
00081                 return m_feature_matrix_sparse1;
00082             if (index==1)
00083                 return m_feature_matrix_sparse2;
00084             return NULL ;
00085         }
00086 
00091         inline bool set_feature_matrix(float64_t* feat, int32_t* dims)
00092         {
00093             SG_FREE(m_feature_matrix);
00094             int32_t len = dims[0]*dims[1]*dims[2];
00095             m_feature_matrix = SG_MALLOC(float64_t, len);
00096             memcpy(m_feature_matrix, feat, len*sizeof(float64_t));
00097             return true;
00098         }
00099 
00105         inline bool set_feature_matrix_sparse(SGSparseVector<float64_t> *f1, SGSparseVector<float64_t> *f2, int32_t* dims)
00106         {
00107             SG_FREE(m_feature_matrix_sparse1);
00108             SG_FREE(m_feature_matrix_sparse2);
00109 
00110             m_feature_matrix_sparse1 = new CSparseFeatures<float64_t>(f1, dims[0], dims[1], true) ;
00111             m_feature_matrix_sparse2 = new CSparseFeatures<float64_t>(f2, dims[0], dims[1], true) ;
00112 
00113             return true;
00114         }
00115 
00119         inline bool set_feature_dims(int32_t* dims)
00120         {
00121             SG_FREE(m_feature_dims);
00122             m_feature_dims = SG_MALLOC(int32_t, 3);
00123             memcpy(m_feature_dims, dims,3*sizeof(int32_t));
00124             return true;
00125         }
00127         inline int32_t* get_feature_dims() { return m_feature_dims; }
00128 
00133         inline bool set_all_pos(int32_t* pos, int32_t Npos)
00134         {
00135             if (m_all_positions!=pos)
00136                 SG_FREE(m_all_positions);
00137             int32_t* cp_array = SG_MALLOC(int32_t, Npos);
00138             memcpy(cp_array, pos, Npos*sizeof(int32_t));
00139             m_num_positions = Npos;
00140             m_all_positions = cp_array;
00141             return true;
00142         }
00144         inline int32_t* get_all_positions() { return m_all_positions; }
00146         inline int32_t get_num_positions() { return m_num_positions; }
00147 
00153         inline bool set_content_svm_weights(
00154             float64_t* weights, int32_t Nweights,
00155             int32_t Mweights /* ==num_svms */)
00156         {
00157             if (m_content_svm_weights!=weights)
00158                 SG_FREE(m_content_svm_weights);
00159             float64_t* cp_array = SG_MALLOC(float64_t, Nweights*Mweights);
00160             memcpy(cp_array, weights,Nweights*Mweights*sizeof(float64_t));
00161             m_content_svm_weights = cp_array;
00162             m_num_svm_weights = Nweights;
00163             return true;
00164         }
00166         inline float64_t* get_content_svm_weights() { return m_content_svm_weights; }
00168         inline int32_t get_num_svm_weights() { return m_num_svm_weights; }
00169 
00171         inline CPlifMatrix* get_plif_matrix() { return m_plif_matrix; }
00172 
00178         inline bool set_orf_info(
00179             int32_t* orf_info, int32_t Norf_info, int32_t Morf_info)
00180         {
00181             if (m_orf_info!=orf_info)
00182                 SG_FREE(m_orf_info);
00183             int32_t* cp_array = SG_MALLOC(int32_t, Norf_info*Morf_info);
00184             memcpy(cp_array, orf_info,Norf_info*Morf_info*sizeof(int32_t));
00185             m_orf_info = cp_array;
00186             return true;
00187         }
00188 
00190         inline int32_t* get_orf_info()
00191         {
00192             return m_orf_info;
00193         }
00194 
00198         inline bool set_use_orf(bool use_orf)
00199         {
00200             m_use_orf = use_orf;
00201             return true;
00202         }
00204         inline bool get_use_orf() { return m_use_orf; }
00205 
00211         inline bool set_mod_words(
00212             int32_t* mod_words, int32_t Nmod_words, int32_t Mmod_words)
00213         {
00214             if (mod_words!=m_mod_words)
00215                 SG_FREE(m_mod_words);
00216             int32_t* cp_array = SG_MALLOC(int32_t, Nmod_words*Mmod_words);
00217             memcpy(cp_array, mod_words, Nmod_words*Mmod_words*sizeof(int32_t));
00218             m_mod_words = cp_array;
00219             return true;
00220         }
00222         inline int32_t* get_mod_words() { return m_mod_words; }
00224         inline int32_t get_num_states() { return m_num_states; }
00228         inline bool set_num_states(int32_t num)
00229         {
00230             m_num_states = num;
00231             return true;
00232         }
00234         inline bool cleanup()
00235         {
00236             delete m_dp;
00237             //SG_FREE(m_feature_matrix);
00238             //delete m_feature_matrix_sparse1;
00239             //delete m_feature_matrix_sparse2;
00240             //SG_FREE(m_feature_dims);
00241             //SG_FREE(m_all_positions);
00242             //SG_FREE(m_content_svm_weights);
00243             //delete m_orf_info;
00244             //delete m_mod_words;
00245             //delete m_plif_matrix;
00246 
00247             return true;
00248         }
00249 
00251         virtual const char* get_name() const { return "GUIStructure"; }
00252 
00253     protected:
00255         CSGInterface* ui;
00257         int32_t m_num_plifs;
00259         int32_t m_num_limits;
00261         int32_t m_num_states;
00263         CDynProg* m_dp;
00265         float64_t* m_feature_matrix;
00267         CSparseFeatures<float64_t>* m_feature_matrix_sparse1;
00269         CSparseFeatures<float64_t>* m_feature_matrix_sparse2;
00271         int32_t* m_feature_dims;
00273         int32_t m_num_positions;
00275         int32_t* m_all_positions;
00277         float64_t* m_content_svm_weights;
00279         int32_t m_num_svm_weights;
00281         int32_t* m_orf_info;
00283         bool m_use_orf;
00285         int32_t* m_mod_words;
00287         CPlifMatrix* m_plif_matrix;
00288 };
00289 }
00290 #endif
00291 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation