16 using namespace shogun;
40 SG_ERROR(
"Number of training vectors does not match number of labels\n");
48 const int64_t maxiter = 1L<<30;
84 for (int32_t i=0; i<n; i++)
96 while (niter++ < maxiter)
102 bool free_alpha=
false;
108 for (int32_t i=0; i<n; i++)
112 if (alphas[i] > 0 && alphas[i] < d)
115 if ( (dalphas[i]==0) ||
116 (alphas[i]==0 && dalphas[i] >0) ||
117 (alphas[i]==d && dalphas[i] <0)
126 else if (v == maxpviol)
133 if (maxpidx<0 || maxdviol<0)
134 SG_ERROR(
"no violation no convergence, should not happen!\n");
142 if (niter%10000 == 0)
146 for (int32_t i=0; i<n; i++)
149 for (int32_t j=0; j<n; j++)
153 SG_DEBUG(
"obj:%f pviol:%f dviol:%f maxpidx:%d iter:%d\n", obj, maxpviol, maxdviol, maxpidx, niter);
159 primalcool = (maxpviol < primaleps*stopfac);
160 dualcool = (maxdviol < dualeps*stopfac) || (!free_alpha);
163 if (primalcool && dualcool)
166 SG_INFO(
" no free alpha, stopping! #iter=%d\n", niter);
168 SG_INFO(
" done! #iter=%d\n", niter);
173 ASSERT(maxpidx>=0 && maxpidx<n);
175 hstep=-hessres[maxpidx]/
compute_H(maxpidx,maxpidx);
179 hessest-=F[maxpidx]*hstep;
186 if (tmpalpha > d-alpha_eps)
189 if (tmpalpha < 0+alpha_eps)
193 float64_t alphachange = tmpalpha - alphas[maxpidx];
194 alphas[maxpidx] = tmpalpha;
197 for (int32_t i=0; i<n; i++)
199 hessres[i]+=h[i]*hstep;
202 dalphas[i] +=h[i]*alphachange;
206 detas+=F[maxpidx]*alphachange;
221 for (int32_t i=0; i<n; i++)
222 dalphas[i]+= F[i] * etachange;
227 if (niter >= maxiter)
232 for (int32_t i=0; i<n; i++)
244 for (int32_t i=0; i<n; i++)
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 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()
bool is_cached(int64_t number)
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)
float64_t get_label(int32_t idx)
bool set_support_vector(int32_t idx, int32_t val)
The class Features is the base class of all feature objects.
A generic Support Vector Machine Interface.
virtual bool has_features()
#define SG_MALLOC(type, len)
float64_t get_objective()
float64_t KERNELCACHE_ELEM
bool create_new_model(int32_t num)
static T abs(T a)
return the absolute value of a number