SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ep21d.h
浏览该文件的文档.
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 EP21D_SLEP
18 #define EP21D_SLEP
19 
20 #include <shogun/lib/config.h>
21 
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <time.h>
25 #include <math.h>
26 #include <shogun/lib/slep/q1/epph.h> /* This is the head file that contains the implementation of the used functions*/
27 
28 /*
29  Euclidean Projection onto l_{2,1} Ball
30 
31  min 1/2 ||X- V||_2^2
32  s.t. ||X||_{2,1} <= z
33 
34  which is converted to the following zero finding problem
35 
36  f(lambda)= \sum_i ( max( |v^i|-lambda,0) )-z=0
37 
38  v^i denotes the i-th row of V
39 
40 Usage:
41 [x, lambda, iter_step]=ep21d(y, n, k, z, lambda0);
42 
43 */
44 
45 
46 void ep21d(double * x, double *root, int * steps, double * v, int n, int k, double z, double lambda0)
47 {
48  int i, j, tn=n*k;
49  double *vnorm=(double *)malloc(sizeof(double)*n);
50  double *vproj=(double *)malloc(sizeof(double)*n);
51  double t;
52 
53  /* compute the 2 norm of each group
54  */
55 
56  for(j=0;j<n;j++){
57  t=0;
58  for(i=j; i< tn; i+=n)
59  t+= v[i]* v[i];
60  vnorm[j]=sqrt(t);
61  }
62 
63 
64 
65  eplb(vproj, root, steps, vnorm, n, z, lambda0);
66 
67  /* compute x
68  */
69 
70  if (*root==0){
71  for(i=0;i<tn;i++)
72  x[i]=v[i];
73  }
74  else{
75  for (j=0;j<n;j++){
76  if ( vnorm[j] <= *root){
77  for(i=j; i< tn; i+=n)
78  x[i]=0;
79  }
80  else{
81  t=1- *root/ vnorm[j];
82  for(i=j; i< tn; i+=n)
83  x[i]=t* v[i];
84  }
85  }
86  }
87 
88  free(vnorm);
89  free(vproj);
90 
91 }
92 #endif /* ----- #ifndef EP21D_SLEP ----- */
93 
void ep21d(double *x, double *root, int *steps, double *v, int n, int k, double z, double lambda0)
Definition: ep21d.h:46
void eplb(double *x, double *root, int *steps, double *v, int n, double z, double lambda0)
Definition: epph.cpp:28

SHOGUN 机器学习工具包 - 项目文档