SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
libbmrm.h
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  * 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 #ifndef libbmrm_h
00015 #define libbmrm_h
00016 
00017 #include <shogun/lib/common.h>
00018 #include <shogun/structure/BmrmStatistics.h>
00019 #include <shogun/structure/DualLibQPBMSOSVM.h>
00020 #include <shogun/io/SGIO.h>
00021 
00022 #define LIBBMRM_PLUS_INF (-log(0.0))
00023 #define LIBBMRM_CALLOC(x, y) SG_CALLOC(y, x)
00024 #define LIBBMRM_REALLOC(x, y) SG_REALLOC(x, y)
00025 #define LIBBMRM_FREE(x) SG_FREE(x)
00026 #define LIBBMRM_MEMCPY(x, y, z) memcpy(x, y, z)
00027 #define LIBBMRM_MEMMOVE(x, y, z) memmove(x, y, z)
00028 #define LIBBMRM_INDEX(ROW, COL, NUM_ROWS) ((COL)*(NUM_ROWS)+(ROW))
00029 #define LIBBMRM_ABS(A) ((A) < 0 ? -(A) : (A))
00030 
00031 namespace shogun
00032 {
00034 IGNORE_IN_CLASSLIST struct bmrm_ll {
00036     bmrm_ll   *prev;
00038     bmrm_ll   *next;
00040     float64_t   *address;
00042     uint32_t    idx;
00043 };
00044 
00046 IGNORE_IN_CLASSLIST struct ICP_stats
00047 {
00049     uint32_t maxCPs;
00050 
00052     uint32_t* ICPcounter;
00053 
00055     float64_t** ICPs;
00056 
00058     uint32_t* ACPs;
00059 
00061     float64_t* H_buff;
00062 };
00063 
00073 void add_cutting_plane(
00074         bmrm_ll**   tail,
00075         bool*       map,
00076         float64_t*  A,
00077         uint32_t    free_idx,
00078         float64_t*  cp_data,
00079         uint32_t    dim);
00080 
00088 void remove_cutting_plane(
00089         bmrm_ll**   head,
00090         bmrm_ll**   tail,
00091         bool*       map,
00092         float64_t*  icp);
00093 
00097 void clean_icp(ICP_stats* icp_stats,
00098         BmrmStatistics& bmrm,
00099         bmrm_ll** head,
00100         bmrm_ll** tail,
00101         float64_t*& H,
00102         float64_t*& diag_H,
00103         float64_t*& beta,
00104         bool*& map,
00105         uint32_t cleanAfter,
00106         float64_t*& b,
00107         uint32_t*& I,
00108         uint32_t cp_models = 0
00109         );
00110 
00116 inline float64_t * get_cutting_plane(bmrm_ll *ptr) { return ptr->address; }
00117 
00124 inline uint32_t find_free_idx(bool *map, uint32_t size)
00125 {
00126     for (uint32_t i=0; i<size; ++i) if (map[i]) return i;
00127     SG_SERROR("No free index available in CP buffer of size %d.\n", size);
00128     return size-1;
00129 }
00130 
00149 BmrmStatistics svm_bmrm_solver(
00150         CDualLibQPBMSOSVM  *machine,
00151         float64_t          *W,
00152         float64_t          TolRel,
00153         float64_t          TolAbs,
00154         float64_t          _lambda,
00155         uint32_t           _BufSize,
00156         bool               cleanICP,
00157         uint32_t           cleanAfter,
00158         float64_t          K,
00159         uint32_t           Tmax,
00160         bool               verbose
00161         );
00162 
00163 }
00164 
00165 #endif /* libbmrm_h */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation