26 using namespace shogun;
50 void CLibLinearMTL::init()
80 SG_ERROR(
"Specified features are not of type CDotFeatures\n");
92 if (num_vec!=num_train_labels)
94 SG_ERROR(
"number of vectors %d does not match "
95 "number of training labels %d\n",
96 num_vec, num_train_labels);
110 memset(training_w, 0,
sizeof(
float64_t)*(num_feat+1));
115 memset(training_w, 0,
sizeof(
float64_t)*(num_feat+0));
122 for (int32_t i=0; i<prob.l; i++)
127 for(
int i=0;i<prob.l;i++)
134 SG_INFO(
"%d training points %d dims\n", prob.l, prob.n);
135 SG_INFO(
"%d positives, %d negatives\n", pos, neg);
139 solve_l2r_l1l2_svc(&prob,
epsilon, Cp, Cn);
149 for (int32_t i=0; i<num_feat; i++)
150 w[i] = training_w[i];
180 #define GETI(i) (y[i]+1)
184 void CLibLinearMTL::solve_l2r_l1l2_svc(
const problem *prob,
double eps,
double Cp,
double Cn)
190 int w_size = prob->n;
203 double PGmax_new, PGmin_new;
213 double diag[3] = {0.5/Cn, 0, 0.5/Cp};
229 for(int32_t k=0; k<w_size*
num_tasks; k++)
250 QD[i] = diag[
GETI(i)];
251 QD[i] += prob->x->
dot(i, prob->x,i);
264 for (i=0; i<active_size; i++)
266 int j = i+rand()%(active_size-i);
270 for (s=0;s<active_size;s++)
275 C = upper_bound[
GETI(i)];
279 typedef std::map<index_t, float64_t>::const_iterator map_iter;
286 int32_t e_i = it->first;
291 inner_sum += sim * yi * prob->x->dense_dot(i, tmp_w, n);
315 else if (alphas[i] == C)
333 if(fabs(PG) > 1.0e-12)
336 double alpha_old = alphas[i];
340 d = (alphas[i] - alpha_old)*yi;
344 prob->x->add_to_dense_vec(d, i, tmp_w, n);
368 PGmax_old = PGmax_new;
369 PGmin_old = PGmin_new;
377 SG_INFO(
"optimization finished, #iter = %d\n",iter);
380 SG_WARNING(
"reaching max number of iterations\nUsing -s 2 may be faster"
381 "(also see liblinear FAQ)\n\n");
435 SG_INFO(
"DONE to compute Primal OBJ\n");
448 for(int32_t i=0; i<w_size; i++)
450 obj += 0.5 * w_t[i]*w_t[i];
463 for(int32_t i=0; i<w_size; i++)
465 obj += 0.5 * l * w_s[i]*w_t[i];
471 for(int32_t i=0; i<num_vec; i++)
482 SG_INFO(
"DONE to compute Primal OBJ, obj=%f\n",obj);
504 SG_INFO(
"starting to compute DUAL OBJ\n");
511 for(int32_t i=0; i<num_vec; i++)
529 for(int32_t i=0; i<v_size; i++)
531 obj -= 0.5 * ts * v_s[i]*v_t[i];