SHOGUN
v2.0.0
|
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) 2012 Chiyuan Zhang 00008 * Copyright (C) 2012 Chiyuan Zhang 00009 */ 00010 00011 #ifndef ECOCDISCRIMINANTENCODER_H__ 00012 #define ECOCDISCRIMINANTENCODER_H__ 00013 00014 #include <vector> 00015 #include <set> 00016 00017 #include <shogun/multiclass/ecoc/ECOCEncoder.h> 00018 #include <shogun/features/DenseFeatures.h> 00019 #include <shogun/labels/Labels.h> 00020 00021 namespace shogun 00022 { 00023 00033 class CECOCDiscriminantEncoder: public CECOCEncoder 00034 { 00035 public: 00037 CECOCDiscriminantEncoder(); 00038 00040 virtual ~CECOCDiscriminantEncoder(); 00041 00043 void set_features(CDenseFeatures<float64_t> *features); 00044 00046 void set_labels(CLabels *labels); 00047 00051 void set_sffs_iterations(int32_t iterations) { m_iterations = iterations; } 00052 00055 int32_t get_sffs_iterations() const { return m_iterations; } 00056 00058 virtual const char* get_name() const { return "ECOCDiscriminantEncoder"; } 00059 00063 virtual SGMatrix<int32_t> create_codebook(int32_t num_classes); 00064 00065 protected: 00067 void init(); 00068 00069 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00070 void binary_partition(const std::vector<int32_t>& classes); 00071 void run_sffs(std::vector<int32_t>& part1, std::vector<int32_t>& part2); 00072 float64_t sffs_iteration(float64_t MI, std::vector<int32_t>& part1, std::set<int32_t>& idata1, 00073 std::vector<int32_t>& part2, std::set<int32_t>& idata2); 00074 float64_t compute_MI(const std::set<int32_t>& idata1, const std::set<int32_t>& idata2); 00075 void compute_hist(int32_t i, float64_t max_val, float64_t min_val, 00076 const std::set<int32_t>& idata, int32_t *hist); 00077 00078 int32_t m_iterations; 00079 int32_t m_num_trees; 00080 00081 SGMatrix<int32_t> m_codebook; 00082 int32_t m_code_idx; 00083 CLabels *m_labels; 00084 CDenseFeatures<float64_t> *m_features; 00085 SGMatrix<float64_t> m_feats; 00086 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 00087 }; 00088 00089 } /* shogun */ 00090 00091 #endif /* end of include guard: ECOCDISCRIMINANTENCODER_H__ */ 00092