eppVectorR.h

Go to the documentation of this file.
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  EPPVECTORR_SLEP
00018 #define  EPPVECTORR_SLEP
00019 
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <time.h>
00023 #include <math.h>
00024 
00025 /*
00026    min  1/2 ( ||x- u||_2^2 + ||t-v||_2^2 )
00027    s.t.  ||x_j||_2 <= t_j
00028  
00029  */
00030 
00031 void eppVectorR(double *x, double * t, double * u, double * v, double * ind, int n, int k){
00032     int i, j;
00033     double temp;
00034 
00035     /* compute the 2 norm of each group
00036     */
00037 
00038     for(j=0;j<k;j++){
00039         temp=0;
00040         for(i=(int) (ind[j]); i< (int) (ind[j+1]); i++)
00041             temp+= u[i]* u[i];
00042         temp=sqrt(temp);
00043         /*temp contains the 2-norm of of each row of u*/
00044 
00045         if(temp > fabs(v[j])){
00046            t[j]=(temp + v[j])/2;
00047            
00048            for(i=(int) (ind[j]); i< (int) (ind[j+1]); i++)
00049                x[i]= t[j] / temp * u[i];
00050         }
00051         else
00052            if(temp <= v[j]){
00053                t[j]=v[j];
00054                 
00055                for(i=(int) (ind[j]); i< (int) (ind[j+1]); i++)
00056                    x[i]= u[i];
00057             }
00058             else{
00059                 t[j]=0;
00060                 
00061                for(i=(int) (ind[j]); i< (int) (ind[j+1]); i++)
00062                    x[i]=0;
00063             }
00064               
00065     }    
00066 }
00067 #endif   /* ----- #ifndef EPPVECTORR_SLEP  ----- */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation