/* epglb(x_c2, v, n, s2, ind, grpNum, tmpW, tmpU); */ void epglb(double *x, double *v, int n, double radius, double *ind, int grpNum, double *w, double *u) { int i, j, be, en, steps; double lambda, sum, lambda0; for(i = 0; i < grpNum; i++) { sum = .0; be = (int)ind[i], en = (int)ind[i+1]; for(j = be; j < en; j++) sum += v[j] * v[j]; w[i] = sqrt(sum); } lambda = lambda0 = .0; eplb(u, &lambda, &steps, w, grpNum, radius, lambda0); for(i = 0, j = 0; j < grpNum; j++) { be = (int)ind[j], en = (int)ind[j+1]; if(fabs(w[j]) > 1e-15) for(i = be; i < en; i++) x[i] = u[j] * v[i] / w[j]; else for(i = be; i < en; i++) x[i] = .0; } }
void eppInf(double *x, double * c, int * iter_step, double *v, int n, double rho, double c0) { int i, steps; /* we assume rho>=0 */ eplb(x, c, &steps, v, n, rho, c0); for(i=0; i< n; i++) { x[i]=v[i]-x[i]; } iter_step[0]=steps; iter_step[1]=0; }
void mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { /*set up input arguments */ double* v= mxGetPr(prhs[0]); int n= (int)mxGetScalar(prhs[1]); double z= mxGetScalar(prhs[2]); double lambda0= mxGetScalar(prhs[3]); double *x, *lambda; double *iter_step; int steps; /* set up output arguments */ plhs[0] = mxCreateDoubleMatrix(n,1,mxREAL); plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); plhs[2] = mxCreateDoubleMatrix(1,1,mxREAL); x=mxGetPr(plhs[0]); lambda=mxGetPr(plhs[1]); iter_step=mxGetPr(plhs[2]); eplb(x, lambda, &steps, v, n, z, lambda0); *iter_step=steps; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *v, *ans, s1, s2; double *ind; double *x; double *u, *tmpV, *tmpU, *tmpW; double up, mid, low, h_s1, lambda0, lambda; int n, grpNum; int i, j, k; if(nlhs != 1) mexErrMsgTxt("Error: Number of output parameter does not match."); if(nrhs !=4) mexErrMsgTxt("Error: Number of input parameter does not match."); /* * Input Parameter handle */ v = mxGetPr(prhs[0]); s1 = mxGetScalar(prhs[1]); s2 = mxGetScalar(prhs[2]); ind = mxGetPr(prhs[3]); n = (int)mxGetNumberOfElements(prhs[0]); grpNum = (int)mxGetNumberOfElements(prhs[3]) - 1; /* * Output Parameter handle */ plhs[0] = mxCreateDoubleMatrix(n, 1, mxREAL); ans = mxGetPr(plhs[0]); /* Temporary variables. */ lambda = lambda0 = .0; x = (double *)malloc(n * sizeof(double)); tmpV = (double *)malloc(n * sizeof(double)); tmpU = (double *)malloc(grpNum * sizeof(double)); tmpW = (double *)malloc(grpNum * sizeof(double)); if(l1Norm(v, n) <= s1 + 1e-12 && grpNorm(v, ind, grpNum) <= s2 + 1e-12) { for(i = 0; i < n; i++) ans[i] = v[i]; free(x); free(tmpV); free(tmpU); free(tmpW); return; } lambda0 = .0; eplb(x, &lambda, &k, v, n, s1, lambda0); if(grpNorm(x, ind, grpNum) < s2 - 1e-12) { for(i = 0; i < n; i++) ans[i] = x[i]; free(x); free(tmpV); free(tmpU); free(tmpW); return; } epglb(x, v, n, s2, ind, grpNum, tmpW, tmpU); if(l1Norm(x, n) < s1 - 1e-12) { for(i = 0; i < n; i++) ans[i] = x[i]; free(x); free(tmpV); free(tmpU); free(tmpW); return; } up = 1e15, low = 1e-12; while(up - low > 1e-7) { if(low > 1e6 && up - low < 1e-5) break; mid = (up + low) / 2; soft_thresholding(tmpV, v, n, mid); if(grpNorm(tmpV, ind, grpNum) < s2 - 1e-15) up = mid; else{ epglb(x, tmpV, n, s2, ind, grpNum, tmpW, tmpU); h_s1 = l1Norm(x, n); if(h_s1 < s1 + 1e-15) up = mid; else low = mid; } } soft_thresholding(tmpV, v, n, up); epglb(x, tmpV, n, s2, ind, grpNum, tmpW, tmpU); for(i = 0; i < n; i++) ans[i] = x[i]; free(x); free(tmpV); free(tmpU); free(tmpW); }