22 #undef DEBUG_SUBGRADIENTSVM
24 using namespace shogun;
28 qpsize_max(2000), use_bias(false), delta_active(0), delta_bound(0)
35 qpsize_max(2000), use_bias(false), delta_active(0), delta_bound(0)
80 int32_t num_feat, int32_t num_vec, int32_t& num_active, int32_t& num_bound)
87 for (int32_t i=0; i<num_vec; i++)
127 for (int32_t i=0; i<num_vec; i++)
137 #ifdef DEBUG_SUBGRADIENTSVM
171 for (int32_t i=0; i<num_vec; i++)
203 for (int32_t i=0; i<num_vec; i++)
230 for (int32_t i=0; i<num_vec; i++)
250 float64_t grad_val = 2*A_zero*alpha + B_zero + sum_B;
264 for (int32_t i=1; i < num_hinge && grad_val < 0; i++)
267 grad_val = 2*A_zero*alpha + B_zero + sum_B;
271 ASSERT(old_grad_val-grad_val != 0);
272 float64_t gamma = -grad_val/(old_grad_val-grad_val);
273 alpha = old_alpha*gamma + (1-gamma)*alpha;
277 old_grad_val = grad_val;
281 grad_val = 2*A_zero*alpha + B_zero + sum_B;
289 int32_t num_feat, int32_t num_vec, int32_t num_active, int32_t num_bound)
302 for (int32_t i=0; i<num_bound; i++)
314 for (int32_t i=0; i<num_bound; i++)
316 for (int32_t j=i; j<num_bound; j++)
321 Z[j*num_bound+i]=Z[i*num_bound+j];
332 #ifdef DEBUG_SUBGRADIENTSVM
349 #ifdef DEBUG_SUBGRADIENTSVM
367 for (int32_t i=0; i<num_bound; i++)
375 for (int32_t i=0; i<num_bound; i++)
396 for (int32_t i=0; i<num_vec; i++)
399 result +=
C1 * (1.0-
proj[i]);
407 for (int32_t i=0; i<num_vec; i++)
416 void CSubGradientSVM::init(int32_t num_vec, int32_t num_feat)
459 memset(
hinge_idx,0,
sizeof(int32_t)*num_vec);
462 memset(
active,0,
sizeof(uint8_t)*num_vec);
468 memset(
idx_bound,0,
sizeof(int32_t)*num_vec);
474 memset(
Z,0,
sizeof(
float64_t)*qpsize_limit*qpsize_limit);
539 SG_ERROR(
"Specified features are not of type CDotFeatures\n");
544 int32_t num_iterations=0;
549 ASSERT(num_vec==num_train_labels);
551 init(num_vec, num_feat);
553 int32_t num_active=0;
567 #ifdef DEBUG_SUBGRADIENTSVM
577 #ifdef DEBUG_SUBGRADIENTSVM
578 SG_PRINT(
"==================================================\niteration: %d ", num_iterations);
580 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",
606 #ifdef DEBUG_SUBGRADIENTSVM
607 SG_PRINT(
"CHECKING OPTIMALITY CONDITIONS: "
608 "work_epsilon: %10.10f delta_active:%d alpha: %10.10f norm_grad: %10.10f a*norm_grad:%10.16f\n",
643 #ifdef DEBUG_SUBGRADIENTSVM
653 SG_INFO(
"converged after %d iterations\n", num_iterations);
656 SG_INFO(
"objective: %f alpha: %f dir_deriv: %f num_bound: %d num_active: %d\n",
657 obj, alpha, dir_deriv, num_bound, num_active);
659 #ifdef DEBUG_SUBGRADIENTSVM