SHOGUN
4.1.0
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
optimization
PNormMappingFunction.h
浏览该文件的文档.
1
/*
2
* Copyright (c) The Shogun Machine Learning Toolbox
3
* Written (w) 2015 Wu Lin
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are met:
8
*
9
* 1. Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
*
26
* The views and conclusions contained in the software and documentation are those
27
* of the authors and should not be interpreted as representing official policies,
28
* either expressed or implied, of the Shogun Development Team.
29
*
30
*/
31
32
#ifndef PNORMMAPPINGFUNCTION_H
33
#define PNORMMAPPINGFUNCTION_H
34
#include <
shogun/optimization/MappingFunction.h
>
35
#include <
shogun/mathematics/Math.h
>
36
namespace
shogun
37
{
45
class
PNormMappingFunction
:
public
MappingFunction
46
{
47
public
:
48
PNormMappingFunction
()
49
:
MappingFunction
()
50
{
51
init();
52
}
53
virtual
~PNormMappingFunction
() {}
54
58
virtual
void
set_norm
(
float64_t
p)
59
{
60
if
(p<2.0)
61
{
62
SG_SWARNING
(
"The norm (%f) should not be less than 2.0 and we use p=2.0 in this case\n"
, p);
63
}
64
else
65
m_p
=p;
66
}
67
74
virtual
SGVector<float64_t>
get_dual_variable
(
SGVector<float64_t>
variable)
75
{
76
SGVector<float64_t>
dual_variable(variable.
vlen
);
77
float64_t
q=1.0/(1.0-1.0/
m_p
);
78
projection
(variable, dual_variable, q);
79
return
dual_variable;
80
}
81
88
virtual
void
update_variable
(
SGVector<float64_t>
variable,
SGVector<float64_t>
dual_variable)
89
{
90
projection
(dual_variable, variable,
m_p
);
91
}
92
101
virtual
void
update_context
(
CMinimizerContext
* context)
102
{
103
REQUIRE
(context,
"Contest must not NULL\n"
);
104
}
105
112
virtual
void
load_from_context
(
CMinimizerContext
* context)
113
{
114
REQUIRE
(context,
"Contest must not NULL\n"
);
115
}
116
protected
:
118
float64_t
m_p
;
119
126
virtual
void
projection
(
SGVector<float64_t>
input,
SGVector<float64_t>
output,
float64_t
degree)
127
{
128
REQUIRE
(input.
vlen
==output.
vlen
,
"The lenght (%d) of input and the length (%d) of output are diffent\n"
,
129
input.
vlen
, output.
vlen
);
130
float64_t
scale
=0.0;
131
for
(
index_t
idx=0; idx<input.
vlen
; idx++)
132
{
133
scale +=
CMath::pow
(
CMath::abs
(input[idx]),degree);
134
if
(input[idx] >= 0.0)
135
output[idx]=
CMath::pow
(input[idx],degree-1);
136
else
137
output[idx]=-
CMath::pow
(-input[idx],degree-1);
138
}
139
scale=
CMath::pow
(scale,1.0-2.0/degree);
140
for
(
index_t
idx=0; idx<input.
vlen
; idx++)
141
output[idx]/=scale;
142
}
143
144
private
:
145
void
init()
146
{
147
m_p=2.0;
148
}
149
};
150
151
}
152
153
#endif
shogun::MappingFunction
The base mapping function for mirror descend.
Definition:
MappingFunction.h:41
shogun::PNormMappingFunction::PNormMappingFunction
PNormMappingFunction()
Definition:
PNormMappingFunction.h:48
Math.h
shogun::PNormMappingFunction::update_context
virtual void update_context(CMinimizerContext *context)
Definition:
PNormMappingFunction.h:101
index_t
int32_t index_t
Definition:
common.h:62
shogun::CMinimizerContext
The class is used to serialize and deserialize variables for the optimization framework.
Definition:
MinimizerContext.h:45
shogun::PNormMappingFunction::~PNormMappingFunction
virtual ~PNormMappingFunction()
Definition:
PNormMappingFunction.h:53
SG_SWARNING
#define SG_SWARNING(...)
Definition:
SGIO.h:178
REQUIRE
#define REQUIRE(x,...)
Definition:
SGIO.h:206
shogun::PNormMappingFunction::get_dual_variable
virtual SGVector< float64_t > get_dual_variable(SGVector< float64_t > variable)
Definition:
PNormMappingFunction.h:74
shogun::SGVector::vlen
index_t vlen
Definition:
SGVector.h:494
shogun::SGVector< float64_t >
float64_t
double float64_t
Definition:
common.h:50
MappingFunction.h
shogun::PNormMappingFunction::set_norm
virtual void set_norm(float64_t p)
Definition:
PNormMappingFunction.h:58
shogun::PNormMappingFunction::m_p
float64_t m_p
Definition:
PNormMappingFunction.h:118
shogun
all of classes and functions are contained in the shogun namespace
Definition:
class_list.h:18
shogun::PNormMappingFunction::projection
virtual void projection(SGVector< float64_t > input, SGVector< float64_t > output, float64_t degree)
Definition:
PNormMappingFunction.h:126
shogun::PNormMappingFunction
This implements the P-norm mapping/projection function.
Definition:
PNormMappingFunction.h:45
shogun::PNormMappingFunction::update_variable
virtual void update_variable(SGVector< float64_t > variable, SGVector< float64_t > dual_variable)
Definition:
PNormMappingFunction.h:88
shogun::linalg::scale
void scale(Matrix A, Matrix B, typename Matrix::Scalar alpha)
Definition:
Core.h:93
shogun::PNormMappingFunction::load_from_context
virtual void load_from_context(CMinimizerContext *context)
Definition:
PNormMappingFunction.h:112
shogun::CMath::pow
static int32_t pow(bool x, int32_t n)
Definition:
Math.h:535
shogun::CMath::abs
static T abs(T a)
Definition:
Math.h:179
SHOGUN
机器学习工具包 - 项目文档