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 EP21R_SLEP 00018 #define EP21R_SLEP 00019 00020 #include <stdlib.h> 00021 #include <stdio.h> 00022 #include <time.h> 00023 #include <math.h> 00024 00025 00026 /* 00027 Euclidean Projection onto l_{2,1} Ball 00028 00029 min 1/2 ||x- u||_2^2 + 1/2 ||t- v||_2^2 00030 s.t. ||x^j||_{2,1} <= t^j 00031 00032 00033 Usage: 00034 [x, t]=ep21R(u, v, n, k); 00035 00036 */ 00037 00038 00039 void ep21R(double * x, double *t, double * u, double * v, int n, int k) 00040 { 00041 int i, j, tn=n*k; 00042 double temp; 00043 00044 /* compute the 2 norm of each group 00045 */ 00046 00047 for(j=0;j<n;j++){ 00048 temp=0; 00049 for(i=j; i< tn; i+=n) 00050 temp+= u[i]* u[i]; 00051 temp=sqrt(temp); 00052 /*temp contains the 2-norm of of each row of u*/ 00053 00054 if(temp > fabs(v[j])){ 00055 t[j]=(temp + v[j])/2; 00056 for (i=j; i<tn; i+=n) 00057 x[i]= t[j] / temp * u[i]; 00058 } 00059 else 00060 if(temp <= v[j]){ 00061 t[j]=v[j]; 00062 00063 for (i=j; i<tn; i+=n) 00064 x[i]= u[i]; 00065 } 00066 else{ 00067 t[j]=0; 00068 00069 for (i=j; i<tn; i+=n) 00070 x[i]=0; 00071 } 00072 00073 } 00074 } 00075 #endif /* ----- #ifndef EP21R_SLEP ----- */ 00076