SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eppVectorR.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 #ifndef EPPVECTORR_SLEP
18 #define EPPVECTORR_SLEP
19 
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <time.h>
23 #include <math.h>
24 
25 /*
26  min 1/2 ( ||x- u||_2^2 + ||t-v||_2^2 )
27  s.t. ||x_j||_2 <= t_j
28 
29  */
30 
31 void eppVectorR(double *x, double * t, double * u, double * v, double * ind, int n, int k){
32  int i, j;
33  double temp;
34 
35  /* compute the 2 norm of each group
36  */
37 
38  for(j=0;j<k;j++){
39  temp=0;
40  for(i=(int) (ind[j]); i< (int) (ind[j+1]); i++)
41  temp+= u[i]* u[i];
42  temp=sqrt(temp);
43  /*temp contains the 2-norm of of each row of u*/
44 
45  if(temp > fabs(v[j])){
46  t[j]=(temp + v[j])/2;
47 
48  for(i=(int) (ind[j]); i< (int) (ind[j+1]); i++)
49  x[i]= t[j] / temp * u[i];
50  }
51  else
52  if(temp <= v[j]){
53  t[j]=v[j];
54 
55  for(i=(int) (ind[j]); i< (int) (ind[j+1]); i++)
56  x[i]= u[i];
57  }
58  else{
59  t[j]=0;
60 
61  for(i=(int) (ind[j]); i< (int) (ind[j+1]); i++)
62  x[i]=0;
63  }
64 
65  }
66 }
67 #endif /* ----- #ifndef EPPVECTORR_SLEP ----- */

SHOGUN Machine Learning Toolbox - Documentation