|
a |
|
b/MLFre/DPC/SLEP/altra.c |
|
|
1 |
#include "mex.h" |
|
|
2 |
#include <stdio.h> |
|
|
3 |
#include <math.h> |
|
|
4 |
#include <string.h> |
|
|
5 |
#include "altra.h" |
|
|
6 |
|
|
|
7 |
|
|
|
8 |
/* |
|
|
9 |
* ------------------------------------------------------------------- |
|
|
10 |
* Function and parameter |
|
|
11 |
* ------------------------------------------------------------------- |
|
|
12 |
* |
|
|
13 |
* altra solves the following problem |
|
|
14 |
* |
|
|
15 |
* 1/2 \|x-v\|^2 + \sum \lambda_i \|x_{G_i}\|, |
|
|
16 |
* |
|
|
17 |
* where x and v are of dimension n, |
|
|
18 |
* \lambda_i >=0, and G_i's follow the tree structure |
|
|
19 |
* |
|
|
20 |
* The file is implemented in the following in Matlab: |
|
|
21 |
* |
|
|
22 |
* x=altra(v, n, ind, nodes); |
|
|
23 |
* |
|
|
24 |
* ind is a 3 x nodes matrix. |
|
|
25 |
* Each column corresponds to a node. |
|
|
26 |
* |
|
|
27 |
* The first element of each column is the starting index, |
|
|
28 |
* the second element of each column is the ending index |
|
|
29 |
* the third element of each column corrreponds to \lambbda_i. |
|
|
30 |
* |
|
|
31 |
* ------------------------------------------------------------------- |
|
|
32 |
* Notices: |
|
|
33 |
* ------------------------------------------------------------------- |
|
|
34 |
* |
|
|
35 |
* 1. The nodes in the parameter "ind" should be given in the |
|
|
36 |
* either |
|
|
37 |
* the postordering of depth-first traversal |
|
|
38 |
* or |
|
|
39 |
* the reverse breadth-first traversal. |
|
|
40 |
* |
|
|
41 |
* 2. When each elements of x are penalized via the same L1 |
|
|
42 |
* (equivalent to the L2 norm) parameter, one can simplify the input |
|
|
43 |
* by specifying |
|
|
44 |
* the "first" column of ind as (-1, -1, lambda) |
|
|
45 |
* |
|
|
46 |
* In this case, we treat it as a single "super" node. Thus in the value |
|
|
47 |
* nodes, we only count it once. |
|
|
48 |
* |
|
|
49 |
* 3. The values in "ind" are in [1,n]. |
|
|
50 |
* |
|
|
51 |
* 4. The third element of each column should be positive. The program does |
|
|
52 |
* not check the validity of the parameter. |
|
|
53 |
* |
|
|
54 |
* It is still valid to use the zero regularization parameter. |
|
|
55 |
* In this case, the program does not change the values of |
|
|
56 |
* correponding indices. |
|
|
57 |
* |
|
|
58 |
* |
|
|
59 |
* ------------------------------------------------------------------- |
|
|
60 |
* History: |
|
|
61 |
* ------------------------------------------------------------------- |
|
|
62 |
* |
|
|
63 |
* Composed by Jun Liu on April 20, 2010 |
|
|
64 |
* |
|
|
65 |
* For any question or suggestion, please email j.liu@asu.edu. |
|
|
66 |
* |
|
|
67 |
*/ |
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
void mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){ |
|
|
72 |
double* v = mxGetPr(prhs[0]); |
|
|
73 |
int n = (int) mxGetScalar(prhs[1]); |
|
|
74 |
double* ind = mxGetPr(prhs[2]); |
|
|
75 |
int nodes = (int) mxGetScalar(prhs[3]); |
|
|
76 |
|
|
|
77 |
int i; |
|
|
78 |
double *x; |
|
|
79 |
|
|
|
80 |
/* set up output arguments */ |
|
|
81 |
plhs[0] = mxCreateDoubleMatrix(n,1,mxREAL); |
|
|
82 |
|
|
|
83 |
x = mxGetPr(plhs[0]); |
|
|
84 |
altra(x, v, n, ind, nodes); |
|
|
85 |
} |
|
|
86 |
|