23 #undef DEBUG_SUBGRADIENTSVM
25 using namespace shogun;
29 qpsize_max(2000), use_bias(false), delta_active(0), delta_bound(0)
36 qpsize_max(2000), use_bias(false), delta_active(0), delta_bound(0)
81 int32_t num_feat, int32_t num_vec, int32_t& num_active, int32_t& num_bound)
88 for (int32_t i=0; i<num_vec; i++)
128 for (int32_t i=0; i<num_vec; i++)
138 #ifdef DEBUG_SUBGRADIENTSVM
172 for (int32_t i=0; i<num_vec; i++)
204 for (int32_t i=0; i<num_vec; i++)
231 for (int32_t i=0; i<num_vec; i++)
251 float64_t grad_val = 2*A_zero*alpha + B_zero + sum_B;
265 for (int32_t i=1; i < num_hinge && grad_val < 0; i++)
268 grad_val = 2*A_zero*alpha + B_zero + sum_B;
272 ASSERT(old_grad_val-grad_val != 0);
273 float64_t gamma = -grad_val/(old_grad_val-grad_val);
274 alpha = old_alpha*gamma + (1-gamma)*alpha;
278 old_grad_val = grad_val;
282 grad_val = 2*A_zero*alpha + B_zero + sum_B;
290 int32_t num_feat, int32_t num_vec, int32_t num_active, int32_t num_bound)
303 for (int32_t i=0; i<num_bound; i++)
315 for (int32_t i=0; i<num_bound; i++)
317 for (int32_t j=i; j<num_bound; j++)
322 Z[j*num_bound+i]=
Z[i*num_bound+j];
333 #ifdef DEBUG_SUBGRADIENTSVM
350 #ifdef DEBUG_SUBGRADIENTSVM
368 for (int32_t i=0; i<num_bound; i++)
376 for (int32_t i=0; i<num_bound; i++)
397 for (int32_t i=0; i<num_vec; i++)
400 result +=
C1 * (1.0-
proj[i]);
408 for (int32_t i=0; i<num_vec; i++)
417 void CSubGradientSVM::init(int32_t num_vec, int32_t num_feat)
458 memset(
hinge_idx,0,
sizeof(int32_t)*num_vec);
461 memset(
active,0,
sizeof(uint8_t)*num_vec);
467 memset(
idx_bound,0,
sizeof(int32_t)*num_vec);
473 memset(
Z,0,
sizeof(
float64_t)*qpsize_limit*qpsize_limit);
538 SG_ERROR(
"Specified features are not of type CDotFeatures\n");
543 int32_t num_iterations=0;
548 ASSERT(num_vec==num_train_labels);
550 init(num_vec, num_feat);
552 int32_t num_active=0;
566 #ifdef DEBUG_SUBGRADIENTSVM
576 #ifdef DEBUG_SUBGRADIENTSVM
577 SG_PRINT(
"==================================================\niteration: %d ", num_iterations);
579 SG_PRINT(
"objective:%.10f alpha: %.10f dir_deriv: %f num_bound: %d num_active: %d work_eps: %10.10f eps: %10.10f auto_eps: %10.10f time:%f\n",
605 #ifdef DEBUG_SUBGRADIENTSVM
606 SG_PRINT(
"CHECKING OPTIMALITY CONDITIONS: "
607 "work_epsilon: %10.10f delta_active:%d alpha: %10.10f norm_grad: %10.10f a*norm_grad:%10.16f\n",
642 #ifdef DEBUG_SUBGRADIENTSVM
652 SG_INFO(
"converged after %d iterations\n", num_iterations);
655 SG_INFO(
"objective: %f alpha: %f dir_deriv: %f num_bound: %d num_active: %d\n",
656 obj, alpha, dir_deriv, num_bound, num_active);
658 #ifdef DEBUG_SUBGRADIENTSVM