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);
48 printf(
"\n Memory allocation failure!");
52 x= (
double *)malloc(
sizeof(
double)*n);
55 printf(
"\n Memory allocation failure!");
68 m_Ax(Ax, W, x, n, ith);
70 for (iter_step=0;iter_step<maxIter; iter_step++){
87 x_new= (s_v-lambda) / u;
90 x_new= (s_v + lambda) / u;
98 Ax[j]+= W[j*n+ i]*(x_new - x[i]);
100 x_change+=fabs(x[i]-x_new);
112 fun_new+=- S[i*n+ith]*x[i]+ lambda* fabs(x[i]);
123 if ( (fabs(fun_new-fun_old) <=fGap) || x_change <=xGap){
141 t=1/(W[ith*n+ith]-t);
142 Theta[ith*n + ith]=t;
147 W[i*n+ ith]=W[ith*n +i]=Ax[i];
148 Theta[i*n+ ith]=Theta[ith*n +i]=-x[i]*t;
155 W[i*n+ ith]=W[ith*n +i]=Ax[i];
156 Theta[i*n+ ith]=Theta[ith*n +i]=x[i];
167 void invCov(
double *Theta,
double *W,
double *S,
double lambda,
double sum_S,
int n,
168 int LassoMaxIter,
double fGap,
double xGap,
169 int maxIter,
double xtol)
171 int iter_step, i,j, ith;
176 W_old= (
double *)malloc(
sizeof(
double)*n*n);
180 printf(
"\n Memory allocation failure!");
187 W_old[i*n+j]=W[i*n+j]=S[i*n+j]+lambda;
189 W_old[i*n+j]=W[i*n+j]=S[i*n+j];
194 for (iter_step=0;iter_step<=maxIter; iter_step++){
195 for(ith=0;ith<n;ith++)
196 lassoCD(Theta, W, S, lambda, n, ith, flag, LassoMaxIter,fGap, xGap);
204 gap+=fabs(W[i*n+j]-W_old[i*n+j]);
205 W_old[i*n+j]=W[i*n+j];
211 if ( (gap <= xtol) || (iter_step==maxIter-1) ){