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 ECOCRANDOMSPARSEENCODER_H__ 00012 #define ECOCRANDOMSPARSEENCODER_H__ 00013 00014 #include <shogun/mathematics/Math.h> 00015 #include <shogun/multiclass/ecoc/ECOCEncoder.h> 00016 00017 namespace shogun 00018 { 00019 00036 class CECOCRandomSparseEncoder: public CECOCEncoder 00037 { 00038 public: 00048 CECOCRandomSparseEncoder(int32_t maxiter=10000, int32_t codelen=0, 00049 float64_t pzero=0.5, float64_t pposone=0.25, float64_t pnegone=0.25); 00050 00052 virtual ~CECOCRandomSparseEncoder() {} 00053 00059 void set_probability(float64_t pzero, float64_t pposone, float64_t pnegone); 00060 00062 virtual const char* get_name() const { return "ECOCRandomSparseEncoder"; } 00063 00073 int32_t get_default_code_length(int32_t num_classes) const 00074 { 00075 return static_cast<int32_t>(CMath::round(15 * CMath::log(num_classes))); 00076 } 00077 00081 virtual SGMatrix<int32_t> create_codebook(int32_t num_classes); 00082 00083 protected: 00085 int32_t m_maxiter; 00087 int32_t m_codelen; 00089 float64_t m_pzero; 00091 float64_t m_pposone; 00093 float64_t m_pnegone; 00094 00095 private: 00101 bool check_probability(float64_t pzero, float64_t pposone, float64_t pnegone) 00102 { 00103 if (CMath::abs(pzero + pposone + pnegone - 1) > 1e-5) 00104 return false; 00105 return true; 00106 } 00107 00109 void init(); 00110 }; 00111 00112 } /* shogun */ 00113 00114 #endif /* end of include guard: ECOCRANDOMSPARSEENCODER_H__ */ 00115