SHOGUN
v2.0.0
|
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 * libbmrm.h: Implementation of the BMRM solver for SO training 00008 * 00009 * Copyright (C) 2012 Michal Uricar, uricamic@cmp.felk.cvut.cz 00010 * 00011 * Implementation of the BMRM solver 00012 *--------------------------------------------------------------------- */ 00013 00014 #include <shogun/lib/common.h> 00015 #include <shogun/structure/StructuredModel.h> 00016 00017 #ifndef libbmrm_h 00018 #define libbmrm_h 00019 00020 #define LIBBMRM_PLUS_INF (-log(0.0)) 00021 #define LIBBMRM_CALLOC(x, y) calloc(x, y) 00022 #define LIBBMRM_REALLOC(x, y) realloc(x, y) 00023 #define LIBBMRM_FREE(x) SG_FREE(x) 00024 #define LIBBMRM_MEMCPY(x, y, z) memcpy(x, y, z) 00025 #define LIBBMRM_MEMMOVE(x, y, z) memmove(x, y, z) 00026 #define LIBBMRM_INDEX(ROW, COL, NUM_ROWS) ((COL)*(NUM_ROWS)+(ROW)) 00027 #define LIBBMRM_ABS(A) ((A) < 0 ? -(A) : (A)) 00028 00029 namespace shogun 00030 { 00032 struct bmrm_return_value_T 00033 { 00035 bmrm_return_value_T() 00036 { 00037 nIter = 0; 00038 nCP = 0; 00039 nzA = 0; 00040 Fp = 0; 00041 Fd = 0; 00042 qp_exitflag = 0; 00043 exitflag = 0; 00044 }; 00045 00047 ~bmrm_return_value_T() { }; 00048 00050 bool load_serializable(CSerializableFile* file, const char* prefix="") { return false; } 00051 00053 bool save_serializable(CSerializableFile* file, const char* prefix="") { return false; } 00054 00056 uint32_t nIter; 00057 00059 uint32_t nCP; 00060 00062 uint32_t nzA; 00063 00065 float64_t Fp; 00066 00068 float64_t Fd; 00069 00071 int8_t qp_exitflag; 00072 00078 int8_t exitflag; 00079 00081 SGVector< float64_t > hist_Fp; 00082 00084 SGVector< float64_t > hist_Fd; 00085 00087 SGVector< float64_t > hist_wdist; 00088 }; 00089 00091 IGNORE_IN_CLASSLIST struct bmrm_ll { 00093 bmrm_ll *prev; 00095 bmrm_ll *next; 00097 float64_t *address; 00099 uint32_t idx; 00100 }; 00101 00111 void add_cutting_plane( 00112 bmrm_ll** tail, 00113 bool* map, 00114 float64_t* A, 00115 uint32_t free_idx, 00116 float64_t* cp_data, 00117 uint32_t dim); 00118 00126 void remove_cutting_plane( 00127 bmrm_ll** head, 00128 bmrm_ll** tail, 00129 bool* map, 00130 float64_t* icp); 00131 00137 inline float64_t * get_cutting_plane(bmrm_ll *ptr) { return ptr->address; } 00138 00145 inline uint32_t find_free_idx(bool *map, uint32_t size) 00146 { for(uint32_t i=0; i<size; ++i) if (map[i]) return i; return size+1; } 00147 00166 bmrm_return_value_T svm_bmrm_solver( 00167 CStructuredModel *model, 00168 float64_t *W, 00169 float64_t TolRel, 00170 float64_t TolAbs, 00171 float64_t _lambda, 00172 uint32_t _BufSize, 00173 bool cleanICP, 00174 uint32_t cleanAfter, 00175 float64_t K, 00176 uint32_t Tmax, 00177 bool verbose 00178 ); 00179 00180 } 00181 00182 #endif /* libbmrm_h */