|
| 1 | +/*function [ x, lambda ] = glLeastC( v, radius, ind, w, u ) |
| 2 | +
|
| 3 | + Solve the following group projection: |
| 4 | +
|
| 5 | + \min_{x} \| x - v \|_2 |
| 6 | + subject to \sum \|x_{G_i}\|_2 <= radius, |
| 7 | +
|
| 8 | + where the group information is contained in the "ind" array |
| 9 | + Require SLEP package, the "eplb" function. |
| 10 | +*/ |
| 11 | + |
| 12 | +#include <math.h> |
| 13 | +#include "mex.h" |
| 14 | +#include "SLEP_4.0/SLEP/CFiles/q1/epph.h" |
| 15 | + |
| 16 | +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
| 17 | +{ |
| 18 | + double *v, *ind, *w, *u, *x, *lambda; |
| 19 | + double radius, lambda0, sum; |
| 20 | + |
| 21 | + int n, grpNum; |
| 22 | + int i, j, k, steps, be, en; |
| 23 | + |
| 24 | + if(nlhs != 2) |
| 25 | + mexErrMsgTxt("Error: Number of output parameter does not match."); |
| 26 | + |
| 27 | + if(nrhs !=5) |
| 28 | + mexErrMsgTxt("Error: Number of input parameter does not match."); |
| 29 | + |
| 30 | + n = mxGetNumberOfElements(prhs[0]); |
| 31 | + grpNum = mxGetNumberOfElements(prhs[2]) - 1; |
| 32 | + lambda0 = .0; |
| 33 | + |
| 34 | + v = mxGetPr(prhs[0]); |
| 35 | + radius = mxGetScalar(prhs[1]); |
| 36 | + ind = mxGetPr(prhs[2]); |
| 37 | + w = mxGetPr(prhs[3]); |
| 38 | + u = mxGetPr(prhs[4]); |
| 39 | + |
| 40 | + |
| 41 | + plhs[0] = mxCreateDoubleMatrix(n, 1, mxREAL); |
| 42 | + plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL); |
| 43 | + x = mxGetPr(plhs[0]); |
| 44 | + lambda = mxGetPr(plhs[1]); |
| 45 | + |
| 46 | + for(i = 0; i < grpNum; i++) |
| 47 | + { |
| 48 | + sum = .0; |
| 49 | + be = (int)ind[i], en = (int)ind[i+1]; |
| 50 | + for(j = be; j < en; j++) |
| 51 | + sum += v[j] * v[j]; |
| 52 | + w[i] = sqrt(sum); |
| 53 | + } |
| 54 | + |
| 55 | + eplb(u, lambda, &steps, w, grpNum, radius, lambda0); |
| 56 | + |
| 57 | + for(i = 0, j = 0; j < grpNum; j++) |
| 58 | + { |
| 59 | + be = (int)ind[j], en = (int)ind[j+1]; |
| 60 | + |
| 61 | + if(fabs(w[j]) > 1e-15) |
| 62 | + for(i = be; i < en; i++) |
| 63 | + x[i] = u[j] * v[i] / w[j]; |
| 64 | + else |
| 65 | + for(i = be; i < en; i++) |
| 66 | + x[i] = 0; |
| 67 | + } |
| 68 | +} |
| 69 | + |
0 commit comments