ECOCPAK v0.9
Classifier_ncc.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_NCC_H_
00025 #define _CLASSIFIER_NCC_H_
00026 
00027 
00028 
00029 #include "Classifier.hpp"
00030 
00031 
00032 
00039 class Classifier_ncc : public Classifier
00040   {
00041   public:
00042 
00043   // ---------------------------------------------------------------- //
00044   // ------------------------ Constructors -------------------------- //
00045   // ---------------------------------------------------------------- //
00046 
00047   // Copy ctor -- Overloaded
00048   Classifier_ncc
00049     (
00050     const Classifier_ncc& c
00051     );
00052 
00053   // User defined ctor NCC -- Overloaded
00054   Classifier_ncc
00055     (
00056     const mat& A,
00057     const mat& B
00058     );
00059 
00060   // ---------------------------------------------------------------- //
00061   // ---------------------- Member Functions ------------------------ //
00062   // ---------------------------------------------------------------- //
00063 
00064   // return prediction value of classifier for input feature vector
00065   double predict(const rowvec& t) const;
00066 
00067   // ---------------------------------------------------------------- //
00068   // -------------------------- Attributes -------------------------- //
00069   // ---------------------------------------------------------------- //
00070 
00071   // centroids for ncc
00072   mat centroids;
00073 
00074   // centroids middle
00075   rowvec middle;
00076   };
00077 
00078 
00079 
00087 Classifier_ncc::Classifier_ncc
00088   (
00089   const Classifier_ncc& c
00090   )
00091   {
00092   // update centers attribute
00093   centroids = c.centroids;
00094 
00095   // update middle attribute
00096   middle = c.middle;
00097 
00098   // update the plus and minus classes
00099   pos = c.pos;
00100   neg = c.neg;
00101 
00102   // update number of possitive and negative samples
00103   n_pos = c.n_pos;
00104   n_neg = c.n_neg;
00105 
00106   // update training error
00107   training_error = c.training_error;
00108   }
00109 
00110 
00111 
00120 Classifier_ncc::Classifier_ncc
00121   (
00122   const mat& A,
00123   const mat& B
00124   )
00125   {
00126   // allocate centroids
00127   centroids = zeros<mat>(2, A.n_cols);
00128 
00129   // find centroid for first class
00130   centroids.row(0) = mean(A);
00131 
00132   // find centroid for second class
00133   centroids.row(1) = mean(B);
00134 
00135   // find out middle
00136   middle = sum(centroids) / 2.0;
00137 
00138   // initialize number of possitive and negative samples
00139   n_pos = 0;
00140   n_neg = 0;
00141   }
00142 
00143 
00144 
00157 inline
00158 double
00159 Classifier_ncc::predict(const rowvec& t) const
00160   {
00161   // return prediction
00162   return accu((t- middle) % (centroids.row(0) - middle));
00163   }
00164 
00165 
00166 
00167 #endif
00168 
00169 
00170 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerator Defines