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 Viktor Gal 00008 * Copyright (C) 2012 Viktor Gal 00009 */ 00010 00011 #include <shogun/latent/LatentSOSVM.h> 00012 #include <shogun/structure/DualLibQPBMSOSVM.h> 00013 00014 using namespace shogun; 00015 00016 CLatentSOSVM::CLatentSOSVM() 00017 : CLinearLatentMachine() 00018 { 00019 register_parameters(); 00020 } 00021 00022 CLatentSOSVM::CLatentSOSVM(CLatentModel* model, CLinearStructuredOutputMachine* so_solver, float64_t C) 00023 : CLinearLatentMachine(model, C) 00024 { 00025 register_parameters(); 00026 set_so_solver(so_solver); 00027 } 00028 00029 CLatentSOSVM::~CLatentSOSVM() 00030 { 00031 SG_UNREF(m_so_solver); 00032 } 00033 00034 CLatentLabels* CLatentSOSVM::apply_latent() 00035 { 00036 return NULL; 00037 } 00038 00039 void CLatentSOSVM::set_so_solver(CLinearStructuredOutputMachine* so) 00040 { 00041 SG_UNREF(m_so_solver); 00042 SG_REF(so); 00043 m_so_solver = so; 00044 } 00045 00046 float64_t CLatentSOSVM::do_inner_loop(float64_t cooling_eps) 00047 { 00048 float64_t lambda = 1/m_C; 00049 CDualLibQPBMSOSVM* so = new CDualLibQPBMSOSVM(); 00050 so->set_lambda(lambda); 00051 so->train(); 00052 00053 /* copy the resulting w */ 00054 SGVector<float64_t> cur_w = so->get_w(); 00055 memcpy(w.vector, cur_w.vector, cur_w.vlen*sizeof(float64_t)); 00056 00057 /* get the primal objective value */ 00058 float64_t po = so->get_result().Fp; 00059 00060 SG_UNREF(so); 00061 00062 return po; 00063 } 00064 00065 void CLatentSOSVM::register_parameters() 00066 { 00067 m_parameters->add((CSGObject**)&m_so_solver, "so_solver", "Structured Output Solver."); 00068 } 00069