/usr/include/shogun/classifier/mkl/MKLMulticlass.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 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 | /*
* 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) 2009 Alexander Binder
* Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
*
* Update to patch 0.10.0 - thanks to Eric aka Yoo (thereisnoknife@gmail.com)
*
*/
#ifndef MKLMulticlass_H_
#define MKLMulticlass_H_
#include <vector>
#include <shogun/base/SGObject.h>
#include <shogun/kernel/Kernel.h>
#include <shogun/kernel/CombinedKernel.h>
#include <shogun/multiclass/GMNPSVM.h>
#include <shogun/classifier/mkl/MKLMulticlassGLPK.h>
#include <shogun/classifier/mkl/MKLMulticlassGradient.h>
#include <shogun/multiclass/MulticlassSVM.h>
namespace shogun
{
/** @brief MKLMulticlass is a class for L1-norm Multiclass MKL.
*
* It is based on the GMNPSVM Multiclass SVM.
* Its own parameters are the L2 norm weight change based MKL
*
* Its termination criterion is set by void set_mkl_epsilon(float64_t eps ); and
* the maximal number of MKL iterations is set by void
* set_max_num_mkliters(int32_t maxnum); It passes the regularization
* constants C1 and C2 to GMNPSVM.
*/
class CMKLMulticlass : public CMulticlassSVM
{
public:
/** Class default Constructor */
CMKLMulticlass();
/** Class Constructor commonly used in Shogun Toolbox
* @param C constant C
* @param k kernel
* @param lab labels
*/
CMKLMulticlass(float64_t C, CKernel* k, CLabels* lab);
/** Class default Destructor */
virtual ~CMKLMulticlass();
/** get classifier type
*
* @return classifier type GMNPMKL
*/
virtual inline EMachineType get_classifier_type()
{ return CT_MKLMULTICLASS; }
/** returns MKL weights for the different kernels
*
* @param numweights is output parameter, is set to zero if no weights
* have been computed or to the number of MKL weights which is equal to the number of kernels
*
* @return NULL if no weights have been computed or otherwise an array
* with the weights, caller has to delete[] the output by itself
*/
float64_t* getsubkernelweights(int32_t & numweights);
/** sets MKL termination threshold
*
* @param eps is the desired threshold value
* the termination criterion is the L2 norm between the current MKL weights
* and their counterpart from the previous iteration
*
*/
void set_mkl_epsilon(float64_t eps );
/** sets maximal number of MKL iterations
*
* @param maxnum is the desired maximal number of MKL iterations; when it
* is reached the MKL terminates irrespective of the MKL progress
* set it to a nonpositive value in order to turn it off
*
*/
void set_max_num_mkliters(int32_t maxnum);
/** set mkl norm
* @param norm
*/
virtual void set_mkl_norm(float64_t norm);
protected:
/** Class Copy Constructor
* protected to avoid its usage
*
*/
CMKLMulticlass( const CMKLMulticlass & cm);
/** Class Assignment operator
* protected to avoid its usage
*
*/
CMKLMulticlass operator=( const CMKLMulticlass & cm);
/** performs some sanity checks (on the provided kernel), inits the
* GLPK-based LP solver
*
*/
void initlpsolver();
/** inits the underlying Multiclass SVM
*
*/
void initsvm();
/** checks MKL for convergence
*
* @param numberofsilpiterations is the number of currently done iterations
*
*/
virtual bool evaluatefinishcriterion(const int32_t
numberofsilpiterations);
/** adds a constraint to the LP used in MKL
*
* @param curweights are the current MKL weights
*
* it uses
* void addingweightsstep( const std::vector<float64_t> & curweights);
* and
* float64_t getsumofsignfreealphas();
*/
void addingweightsstep( const std::vector<float64_t> & curweights);
/** computes the first svm-dependent part used for generating MKL constraints
* it is
* \f$ \sum_y b_y^2-\sum_i \sum_{ y | y \neq y_i} \alpha_{iy}(b_{y_i}-b_y-1) \f$
*/
float64_t getsumofsignfreealphas();
/** computes the second svm-dependent part used for generating MKL
* constraints
*
* @param ind is the index of the kernel for which
* to compute \f$ \|w \|^2 \f$
*/
float64_t getsquarenormofprimalcoefficients(
const int32_t ind);
/** train Multiclass MKL 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);
/** @return object name */
virtual const char* get_name() const { return "MKLMulticlass"; }
protected:
/** the Multiclass svm for fixed MKL weights
*
*
*/
CGMNPSVM* svm;
/** the solver wrapper */
MKLMulticlassOptimizationBase* lpw;
/** stores the last two mkl iteration weights */
::std::vector< std::vector< float64_t> > weightshistory;
/** MKL termination threshold
* is set by void set_mkl_epsilon(float64_t eps );
*/
float64_t mkl_eps;
/** maximal number of MKL iterations
* is set by void set_max_num_mkliters(int32_t maxnum);
*/
int32_t max_num_mkl_iters;
/** MKL norm >=1
*
*/
float64_t pnorm;
/** stores the term
* \f$\| w_l \|^2 = \alpha Y K_l Y \alpha\f$
*
*/
std::vector<float64_t> normweightssquared;
/** norm term above from previous iteration */
std::vector<float64_t> oldnormweightssquared;
/** first svm-dependent part used for generating MKL constraints */
float64_t curalphaterm;
/** alpha term above from previous iteration */
float64_t oldalphaterm;
};
}
#endif // GMNPMKL_H_
|