21 #include <shogun/classifier/svm/qpbsvmlib.h>
25 using namespace shogun;
27 #define DEBUG_SUBGRADIENTLPM
30 : CLinearClassifier(), C1(1), C2(1), epsilon(1e-5), qpsize(42),
31 qpsize_max(2000), use_bias(false), delta_active(0), delta_bound(0)
37 : CLinearClassifier(), C1(C), C2(C), epsilon(1e-5), qpsize(42),
38 qpsize_max(2000), use_bias(false), delta_active(0), delta_bound(0)
40 CLinearClassifier::features=traindat;
41 CClassifier::labels=trainlab;
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++)
253 for (int32_t i=0; i<num_feat+num_vec; i++)
270 D[i]=
C1*(1-
proj[i-num_feat]);
273 if (A[i]==C[i] && B[i]>D[i])
275 else if (A[i]==C[i] && B[i]==D[i])
304 while (i < num_hinge-1 && sgrad < 0)
311 sgrad += C[hinge_idx[i]] - A[hinge_idx[i]];
326 int32_t num_feat, int32_t num_vec, int32_t num_active, int32_t num_bound)
358 for (int32_t i=0; i<num_bound; i++)
364 for (int32_t i=0; i<num_feat; i++)
415 for (int32_t i=0; i<num_vec; i++)
418 result +=
C1 * (1.0-
proj[i]);
426 for (int32_t i=0; i<num_vec; i++)
427 proj[i]=get_label(i)*(features->dense_dot(i, w, num_feat) + bias);
441 for (int32_t i=0; i<num_feat; i++)
449 memset(
w_pos,0,
sizeof(int32_t)*num_feat);
452 memset(
w_zero,0,
sizeof(int32_t)*num_feat);
455 memset(
w_neg,0,
sizeof(int32_t)*num_feat);
481 memset(
hinge_idx,0,
sizeof(int32_t)*(num_vec+num_feat));
484 memset(
active,0,
sizeof(uint8_t)*num_vec);
490 memset(
idx_bound,0,
sizeof(int32_t)*num_vec);
496 memset(
beta,0,
sizeof(
float64_t)*num_feat+1+num_feat+num_vec);
549 SG_ERROR(
"Specified features are not of type CDotFeatures\n");
554 int32_t num_iterations=0;
555 int32_t num_train_labels=labels->get_num_labels();
556 int32_t num_feat=features->get_dim_feature_space();
557 int32_t num_vec=features->get_num_vectors();
559 ASSERT(num_vec==num_train_labels);
561 init(num_vec, num_feat);
563 int32_t num_active=0;
585 #ifdef DEBUG_SUBGRADIENTLPM
586 SG_PRINT(
"==================================================\niteration: %d ", num_iterations);
588 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",
614 SG_PRINT(
"CHECKING OPTIMALITY CONDITIONS: "
615 "work_epsilon: %10.10f delta_active:%d alpha: %10.10f norm_grad: %10.10f a*norm_grad:%10.16f\n",
647 if (get_max_train_time()>0 && time.
cur_time_diff()>get_max_train_time())
651 SG_INFO(
"converged after %d iterations\n", num_iterations);
654 SG_INFO(
"objective: %f alpha: %f dir_deriv: %f num_bound: %d num_active: %d\n",
655 obj, alpha, dir_deriv, num_bound, num_active);
657 #ifdef DEBUG_SUBGRADIENTLPM