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