SHOGUN
v3.2.0
|
00001 /* This program is free software: you can redistribute it and/or modify 00002 * it under the terms of the GNU General Public License as published by 00003 * the Free Software Foundation, either version 3 of the License, or 00004 * (at your option) any later version. 00005 * 00006 * This program is distributed in the hope that it will be useful, 00007 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00008 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00009 * GNU General Public License for more details. 00010 * 00011 * You should have received a copy of the GNU General Public License 00012 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00013 * 00014 * Copyright (C) 2009 - 2012 Jun Liu and Jieping Ye 00015 */ 00016 00017 #ifndef EP21D_SLEP 00018 #define EP21D_SLEP 00019 00020 #include <stdlib.h> 00021 #include <stdio.h> 00022 #include <time.h> 00023 #include <math.h> 00024 #include <shogun/lib/slep/q1/epph.h> /* This is the head file that contains the implementation of the used functions*/ 00025 00026 /* 00027 Euclidean Projection onto l_{2,1} Ball 00028 00029 min 1/2 ||X- V||_2^2 00030 s.t. ||X||_{2,1} <= z 00031 00032 which is converted to the following zero finding problem 00033 00034 f(lambda)= \sum_i ( max( |v^i|-lambda,0) )-z=0 00035 00036 v^i denotes the i-th row of V 00037 00038 Usage: 00039 [x, lambda, iter_step]=ep21d(y, n, k, z, lambda0); 00040 00041 */ 00042 00043 00044 void ep21d(double * x, double *root, int * steps, double * v, int n, int k, double z, double lambda0) 00045 { 00046 int i, j, tn=n*k; 00047 double *vnorm=(double *)malloc(sizeof(double)*n); 00048 double *vproj=(double *)malloc(sizeof(double)*n); 00049 double t; 00050 00051 /* compute the 2 norm of each group 00052 */ 00053 00054 for(j=0;j<n;j++){ 00055 t=0; 00056 for(i=j; i< tn; i+=n) 00057 t+= v[i]* v[i]; 00058 vnorm[j]=sqrt(t); 00059 } 00060 00061 00062 00063 eplb(vproj, root, steps, vnorm, n, z, lambda0); 00064 00065 /* compute x 00066 */ 00067 00068 if (*root==0){ 00069 for(i=0;i<tn;i++) 00070 x[i]=v[i]; 00071 } 00072 else{ 00073 for (j=0;j<n;j++){ 00074 if ( vnorm[j] <= *root){ 00075 for(i=j; i< tn; i+=n) 00076 x[i]=0; 00077 } 00078 else{ 00079 t=1- *root/ vnorm[j]; 00080 for(i=j; i< tn; i+=n) 00081 x[i]=t* v[i]; 00082 } 00083 } 00084 } 00085 00086 free(vnorm); 00087 free(vproj); 00088 00089 } 00090 #endif /* ----- #ifndef EP21D_SLEP ----- */ 00091