yat
0.8.3pre
|
00001 #ifndef _theplu_yat_classifier_svm_ 00002 #define _theplu_yat_classifier_svm_ 00003 00004 // $Id: SVM.h 2384 2010-12-22 14:03:36Z peter $ 00005 00006 /* 00007 Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson 00008 Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér 00009 Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson 00010 Copyright (C) 2009, 2010 Peter Johansson 00011 00012 This file is part of the yat library, http://dev.thep.lu.se/yat 00013 00014 The yat library is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU General Public License as 00016 published by the Free Software Foundation; either version 3 of the 00017 License, or (at your option) any later version. 00018 00019 The yat library is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License 00025 along with yat. If not, see <http://www.gnu.org/licenses/>. 00026 */ 00027 00028 #include "SVindex.h" 00029 #include "Target.h" 00030 #include "yat/utility/Vector.h" 00031 00032 #include <utility> 00033 #include <vector> 00034 00035 namespace theplu { 00036 namespace yat { 00037 namespace utility{ 00038 class Matrix; 00039 } 00040 00041 namespace classifier { 00042 00043 class DataLookup1D; 00044 class DataLookupWeighted1D; 00045 class KernelLookup; 00046 00050 class SVM 00051 { 00052 00053 public: 00057 SVM(void); 00058 00062 SVM(const SVM&); 00063 00067 virtual ~SVM(); 00068 00075 SVM* make_classifier(void) const; 00076 00080 const utility::Vector& alpha(void) const; 00081 00096 double C(void) const; 00097 00103 unsigned long int max_epochs(void) const; 00104 00108 void max_epochs(unsigned long int); 00109 00116 const theplu::yat::utility::Vector& output(void) const; 00117 00132 void predict(const KernelLookup& input, utility::Matrix& predict) const; 00133 00134 /* 00139 double predict(const DataLookup1D& input) const; 00140 00145 double predict(const DataLookupWeighted1D& input) const; 00146 */ 00147 00155 void reset(void); 00156 00160 void set_C(const double); 00161 00195 void train(const KernelLookup& kernel, const Target& target); 00196 00202 bool trained(void) const; 00203 00204 private: 00208 void bounds(double&, double&) const; 00209 00215 void calculate_bias(void); 00216 00220 void calculate_margin(void); 00221 00232 bool choose(const theplu::yat::utility::Vector&); 00233 00237 double kernel_mod(const size_t i, const size_t j) const; 00238 00242 int target(size_t i) const; 00243 00244 utility::Vector alpha_; 00245 double bias_; 00246 double C_inverse_; 00247 // not owned by SVM 00248 const KernelLookup* kernel_; 00249 double margin_; 00250 unsigned long int max_epochs_; 00251 utility::Vector output_; 00252 SVindex sample_; 00253 Target target_; 00254 double tolerance_; 00255 bool trained_; 00256 00257 }; 00258 00259 }}} // of namespace classifier, yat, and theplu 00260 00261 #endif