19 void m_Ax(
double *Ax,
double *A,
double *x,
int n,
int ith)
37 int lassoCD(
double *Theta,
double *W,
double *S,
double lambda,
int n,
int ith,
int flag,
int maxIter,
double fGap,
double xGap)
41 double u, v, s_v, t=0, x_new;
42 double fun_new,fun_old=-100;
45 Ax= (
double *)malloc(
sizeof(
double)*n);
46 x= (
double *)malloc(
sizeof(
double)*n);
49 if ( (Ax==NULL) || (x==NULL) ){
50 printf(
"\n Memory allocation failure!");
62 m_Ax(Ax, W, x, n, ith);
64 for (iter_step=0;iter_step<maxIter; iter_step++){
81 x_new= (s_v-lambda) / u;
84 x_new= (s_v + lambda) / u;
92 Ax[j]+= W[j*n+ i]*(x_new - x[i]);
94 x_change+=fabs(x[i]-x_new);
106 fun_new+=- S[i*n+ith]*x[i]+ lambda* fabs(x[i]);
117 if ( (fabs(fun_new-fun_old) <=fGap) || x_change <=xGap){
135 t=1/(W[ith*n+ith]-t);
136 Theta[ith*n + ith]=t;
141 W[i*n+ ith]=W[ith*n +i]=Ax[i];
142 Theta[i*n+ ith]=Theta[ith*n +i]=-x[i]*t;
149 W[i*n+ ith]=W[ith*n +i]=Ax[i];
150 Theta[i*n+ ith]=Theta[ith*n +i]=x[i];
161 void invCov(
double *Theta,
double *W,
double *S,
double lambda,
double sum_S,
int n,
162 int LassoMaxIter,
double fGap,
double xGap,
163 int maxIter,
double xtol)
165 int iter_step, i,j, ith;
170 W_old= (
double *)malloc(
sizeof(
double)*n*n);
174 printf(
"\n Memory allocation failure!");
181 W_old[i*n+j]=W[i*n+j]=S[i*n+j]+lambda;
183 W_old[i*n+j]=W[i*n+j]=S[i*n+j];
188 for (iter_step=0;iter_step<=maxIter; iter_step++){
189 for(ith=0;ith<n;ith++)
190 lassoCD(Theta, W, S, lambda, n, ith, flag, LassoMaxIter,fGap, xGap);
198 gap+=fabs(W[i*n+j]-W_old[i*n+j]);
199 W_old[i*n+j]=W[i*n+j];
205 if ( (gap <= xtol) || (iter_step==maxIter-1) ){