SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ep21d.h
Go to the documentation of this file.
1 /* This program is free software: you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation, either version 3 of the License, or
4  * (at your option) any later version.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program. If not, see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright (C) 2009 - 2012 Jun Liu and Jieping Ye
15  */
16 
17 
18 #ifndef EP21D_SLEP
19 #define EP21D_SLEP
20 
21 #include <shogun/lib/config.h>
22 #ifdef USE_GPL_SHOGUN
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <time.h>
27 #include <math.h>
28 #include <shogun/lib/slep/q1/epph.h> /* This is the head file that contains the implementation of the used functions*/
29 
30 /*
31  Euclidean Projection onto l_{2,1} Ball
32 
33  min 1/2 ||X- V||_2^2
34  s.t. ||X||_{2,1} <= z
35 
36  which is converted to the following zero finding problem
37 
38  f(lambda)= \sum_i ( max( |v^i|-lambda,0) )-z=0
39 
40  v^i denotes the i-th row of V
41 
42 Usage:
43 [x, lambda, iter_step]=ep21d(y, n, k, z, lambda0);
44 
45 */
46 
47 
48 void ep21d(double * x, double *root, int * steps, double * v, int n, int k, double z, double lambda0)
49 {
50  int i, j, tn=n*k;
51  double *vnorm=(double *)malloc(sizeof(double)*n);
52  double *vproj=(double *)malloc(sizeof(double)*n);
53  double t;
54 
55  /* compute the 2 norm of each group
56  */
57 
58  for(j=0;j<n;j++){
59  t=0;
60  for(i=j; i< tn; i+=n)
61  t+= v[i]* v[i];
62  vnorm[j]=sqrt(t);
63  }
64 
65 
66 
67  eplb(vproj, root, steps, vnorm, n, z, lambda0);
68 
69  /* compute x
70  */
71 
72  if (*root==0){
73  for(i=0;i<tn;i++)
74  x[i]=v[i];
75  }
76  else{
77  for (j=0;j<n;j++){
78  if ( vnorm[j] <= *root){
79  for(i=j; i< tn; i+=n)
80  x[i]=0;
81  }
82  else{
83  t=1- *root/ vnorm[j];
84  for(i=j; i< tn; i+=n)
85  x[i]=t* v[i];
86  }
87  }
88  }
89 
90  free(vnorm);
91  free(vproj);
92 
93 }
94 #endif //USE_GPL_SHOGUN
95 #endif /* ----- #ifndef EP21D_SLEP ----- */
96 

SHOGUN Machine Learning Toolbox - Documentation