ECOCPAK v0.9
Classifier_ls.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2011 the authors listed below
00002 // http://ecocpak.sourceforge.net
00003 //
00004 // Authors:
00005 // - Dimitrios Bouzas (bouzas at ieee dot org)
00006 // - Nikolaos Arvanitopoulos (niarvani at ieee dot org)
00007 // - Anastasios Tefas (tefas at aiia dot csd dot auth dot gr)
00008 //
00009 // This file is part of the ECOC PAK C++ library. It is
00010 // provided without any warranty of fitness for any purpose.
00011 //
00012 // You can redistribute this file and/or modify it under
00013 // the terms of the GNU Lesser General Public License (LGPL)
00014 // as published by the Free Software Foundation, either
00015 // version 3 of the License or (at your option) any later
00016 // version.
00017 // (see http://www.opensource.org/licenses for more info)
00018 
00019 
00022 
00023 
00024 #ifndef _CLASSIFIER_LS_H_
00025 #define _CLASSIFIER_LS_H_
00026 
00027 
00028 
00029 #include "Classifier.hpp"
00030 
00031 
00032 
00037 class Classifier_ls: public Classifier
00038   {
00039   public:
00040 
00041   // ---------------------------------------------------------------- //
00042   // ------------------------ Constructors -------------------------- //
00043   // ---------------------------------------------------------------- //
00044 
00045   // Copy ctor -- Overloaded
00046   Classifier_ls
00047     (
00048     const Classifier_ls& c
00049     );
00050 
00051   // User defined ctor adaBoost -- Overloaded
00052   Classifier_ls
00053     (
00054     const mat& A,
00055     const mat& B
00056     );
00057 
00058   // ---------------------------------------------------------------- //
00059   // ---------------------- Member Functions ------------------------ //
00060   // ---------------------------------------------------------------- //
00061 
00062   // return prediction value of classifier for input feature vector
00063   double predict(const rowvec& t) const;
00064 
00065   // ---------------------------------------------------------------- //
00066   // --------------------- Overloaded Operators --------------------- //
00067   // ---------------------------------------------------------------- //
00068 
00069   // ---------------------------------------------------------------- //
00070   // -------------------------- Attributes -------------------------- //
00071   // ---------------------------------------------------------------- //
00072 
00073   // projection vector
00074   colvec w;
00075   };
00076 
00077 
00078 
00086 Classifier_ls::Classifier_ls
00087   (
00088   const Classifier_ls& c
00089   )
00090   {
00091   // update seperating hyperplane vector
00092   w = c.w;
00093 
00094   // update the plus and minus labels
00095   pos = c.pos;
00096   neg = c.neg;
00097 
00098   // update number of possitive and negative samples
00099   n_pos = c.n_pos;
00100   n_neg = c.n_neg;
00101 
00102   // update training error
00103   training_error = c.training_error;
00104   }
00105 
00106 
00107 
00116 Classifier_ls::Classifier_ls
00117   (
00118   const mat& A,
00119   const mat& B
00120   )
00121   {
00122   // number of first class feature vectors
00123   const u32 n_samplesA = A.n_rows;
00124 
00125   // number of second class feature vectors
00126   const u32 n_samplesB = B.n_rows;
00127 
00128   // number of attributes
00129   const u32 d = A.n_cols;
00130 
00131   // construct total datamatrix
00132   const mat X = join_cols(A,B);
00133 
00134   // construct labels
00135   colvec Y = join_cols
00136                (
00137                ones<colvec>(n_samplesA, 1),
00138                -ones<colvec>(n_samplesB, 1)
00139                );
00140 
00141 
00142   // compute seperation hyperplane vector
00143   w = solve((trans(X) * X) +  param.C * eye<mat>(d,d), trans(X) * Y);
00144 
00145   // initialize number of possitive and negative samples
00146   n_pos = 0;
00147   n_neg = 0;
00148   }
00149 
00150 
00151 
00164 inline
00165 double
00166 Classifier_ls::predict(const rowvec& t) const
00167   {
00168   return as_scalar(t * w);
00169   }
00170 
00171 
00172 
00173 #endif
00174 
00175 
00176 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerator Defines