#include #include /* Input: * S: sample correlation matrix * W: estimated covariance matrix * T: estimated inverse of covariance matrix * d: dimension * ilambda: lambda */ void hugeglasso(const double *S, double *W, double *T, int d, double ilambda) { int d2; d2 = d*d; int i,j,k; //initialize indices int rss_idx,w_idx; int tmp_i; int tmp_j,tmp_a; int gap_int; double gap_ext,gap_act; double thol_act = 1e-4; double thol_ext = 1e-4; int MAX_ITER_EXT = 100; int MAX_ITER_INT = 10000; int MAX_ITER_ACT = 10000; int iter_ext,iter_int,iter_act; int *idx_a = (int*) malloc((d2)*sizeof(int)); //active sets int *idx_i = (int*) malloc((d2)*sizeof(int)); //inactive sets int *size_a = (int*) malloc(d*sizeof(int)); //sizes of active sets double *w1 = (double*) malloc(d*sizeof(double)); double *ww = (double*) malloc(d*sizeof(double)); int size_a_prev; //original size of the active set int junk_a; //the number of variables returning to the inactive set from the active set double r; //partial residual double tmp1,tmp2,tmp3,tmp4,tmp5,tmp6; //Given the initial input W and T, recover inital solution for each individual lasso for(i=0;ithol_ext && iter_ext < MAX_ITER_EXT) //outer loop { tmp1 = 0; tmp6 = 0; tmp5 = 0; for(i=0;iilambda) { w1[j] = (r - ilambda)/W[tmp_j+j]; idx_a[tmp_i+size_a[i]] = j; size_a[i] = size_a[i] + 1; idx_i[tmp_i+j] = -1; } else if(r<-ilambda) { w1[j] = (r + ilambda)/W[tmp_j+j]; idx_a[tmp_i+size_a[i]] = j; size_a[i] = size_a[i] + 1; idx_i[tmp_i+j] = -1; } else w1[j] = 0; T[tmp_i+j] = w1[j]; } } gap_int = size_a[i] - size_a_prev; gap_act = 1; iter_act = 0; while(gap_act>thol_act && iter_act < MAX_ITER_ACT) { tmp3 = 0; tmp4 = 0; for(j=0;jilambda){ w1[w_idx] = (r - ilambda)/W[tmp_a+w_idx]; tmp4 += w1[w_idx]; } else if(r<-ilambda){ w1[w_idx] = (r + ilambda)/W[tmp_a+w_idx]; tmp4 -= w1[w_idx]; } else w1[w_idx] = 0; tmp3 = tmp3 + fabs(w1[w_idx] - T[tmp_i+w_idx]); T[tmp_i+w_idx] = w1[w_idx]; } } gap_act = tmp3/tmp4; iter_act++; } //move the false active variables to the inactive set junk_a = 0; for(j=0;j