Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/SVMLinearClassifier.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #ifndef MARSYAS_SVMCLASSIFIER_H
00020 #define MARSYAS_SVMCLASSIFIER_H
00021 
00022 #include <marsyas/system/MarSystem.h>
00023 #include "svm.h"
00024 #include "linear.h"
00025 #include <marsyas/WekaData.h>
00026 
00027 namespace Marsyas
00028 {
00034 class SVMClassifier: public MarSystem
00035 {
00036 private:
00037   MarControlPtr ctrl_sv_coef_ ;
00038   MarControlPtr ctrl_sv_indices_ ;
00039   MarControlPtr ctrl_SV_ ;
00040   MarControlPtr ctrl_rho_ ;
00041   MarControlPtr ctrl_probA_ ;
00042   MarControlPtr ctrl_probB_ ;
00043   MarControlPtr ctrl_label_ ;
00044   MarControlPtr ctrl_nSV_ ;
00045   MarControlPtr ctrl_nr_class_ ;
00046   MarControlPtr ctrl_weight_;
00047   MarControlPtr ctrl_weight_label_;
00048   MarControlPtr ctrl_minimums_;
00049   MarControlPtr ctrl_maximums_;
00050   MarControlPtr ctrl_mode_;
00051   MarControlPtr ctrl_nClasses_;
00052   MarControlPtr ctrl_l_;
00053   MarControlPtr ctrl_svm_;
00054   MarControlPtr ctrl_kernel_;
00055   MarControlPtr ctrl_degree_;
00056   MarControlPtr ctrl_gamma_;
00057   MarControlPtr ctrl_coef0_;
00058   MarControlPtr ctrl_nu_;
00059   MarControlPtr ctrl_cache_size_;
00060   MarControlPtr ctrl_C_;
00061   MarControlPtr ctrl_eps_;
00062   MarControlPtr ctrl_p_;
00063   MarControlPtr ctrl_shrinking_;
00064   MarControlPtr ctrl_probability_;
00065   MarControlPtr ctrl_nr_weight_;
00066   MarControlPtr ctrl_classPerms_;
00067 
00068   std::vector<int> classPerms_;
00069 
00070 
00071   void addControls();
00072   void myUpdate(MarControlPtr sender);
00073 
00074   WekaData instances_;
00075   struct svm_problem svm_prob_;
00076   struct svm_parameter svm_param_;
00077   struct svm_model *svm_model_;
00078   mrs_bool trained_, training_, was_training_;
00079   mrs_natural kernel_, svm_;
00080 
00081   // to clean-up memory leaks
00082   mrs_natural num_nodes;
00083   void ensure_free_svm_model();
00084   void ensure_free_svm_prob_xy();
00085   mrs_natural num_svm_prob_x;
00086 
00087 public:
00088   SVMClassifier(std::string name);
00089   SVMClassifier(const SVMClassifier& a);
00090   ~SVMClassifier();
00091   MarSystem* clone() const;
00092 
00093   void myProcess(realvec& in, realvec& out);
00094 };
00095 
00096 }
00097 
00098 #endif