25 using namespace shogun;
27 #define DEBUG_SUBGRADIENTLPM
31 qpsize_max(2000), use_bias(false), delta_active(0), delta_bound(0)
38 qpsize_max(2000), use_bias(false), delta_active(0), delta_bound(0)
51 int32_t num_feat, int32_t num_vec, int32_t& num_active, int32_t& num_bound)
84 for (int32_t i=0; i<num_vec; i++)
124 for (int32_t i=0; i<num_vec; i++)
134 #ifdef DEBUG_SUBGRADIENTSVM
168 for (int32_t i=0; i<num_vec; i++)
197 for (int32_t i=0; i<num_feat; i++)
223 for (int32_t i=0; i<num_vec; i++)
254 for (int32_t i=0; i<num_feat+num_vec; i++)
271 D[i]=
C1*(1-
proj[i-num_feat]);
274 if (A[i]==C[i] && B[i]>D[i])
276 else if (A[i]==C[i] && B[i]==D[i])
305 while (i < num_hinge-1 && sgrad < 0)
312 sgrad += C[hinge_idx[i]] - A[hinge_idx[i]];
327 int32_t num_feat, int32_t num_vec, int32_t num_active, int32_t num_bound)
356 dir_deriv = CMath::dot(
beta,
grad_w, num_feat);
359 for (int32_t i=0; i<num_bound; i++)
365 for (int32_t i=0; i<num_feat; i++)
414 float64_t result= CMath::sum_abs(
w, num_feat);
416 for (int32_t i=0; i<num_vec; i++)
419 result +=
C1 * (1.0-
proj[i]);
427 for (int32_t i=0; i<num_vec; i++)
433 CMath::vec1_plus_scalar_times_vec2(
proj,-alpha,
grad_proj, num_vec);
436 void CSubGradientLPM::init(int32_t num_vec, int32_t num_feat)
442 for (int32_t i=0; i<num_feat; i++)
450 memset(
w_pos,0,
sizeof(int32_t)*num_feat);
453 memset(
w_zero,0,
sizeof(int32_t)*num_feat);
456 memset(
w_neg,0,
sizeof(int32_t)*num_feat);
482 memset(
hinge_idx,0,
sizeof(int32_t)*(num_vec+num_feat));
485 memset(
active,0,
sizeof(uint8_t)*num_vec);
491 memset(
idx_bound,0,
sizeof(int32_t)*num_vec);
497 memset(
beta,0,
sizeof(
float64_t)*num_feat+1+num_feat+num_vec);
550 SG_ERROR(
"Specified features are not of type CDotFeatures\n");
555 int32_t num_iterations=0;
560 ASSERT(num_vec==num_train_labels);
562 init(num_vec, num_feat);
564 int32_t num_active=0;
586 #ifdef DEBUG_SUBGRADIENTLPM
587 SG_PRINT(
"==================================================\niteration: %d ", num_iterations);
589 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",
615 SG_PRINT(
"CHECKING OPTIMALITY CONDITIONS: "
616 "work_epsilon: %10.10f delta_active:%d alpha: %10.10f norm_grad: %10.10f a*norm_grad:%10.16f\n",
639 CMath::vec1_plus_scalar_times_vec2(
w, -alpha,
grad_w, num_feat);
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_SUBGRADIENTLPM
659 CMath::display_vector(
w, w_dim,
"w");