SHOGUN
6.0.0
src
shogun
lib
slep
q1
ep1R.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
18
#ifndef EP1R_SLEP
19
#define EP1R_SLEP
20
21
#include <shogun/lib/config.h>
22
#ifdef USE_GPL_SHOGUN
23
24
#include <stdlib.h>
25
#include <stdio.h>
26
#include <time.h>
27
#include <math.h>
28
29
30
/*
31
Euclidean Projection onto l_{2,1} Ball
32
33
min 1/2 ||x- u||_2^2 + 1/2 ||t- v||_2^2
34
s.t. |x|<=t
35
36
37
Usage:
38
[x, t]=ep1R(u, v, n);
39
40
*/
41
42
43
void
ep1R(
double
* x,
double
*t,
double
* u,
double
* v,
int
n)
44
{
45
int
j;
46
47
48
for
(j=0;j<n;j++){
49
50
if
(fabs(u[j]) > fabs(v[j])){
51
t[j]=(fabs(u[j]) + v[j])/2;
52
53
if
(u[j] >0)
54
x[j]=t[j];
55
else
56
x[j]=-t[j];
57
}
58
else
59
if
(fabs(u[j]) <= v[j]){
60
t[j]=v[j];
61
x[j]=u[j];
62
}
63
else
{
64
t[j]=x[j]=0;
65
}
66
67
}
68
}
69
#endif //USE_GPL_SHOGUN
70
#endif
/* ----- #ifndef EP1R_SLEP ----- */
71
SHOGUN
Machine Learning Toolbox - Documentation