/usr/include/shogun/classifier/svm/SubGradientSVM.h is in libshogun-dev 1.1.0-4ubuntu2.
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | /*
* 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.
*
* Written (W) 2007-2009 Soeren Sonnenburg
* Written (W) 2007-2008 Vojtech Franc
* Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society
*/
#ifndef _SUBGRADIENTSVM_H___
#define _SUBGRADIENTSVM_H___
#include <shogun/lib/common.h>
#include <shogun/machine/LinearMachine.h>
#include <shogun/features/DotFeatures.h>
#include <shogun/features/Labels.h>
namespace shogun
{
/** @brief class SubGradientSVM */
class CSubGradientSVM : public CLinearMachine
{
public:
/** default constructor */
CSubGradientSVM();
/** constructor
*
* @param C constant C
* @param traindat training features
* @param trainlab labels for training features
*/
CSubGradientSVM(
float64_t C, CDotFeatures* traindat,
CLabels* trainlab);
virtual ~CSubGradientSVM();
/** get classifier type
*
* @return classifier type SUBGRADIENTSVM
*/
virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTSVM; }
/** set C
*
* @param c_neg C1
* @param c_pos C2
*/
inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
/** get C1
*
* @return C1
*/
inline float64_t get_C1() { return C1; }
/** get C2
*
* @return C2
*/
inline float64_t get_C2() { return C2; }
/** set if bias shall be enabled
*
* @param enable_bias if bias shall be enabled
*/
inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
/** check if bias is enabled
*
* @return if bias is enabled
*/
inline bool get_bias_enabled() { return use_bias; }
/** set epsilon
*
* @param eps new epsilon
*/
inline void set_epsilon(float64_t eps) { epsilon=eps; }
/** get epsilon
*
* @return epsilon
*/
inline float64_t get_epsilon() { return epsilon; }
/** set qpsize
*
* @param q new qpsize
*/
inline void set_qpsize(int32_t q) { qpsize=q; }
/** get qpsize
*
* @return qpsize
*/
inline int32_t get_qpsize() { return qpsize; }
/** set qpsize_max
*
* @param q new qpsize_max
*/
inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
/** get qpsize_max
*
* @return qpsize_max
*/
inline int32_t get_qpsize_max() { return qpsize_max; }
protected:
/// returns number of changed constraints for precision work_epsilon
/// and fills active array
int32_t find_active(
int32_t num_feat, int32_t num_vec, int32_t& num_active,
int32_t& num_bound);
/// swaps the active / old_active and computes idx_active, idx_bound
/// and sum_CXy_active arrays and the sum_Cy_active variable
void update_active(int32_t num_feat, int32_t num_vec);
/// compute svm objective
float64_t compute_objective(int32_t num_feat, int32_t num_vec);
/// compute minimum norm subgradient
/// return norm of minimum norm subgradient
float64_t compute_min_subgradient(
int32_t num_feat, int32_t num_vec, int32_t num_active,
int32_t num_bound);
///performs a line search to determine step size
float64_t line_search(int32_t num_feat, int32_t num_vec);
/// compute projection
void compute_projection(int32_t num_feat, int32_t num_vec);
/// only computes updates on the projection
void update_projection(float64_t alpha, int32_t num_vec);
/// alloc helper arrays
void init(int32_t num_vec, int32_t num_feat);
/// de-alloc helper arrays
void cleanup();
/** @return object name */
inline virtual const char* get_name() const { return "SubGradientSVM"; }
protected:
/** train SVM classifier
*
* @param data training data (parameter can be avoided if distance or
* kernel-based classifiers are used and distance/kernels are
* initialized with train data)
*
* @return whether training was successful
*/
virtual bool train_machine(CFeatures* data=NULL);
protected:
/** C1 */
float64_t C1;
/** C2 */
float64_t C2;
/** epsilon */
float64_t epsilon;
/** work epsilon */
float64_t work_epsilon;
/** autoselected epsilon */
float64_t autoselected_epsilon;
/** qpsize */
int32_t qpsize;
/** maximum qpsize */
int32_t qpsize_max;
/** limit of qpsize */
int32_t qpsize_limit;
/** shall bias be used */
bool use_bias;
/** last iteration no improvement */
int32_t last_it_noimprovement;
/** number of iterations no improvement */
int32_t num_it_noimprovement;
//idx vectors of length num_vec
/** 0=not active, 1=active, 2=on boundary */
uint8_t* active;
/** old active */
uint8_t* old_active;
/** idx active */
int32_t* idx_active;
/** idx bound */
int32_t* idx_bound;
/** delta active */
int32_t delta_active;
/** delta bound */
int32_t delta_bound;
/** proj */
float64_t* proj;
/** tmp proj*/
float64_t* tmp_proj;
/** tmp proj index */
int32_t* tmp_proj_idx;
//vector of length num_feat
/** sum CXy active */
float64_t* sum_CXy_active;
/** v */
float64_t* v;
/** old v */
float64_t* old_v;
/** sum Cy active */
float64_t sum_Cy_active;
//vector of length num_feat
/** grad w */
float64_t* grad_w;
/** grad b */
float64_t grad_b;
/** grad proj */
float64_t* grad_proj;
/** hinge point */
float64_t* hinge_point;
/** hinge index */
int32_t* hinge_idx;
//vectors/sym matrix of size qpsize_limit
/** beta */
float64_t* beta;
/** old beta */
float64_t* old_beta;
/** Zv */
float64_t* Zv;
/** old Zv */
float64_t* old_Zv;
/** Z */
float64_t* Z;
/** old Z */
float64_t* old_Z;
/** timing measurement */
float64_t tim;
};
}
#endif
|