/usr/include/shogun/lib/external/libocas.h is in libshogun-dev 3.2.0-7.3build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | /*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* libocas.h: Implementation of the OCAS solver for training
* linear SVM classifiers.
*
* Copyright (C) 2008, 2009 Vojtech Franc, xfrancv@cmp.felk.cvut.cz
* Soeren Sonnenburg, soeren.sonnenburg@first.fraunhofer.de
* Implementation of SVM-Ocas solver.
*-------------------------------------------------------------------- */
#include <shogun/lib/common.h>
#ifndef libocas_h
#define libocas_h
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace shogun
{
#define LIBOCAS_PLUS_INF (-log(0.0))
#define LIBOCAS_CALLOC(x,y) SG_CALLOC(y,x)
#define LIBOCAS_FREE(x) SG_FREE(x)
#define LIBOCAS_INDEX(ROW,COL,NUM_ROWS) ((COL)*(NUM_ROWS)+(ROW))
#define LIBOCAS_MIN(A,B) ((A) > (B) ? (B) : (A))
#define LIBOCAS_MAX(A,B) ((A) < (B) ? (B) : (A))
#define LIBOCAS_ABS(A) ((A) < 0 ? -(A) : (A))
typedef struct {
uint32_t nIter; /* number of iterations */
uint32_t nCutPlanes; /* number of cutitng buffered planes */
uint32_t nNZAlpha; /* number of non-zero Lagrangeans (effective number of CPs) */
uint32_t trn_err; /* number of training errors */
float64_t Q_P; /* primal objective value */
float64_t Q_D; /* dual objective value */
float64_t output_time; /* time spent in computing outputs */
float64_t sort_time; /* time spent in sorting */
float64_t add_time; /* time spent in adding examples to compute cutting planes */
float64_t w_time; /* time spent in computing parameter vector */
float64_t qp_solver_time; /* time spent in inner QP solver */
float64_t ocas_time; /* total time spent in svm_ocas_solver */
float64_t print_time; /* time spent in ocas_print function */
int8_t qp_exitflag; /* exitflag from the last call of the inner QP solver */
int8_t exitflag; /* 1 .. ocas.Q_P - ocas.Q_D <= TolRel*ABS(ocas.Q_P)
2 .. ocas.Q_P - ocas.Q_D <= TolAbs
3 .. ocas.Q_P <= QPBound
4 .. optimization time >= MaxTime
-1 .. ocas.nCutPlanes >= BufSize
-2 .. not enough memory for the solver */
} ocas_return_value_T;
/* binary linear SVM solver */
ocas_return_value_T svm_ocas_solver(
float64_t C, /* regularizarion constant */
uint32_t nData, /* number of exmaples */
float64_t TolRel, /* halts if 1-Q_P/Q_D <= TolRel */
float64_t TolAbs, /* halts if Q_P-Q_D <= TolRel */
float64_t QPBound, /* halts if QP <= QPBound */
float64_t MaxTime, /* maximal time in seconds spent in optmization */
uint32_t BufSize, /* maximal number of buffered cutting planes */
uint8_t Method, /* 0..standard CP (SVM-Perf,BMRM), 1..OCAS */
void (*compute_W)(float64_t*, float64_t*, float64_t*, uint32_t, void*),
float64_t (*update_W)(float64_t, void*),
int (*add_new_cut)(float64_t*, uint32_t*, uint32_t, uint32_t, void*),
int (*compute_output)( float64_t*, void* ),
int (*sort)(float64_t*, float64_t*, uint32_t),
void (*ocas_print)(ocas_return_value_T),
void* user_data);
/* binary linear SVM solver which allows using different C for each example*/
ocas_return_value_T svm_ocas_solver_difC(
float64_t *C, /* regularizarion constants for each example */
uint32_t nData, /* number of exmaples */
float64_t TolRel, /* halts if 1-Q_P/Q_D <= TolRel */
float64_t TolAbs, /* halts if Q_P-Q_D <= TolRel */
float64_t QPBound, /* halts if QP <= QPBound */
float64_t MaxTime, /* maximal time in seconds spent in optmization */
uint32_t BufSize, /* maximal number of buffered cutting planes */
uint8_t Method, /* 0..standard CP (SVM-Perf,BMRM), 1..OCAS */
void (*compute_W)(float64_t*, float64_t*, float64_t*, uint32_t, void*),
float64_t (*update_W)(float64_t, void*),
int (*add_new_cut)(float64_t*, uint32_t*, uint32_t, uint32_t, void*),
int (*compute_output)( float64_t*, void* ),
int (*sort)(float64_t*, float64_t*, uint32_t),
void (*ocas_print)(ocas_return_value_T),
void* user_data);
/* multi-class (Singer-Crammer formulation) linear SVM solver */
ocas_return_value_T msvm_ocas_solver(
float64_t C,
float64_t *data_y,
uint32_t nY,
uint32_t nData,
float64_t TolRel,
float64_t TolAbs,
float64_t QPBound,
float64_t MaxTime,
uint32_t _BufSize,
uint8_t Method,
void (*compute_W)(float64_t*, float64_t*, float64_t*, uint32_t, void*),
float64_t (*update_W)(float64_t, void*),
int (*add_new_cut)(float64_t*, uint32_t*, uint32_t, void*),
int (*compute_output)(float64_t*, void* ),
int (*sort)(float64_t*, float64_t*, uint32_t),
void (*ocas_print)(ocas_return_value_T),
void* user_data);
/* binary linear SVM solver */
ocas_return_value_T svm_ocas_solver_nnw(
float64_t C, /* regularizarion constant */
uint32_t nData, /* number of exmaples */
uint32_t num_nnw, /* number of components of W which must non-negative*/
uint32_t* nnw_idx, /* indices of W which must be non-negative */
float64_t TolRel, /* halts if 1-Q_P/Q_D <= TolRel */
float64_t TolAbs, /* halts if Q_P-Q_D <= TolRel */
float64_t QPBound, /* halts if QP <= QPBound */
float64_t MaxTime, /* maximal time in seconds spent in optmization */
uint32_t BufSize, /* maximal number of buffered cutting planes */
uint8_t Method, /* 0..standard CP (SVM-Perf,BMRM), 1..OCAS */
int (*add_pw_constr)(uint32_t, uint32_t, void*),
void (*clip_neg_w)(uint32_t, uint32_t*, void*),
void (*compute_W)(float64_t*, float64_t*, float64_t*, uint32_t, void*),
float64_t (*update_W)(float64_t, void*),
int (*add_new_cut)(float64_t*, uint32_t*, uint32_t, uint32_t, void*),
int (*compute_output)( float64_t*, void* ),
int (*sort)(float64_t*, float64_t*, uint32_t),
void (*ocas_print)(ocas_return_value_T),
void* user_data);
}
#endif // DOXYGEN_SHOULD_SKIP_THIS
#endif /* libocas_h */
|