14 using namespace shogun;
54 " CMKLMultiClass::CMKLMultiClass(const CMKLMultiClass & cm): must "
55 "not be called, glpk structure is currently not copyable");
61 " CMKLMultiClass CMKLMultiClass::operator=(...): must "
62 "not be called, glpk structure is currently not copyable");
71 SG_ERROR(
"CMKLMultiClass::initsvm(): the set labels is NULL\n");
83 SG_ERROR(
"CMKLMultiClass::initsvm(): the number of labels is "
84 "nonpositive, do not know how to handle this!\n");
94 SG_ERROR(
"CMKLMultiClass::initlpsolver(): the set kernel is NULL\n");
99 SG_ERROR(
"CMKLMultiClass::initlpsolver(): given kernel is not of type"
100 " K_COMBINED %d required by Multiclass Mkl \n",
130 numberofsilpiterations)
139 std::vector<float64_t> wold,wnew;
145 ASSERT (wold.size()==wnew.size());
148 if((
pnorm<=1)&&(!normweightssquared.empty()))
152 for (
size_t i=0;i< wnew.size();++i)
154 delta+=(wold[i]-wnew[i])*(wold[i]-wnew[i]);
157 SG_SDEBUG(
"L1 Norm chosen, weight delta %f \n",delta);
162 float64_t maxval=normweightssquared[maxind];
164 for (
size_t i=0;i< wnew.size();++i)
166 delta+=normweightssquared[i]*wnew[i];
173 delta-=normweightssquared[maxind];
175 SG_SDEBUG(
"L1 Norm chosen, MKL part of duality gap %f \n",delta);
176 if( (delta <
mkl_eps) && (numberofsilpiterations>=1) )
187 for (
size_t i=0;i< wnew.size();++i)
189 delta+=(wold[i]-wnew[i])*(wold[i]-wnew[i]);
192 SG_SDEBUG(
"Lp Norm chosen, weight delta %f \n",delta);
194 if( (delta <
mkl_eps) && (numberofsilpiterations>=1) )
216 std::copy(curweights.begin(),curweights.end(),weights);
232 normweightssquared.resize(numkernels);
233 for (int32_t ind=0; ind < numkernels; ++ind )
246 std::copy(lab.vector,lab.vector+lab.vlen, trainlabels2.begin());
249 ASSERT (trainlabels2.size()>0);
262 index_t basealphas_y = 0, basealphas_x = 0;
266 for (
size_t lb=0; lb< trainlabels2.size();++lb)
272 if ((
int)nc!=trainlabels2[lb])
280 sum+= -basealphas[lb*basealphas_y + nc]*(bia1-bia2-1);
311 tmp+=alphai*ker->
kernel(svindi,svindk)
334 SG_ERROR(
"Number of training vectors does not match number of "
346 ::std::vector<float64_t> curweights(numkernels,1.0/numkernels);
351 int32_t numberofsilpiterations=0;
362 ++numberofsilpiterations;
373 for (int32_t i=0; i<numcl; i++)
433 SG_ERROR(
"CMKLMultiClass::set_mkl_norm(float64_t norm) : parameter pnorm<1");
virtual bool init(CFeatures *lhs, CFeatures *rhs)
int32_t get_num_support_vectors()
The class Labels models labels, i.e. class assignments of objects.
virtual void addconstraint(const ::std::vector< float64_t > &normw2, const float64_t sumofpositivealphas)
MKLMultiClass is a class for L1-norm multiclass MKL.
MKLMultiClassGLPK is a helper class for MKLMultiClass.
virtual int32_t get_num_vectors() const =0
float64_t * get_basealphas_ptr(index_t *y, index_t *x)
CMKLMultiClass operator=(const CMKLMultiClass &cm)
void addingweightsstep(const std::vector< float64_t > &curweights)
float64_t kernel(int32_t idx_a, int32_t idx_b)
virtual void set_mkl_norm(float64_t norm)
bool create_multiclass_svm(int32_t num_classes)
virtual bool evaluatefinishcriterion(const int32_t numberofsilpiterations)
virtual void setup(const int32_t numkernels2)
CSVM * get_svm(int32_t num)
virtual void free_vector()
bool set_svm(int32_t num, CSVM *svm)
SGVector< int32_t > get_int_labels()
void set_bias(float64_t bias)
float64_t getsumofsignfreealphas()
virtual void set_mkl_norm(float64_t norm)
float64_t getsquarenormofprimalcoefficients(const int32_t ind)
virtual void computeweights(std::vector< float64_t > &weights2)
bool set_alpha(int32_t idx, float64_t val)
::std::vector< std::vector< float64_t > > weightshistory
float64_t get_alpha(int32_t idx)
The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by lin...
bool set_support_vector(int32_t idx, int32_t val)
int32_t get_support_vector(int32_t idx)
float64_t * getsubkernelweights(int32_t &numweights)
virtual void set_subkernel_weights(SGVector< float64_t > weights)
MKLMultiClassOptimizationBase * lpw
int32_t get_num_classes()
virtual EKernelType get_kernel_type()=0
Class GMNPSVM implements a one vs. rest MultiClass SVM.
The class Features is the base class of all feature objects.
virtual bool train(CFeatures *data=NULL)
A generic Support Vector Machine Interface.
virtual ~CMKLMultiClass()
void set_epsilon(float64_t eps)
void set_kernel(CKernel *k)
void set_mkl_epsilon(float64_t eps)
virtual bool train_machine(CFeatures *data=NULL)
MKLMultiClassGradient is a helper class for MKLMultiClass.
virtual void set_labels(CLabels *lab)
void set_max_num_mkliters(int32_t maxnum)
int32_t max_num_mkl_iters
#define SG_MALLOC(type, len)
void set_C(float64_t c_neg, float64_t c_pos)