41 SG_ERROR(
"Number of training vectors does not match number of labels\n")
49 const int64_t maxiter = 1L<<30;
85 for (int32_t i=0; i<n; i++)
97 while (niter++ < maxiter)
103 bool free_alpha=
false;
109 for (int32_t i=0; i<n; i++)
113 if (alphas[i] > 0 && alphas[i] < d)
116 if ( (dalphas[i]==0) ||
117 (alphas[i]==0 && dalphas[i] >0) ||
118 (alphas[i]==d && dalphas[i] <0)
127 else if (v == maxpviol)
134 if (maxpidx<0 || maxdviol<0)
135 SG_ERROR(
"no violation no convergence, should not happen!\n")
143 if (niter%10000 == 0)
147 for (int32_t i=0; i<n; i++)
150 for (int32_t j=0; j<n; j++)
154 SG_DEBUG(
"obj:%f pviol:%f dviol:%f maxpidx:%d iter:%d\n", obj, maxpviol, maxdviol, maxpidx, niter)
160 primalcool = (maxpviol < primaleps*stopfac);
161 dualcool = (maxdviol < dualeps*stopfac) || (!free_alpha);
164 if (primalcool && dualcool)
167 SG_INFO(
" no free alpha, stopping! #iter=%d\n", niter)
169 SG_INFO(
" done! #iter=%d\n", niter)
174 ASSERT(maxpidx>=0 && maxpidx<n)
176 hstep=-hessres[maxpidx]/
compute_H(maxpidx,maxpidx);
180 hessest-=F[maxpidx]*hstep;
187 if (tmpalpha > d-alpha_eps)
190 if (tmpalpha < 0+alpha_eps)
194 float64_t alphachange = tmpalpha - alphas[maxpidx];
195 alphas[maxpidx] = tmpalpha;
198 for (int32_t i=0; i<n; i++)
200 hessres[i]+=h[i]*hstep;
203 dalphas[i] +=h[i]*alphachange;
207 detas+=F[maxpidx]*alphachange;
222 for (int32_t i=0; i<n; i++)
223 dalphas[i]+= F[i] * etachange;
228 if (niter >= maxiter)
233 for (int32_t i=0; i<n; i++)
245 for (int32_t i=0; i<n; i++)
virtual bool init(CFeatures *lhs, CFeatures *rhs)
int32_t get_num_support_vectors()
virtual ELabelType get_label_type() const =0
The class Labels models labels, i.e. class assignments of objects.
virtual int32_t get_num_labels() const =0
virtual int32_t get_num_vectors() const =0
float64_t kernel(int32_t idx_a, int32_t idx_b)
void unlock_kernel_row(int32_t i)
float64_t compute_H(int32_t i, int32_t j)
KERNELCACHE_ELEM * lock_kernel_row(int32_t i)
float64_t compute_svm_dual_objective()
virtual bool train_machine(CFeatures *data=NULL)
void set_bias(float64_t bias)
CCache< KERNELCACHE_ELEM > * kernel_cache
bool set_alpha(int32_t idx, float64_t val)
bool set_support_vector(int32_t idx, int32_t val)
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
A generic Support Vector Machine Interface.
Binary Labels for binary classification.
bool is_cached(int64_t number)
virtual bool has_features()
float64_t get_objective()
float64_t KERNELCACHE_ELEM
bool create_new_model(int32_t num)