Skip to content

Commit

Permalink
Merge branch 'slep' of git://github.com/lisitsyn/shogun
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jul 2, 2012
2 parents f482b5d + 7765f01 commit 84b7803
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
24 changes: 2 additions & 22 deletions src/shogun/lib/slep/slep_tree_mt_lr.cpp
Expand Up @@ -30,7 +30,6 @@ slep_result_t slep_tree_mt_lr(
double funcp = 0.0, func = 0.0;

int n_tasks = options.n_tasks;
//SG_SPRINT("N tasks = %d \n", n_tasks);

int iter = 1;
bool done = false;
Expand Down Expand Up @@ -81,7 +80,7 @@ slep_result_t slep_tree_mt_lr(
else
lambda_max = findLambdaMax_mt(ATb, n_feats, n_tasks, options.ind_t, options.n_nodes);

lambda_max /= n_feats*n_tasks;
lambda_max /= n_vecs*n_tasks;

lambda = z*lambda_max;
}
Expand Down Expand Up @@ -144,7 +143,6 @@ slep_result_t slep_tree_mt_lr(
while (!done && iter <= options.max_iter)
{
beta = (alphap-1.0)/alpha;
//SG_SPRINT("beta = %f \n", beta);

for (i=0; i<n_feats*n_tasks; i++)
s[i] = w[i] + beta*wwp[i];
Expand All @@ -154,8 +152,6 @@ slep_result_t slep_tree_mt_lr(
for (i=0; i<n_vecs; i++)
As[i] = Aw[i] + beta*(Aw[i]-Awp[i]);

//SG_SPRINT("As = %f\n",SGVector<float64_t>::dot(As,As,n_vecs));

double fun_s = 0.0;
for (i=0; i<n_tasks*n_feats; i++)
g[i] = 0.0;
Expand All @@ -181,10 +177,6 @@ slep_result_t slep_tree_mt_lr(
}
fun_s /= n_vecs;

//SG_SPRINT("fun_s = %f\n", fun_s);

//SG_SPRINT("g = %f\n", SGVector<float64_t>::dot(g,g,n_feats*n_tasks));

for (i=0; i<n_feats*n_tasks; i++)
wp[i] = w[i];

Expand All @@ -195,7 +187,7 @@ slep_result_t slep_tree_mt_lr(
Awp[i] = Aw[i];

int inner_iter = 1;
while (inner_iter < 100)
while (inner_iter < 1000)
{
// v = s - g / L
for (i=0; i<n_feats*n_tasks; i++)
Expand All @@ -210,12 +202,6 @@ slep_result_t slep_tree_mt_lr(
else
altra_mt(w.matrix, v, n_feats, n_tasks, options.ind_t, options.n_nodes, lambda/L);

//SG_SPRINT("params [%d,%d,%f,%f]\n", n_feats, n_tasks, lambda/L, options.q);

//w.display_matrix();
//SG_SPRINT("w = %f \n", SGVector<float64_t>::dot(w.matrix,w.matrix,n_feats*n_tasks));

// v = x - s
for (i=0; i<n_feats*n_tasks; i++)
v[i] = w[i] - s[i];

Expand All @@ -235,9 +221,6 @@ slep_result_t slep_tree_mt_lr(
}
fun_x /= n_vecs;

//SG_SPRINT("Aw = %f\n", SGVector<float64_t>::dot(Aw,Aw,n_vecs));
//c.display_vector();

double r_sum = SGVector<float64_t>::dot(v,v,n_feats*n_tasks);
double l_sum = fun_x - fun_s - SGVector<float64_t>::dot(v,g,n_feats*n_tasks);

Expand All @@ -248,8 +231,6 @@ slep_result_t slep_tree_mt_lr(
}
r_sum /= 2.0;

//SG_SPRINT("sums = [%f, %f, %f]\n", r_sum, l_sum, fun_x);

if (r_sum <= 1e-20)
{
gradient_break = true;
Expand Down Expand Up @@ -290,7 +271,6 @@ slep_result_t slep_tree_mt_lr(

funcp = func;
func = fun_x + lambda*regularizer;
//SG_SPRINT("Obj = %f + %f * %f = %f \n",fun_x, lambda, regularizer, func);

if (gradient_break)
break;
Expand Down
12 changes: 7 additions & 5 deletions src/shogun/lib/slep/slep_tree_mt_lsr.cpp
Expand Up @@ -38,10 +38,12 @@ SGMatrix<double> slep_tree_mt_lsr(
double* ATy = SG_CALLOC(double, n_feats*n_tasks);
for (t=0; t<n_tasks; t++)
{
int task_ind_start = options.ind[t]+1;
int task_ind_start = options.ind[t];
int task_ind_end = options.ind[t+1];
for (i=task_ind_start; i<task_ind_end; i++)
{
features->add_to_dense_vec(y[i],i,ATy+t*n_feats,n_feats);
}
}

if (options.regularization!=0)
Expand Down Expand Up @@ -75,7 +77,7 @@ SGMatrix<double> slep_tree_mt_lsr(
double* Aw = SG_CALLOC(double, n_vecs);
for (t=0; t<n_tasks; t++)
{
int task_ind_start = options.ind[t]+1;
int task_ind_start = options.ind[t];
int task_ind_end = options.ind[t+1];
for (i=task_ind_start; i<task_ind_end; i++)
Aw[i] = features->dense_dot(i,w.matrix+t*n_feats,n_feats);
Expand All @@ -100,7 +102,7 @@ SGMatrix<double> slep_tree_mt_lsr(
double alphap = 0.0;
double alpha = 1.0;

while (!done && iter < options.max_iter)
while (!done && iter <= options.max_iter)
{
beta = (alphap-1.0)/alpha;

Expand All @@ -116,7 +118,7 @@ SGMatrix<double> slep_tree_mt_lsr(

for (t=0; t<n_tasks; t++)
{
int task_ind_start = options.ind[t]+1;
int task_ind_start = options.ind[t];
int task_ind_end = options.ind[t+1];
for (i=task_ind_start; i<task_ind_end; i++)
features->add_to_dense_vec(As[i],i,ATAs+t*n_feats,n_feats);
Expand Down Expand Up @@ -149,7 +151,7 @@ SGMatrix<double> slep_tree_mt_lsr(

for (t=0; t<n_tasks; t++)
{
int task_ind_start = options.ind[t]+1;
int task_ind_start = options.ind[t];
int task_ind_end = options.ind[t+1];
for (i=task_ind_start; i<task_ind_end; i++)
Aw[i] = features->dense_dot(i,w.matrix+t*n_feats,n_feats);
Expand Down

0 comments on commit 84b7803

Please sign in to comment.