DualLibQPBMSOSVM.cpp

Go to the documentation of this file.
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 Michal Uricar
00008  * Copyright (C) 2012 Michal Uricar
00009  */
00010 
00011 #include <shogun/structure/DualLibQPBMSOSVM.h>
00012 #include <shogun/structure/libppbm.h>
00013 #include <shogun/structure/libp3bm.h>
00014 
00015 using namespace shogun;
00016 
00017 CDualLibQPBMSOSVM::CDualLibQPBMSOSVM()
00018 :CLinearStructuredOutputMachine()
00019 {
00020 }
00021 
00022 CDualLibQPBMSOSVM::CDualLibQPBMSOSVM(
00023         CStructuredModel*       model,
00024         CLossFunction*          loss,
00025         CStructuredLabels*      labs,
00026         float64_t               _lambda,
00027         SGVector< float64_t >   W)
00028  : CLinearStructuredOutputMachine(model, loss, labs)
00029 {
00030     set_TolRel(0.001);
00031     set_TolAbs(0.0);
00032     set_BufSize(1000);
00033     set_lambda(_lambda);
00034     set_cleanICP(true);
00035     set_cleanAfter(10);
00036     set_K(0.4);
00037     set_Tmax(100);
00038     set_cp_models(1);
00039     set_verbose(true);
00040     set_solver(BMRM);
00041 
00042     // get dimension of w
00043     uint32_t nDim=this->m_model->get_dim();
00044 
00045     // Check for initial solution
00046     if (W.vlen==0)
00047     {
00048         m_w=SGVector< float64_t >(nDim);
00049 
00050         m_w.zero();
00051     }
00052     else
00053     {
00054         set_w(W);
00055     }
00056 
00057     init();
00058 }
00059 
00060 CDualLibQPBMSOSVM::~CDualLibQPBMSOSVM()
00061 {
00062 }
00063 
00064 void CDualLibQPBMSOSVM::init()
00065 {
00066     SG_ADD(&m_TolRel, "m_TolRel", "Relative tolerance", MS_NOT_AVAILABLE);
00067     SG_ADD(&m_TolAbs, "m_TolAbs", "Absolute tolerance", MS_NOT_AVAILABLE);
00068     SG_ADD(&m_BufSize, "m_BuffSize", "Size of CP Buffer", MS_AVAILABLE);
00069     SG_ADD(&m_lambda, "m_lambda", "Regularization constant lambda",
00070             MS_AVAILABLE);
00071     SG_ADD(&m_cleanICP, "m_cleanICP", "Inactive cutting plane removal flag",
00072             MS_AVAILABLE);
00073     SG_ADD(&m_cleanAfter,
00074             "m_cleanAfter",
00075             "Number of inactive iterations after which ICP will be removed",
00076             MS_NOT_AVAILABLE);
00077     SG_ADD(&m_K, "m_K", "Parameter K", MS_NOT_AVAILABLE);
00078     SG_ADD(&m_Tmax, "m_Tmax", "Parameter Tmax", MS_AVAILABLE);
00079     SG_ADD(&m_cp_models, "m_cp_models", "Number of cutting plane models",
00080             MS_AVAILABLE);
00081     SG_ADD(&m_verbose, "m_verbose", "Verbosity flag", MS_AVAILABLE);
00082 }
00083 
00084 bool CDualLibQPBMSOSVM::train_machine(CFeatures* data)
00085 {
00086     if (data)
00087         set_features(data);
00088 
00089     // call the solver
00090     switch(m_solver)
00091     {
00092         case BMRM:
00093             m_result=svm_bmrm_solver(m_model, m_w.vector, m_TolRel, m_TolAbs,
00094                     m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
00095                     m_verbose);
00096             break;
00097         case PPBMRM:
00098             m_result=svm_ppbm_solver(m_model, m_w.vector, m_TolRel, m_TolAbs,
00099                     m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
00100                     m_verbose);
00101             break;
00102         case P3BMRM:
00103             m_result=svm_p3bm_solver(m_model, m_w.vector, m_TolRel, m_TolAbs,
00104                     m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
00105                     m_cp_models, m_verbose);
00106             break;
00107     }
00108 
00109     if (m_result.exitflag==1)
00110     {
00111         return true;
00112     }
00113     else
00114     {
00115         return false;
00116     }
00117 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation