SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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/libbmrm.h>
00013 #include <shogun/structure/libppbm.h>
00014 #include <shogun/structure/libp3bm.h>
00015 #include <shogun/structure/libncbm.h>
00016 
00017 using namespace shogun;
00018 
00019 CDualLibQPBMSOSVM::CDualLibQPBMSOSVM()
00020 :CLinearStructuredOutputMachine()
00021 {
00022     init();
00023 }
00024 
00025 CDualLibQPBMSOSVM::CDualLibQPBMSOSVM(
00026         CStructuredModel*   model,
00027         CStructuredLabels*  labs,
00028         float64_t   _lambda,
00029         SGVector< float64_t >   W)
00030  : CLinearStructuredOutputMachine(model, labs)
00031 {
00032     init();
00033     set_lambda(_lambda);
00034 
00035     // get dimension of w
00036     int32_t nDim=this->m_model->get_dim();
00037 
00038     // Check for initial solution
00039     if (W.vlen==0)
00040     {
00041         set_w(SGVector< float64_t >(nDim));
00042         get_w().zero();
00043     }
00044     else
00045     {
00046         ASSERT(W.size() == nDim);
00047         set_w(W);
00048     }
00049 }
00050 
00051 CDualLibQPBMSOSVM::~CDualLibQPBMSOSVM()
00052 {
00053 }
00054 
00055 void CDualLibQPBMSOSVM::init()
00056 {
00057     SG_ADD(&m_TolRel, "m_TolRel", "Relative tolerance", MS_AVAILABLE);
00058     SG_ADD(&m_TolAbs, "m_TolAbs", "Absolute tolerance", MS_AVAILABLE);
00059     SG_ADD(&m_BufSize, "m_BuffSize", "Size of CP Buffer", MS_AVAILABLE);
00060     SG_ADD(&m_lambda, "m_lambda", "Regularization constant lambda",
00061             MS_AVAILABLE);
00062     SG_ADD(&m_cleanICP, "m_cleanICP", "Inactive cutting plane removal flag",
00063             MS_AVAILABLE);
00064     SG_ADD(&m_cleanAfter,
00065             "m_cleanAfter",
00066             "Number of inactive iterations after which ICP will be removed",
00067             MS_AVAILABLE);
00068     SG_ADD(&m_K, "m_K", "Parameter K", MS_NOT_AVAILABLE);
00069     SG_ADD(&m_Tmax, "m_Tmax", "Parameter Tmax", MS_AVAILABLE);
00070     SG_ADD(&m_cp_models, "m_cp_models", "Number of cutting plane models",
00071             MS_AVAILABLE);
00072 
00073     set_TolRel(0.001);
00074     set_TolAbs(0.0);
00075     set_BufSize(1000);
00076     set_lambda(0.0);
00077     set_cleanICP(true);
00078     set_cleanAfter(10);
00079     set_K(0.4);
00080     set_Tmax(100);
00081     set_cp_models(1);
00082     set_solver(BMRM);
00083 }
00084 
00085 bool CDualLibQPBMSOSVM::train_machine(CFeatures* data)
00086 {
00087     if (data)
00088         set_features(data);
00089 
00090     if (m_verbose)
00091     {
00092         if (m_helper != NULL)
00093             SG_UNREF(m_helper);
00094 
00095         m_helper = new CSOSVMHelper();
00096         SG_REF(m_helper);
00097     }
00098 
00099     // Initialize the model for training
00100     m_model->init_training();
00101     // call the solver
00102     switch(m_solver)
00103     {
00104         case BMRM:
00105             m_result=svm_bmrm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
00106                     m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
00107                     m_verbose);
00108             break;
00109         case PPBMRM:
00110             m_result=svm_ppbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
00111                     m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
00112                     m_verbose);
00113             break;
00114         case P3BMRM:
00115             m_result=svm_p3bm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
00116                     m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
00117                     m_cp_models, m_verbose);
00118             break;
00119         case NCBM:
00120             m_result=svm_ncbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
00121                     m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, true /* convex */,
00122                     true /* use line search*/, m_verbose);
00123             break;
00124         default:
00125             SG_ERROR("CDualLibQPBMSOSVM: m_solver=%d is not supported", m_solver);
00126     }
00127 
00128     if (m_result.exitflag>0)
00129         return true;
00130     else
00131         return false;
00132 }
00133 
00134 EMachineType CDualLibQPBMSOSVM::get_classifier_type()
00135 {
00136     return CT_LIBQPSOSVM;
00137 }
00138 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation