Shark machine learning library
About Shark
News!
Contribute
Credits and copyright
Downloads
Getting Started
Installation
Using the docs
Documentation
Tutorials
Quick references
Class list
Global functions
FAQ
Showroom
include
shark
Models
LinearNorm.h
Go to the documentation of this file.
1
/*!
2
* \brief Implements the linear norm class
3
*
4
* \author O. Krause
5
* \date 2012
6
*
7
*
8
* \par Copyright 1995-2017 Shark Development Team
9
*
10
* <BR><HR>
11
* This file is part of Shark.
12
* <http://shark-ml.org/>
13
*
14
* Shark is free software: you can redistribute it and/or modify
15
* it under the terms of the GNU Lesser General Public License as published
16
* by the Free Software Foundation, either version 3 of the License, or
17
* (at your option) any later version.
18
*
19
* Shark is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU Lesser General Public License for more details.
23
*
24
* You should have received a copy of the GNU Lesser General Public License
25
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
26
*
27
*/
28
#ifndef SHARK_ML_MODEL_LINEAR_NORM_H
29
#define SHARK_ML_MODEL_LINEAR_NORM_H
30
31
#include <
shark/Core/DLLSupport.h
>
32
#include <
shark/Models/AbstractModel.h
>
33
namespace
shark
{
34
/*!
35
* \brief Normalizes the (non-negative) input by dividing by the overall sum.
36
*/
37
class
LinearNorm
:
public
AbstractModel
<RealVector,RealVector>
38
{
39
private
:
40
struct
InternalState:
public
State
{
41
RealVector norm;
42
43
void
resize(std::size_t patterns){
44
norm.resize(patterns);
45
}
46
};
47
public
:
48
SHARK_EXPORT_SYMBOL
LinearNorm
();
49
SHARK_EXPORT_SYMBOL
LinearNorm
(std::size_t
inputSize
);
50
51
/// \brief From INameable: return the class name.
52
std::string
name
()
const
53
{
return
"Linear Norm"
; }
54
55
RealVector
parameterVector
()
const
{
56
return
RealVector();
57
}
58
void
setParameterVector
(RealVector
const
& newParameters){}
59
60
std::size_t
inputSize
()
const
{
61
return
m_inputSize
;
62
}
63
std::size_t
outputSize
()
const
{
64
return
m_inputSize
;
65
}
66
std::size_t
numberOfParameters
()
const
{
67
return
0;
68
}
69
70
void
setStructure
(std::size_t
inputDimension
){
71
m_inputSize
=
inputDimension
;
72
}
73
74
boost::shared_ptr<State>
createState
()
const
{
75
return
boost::shared_ptr<State>(
new
InternalState());
76
}
77
78
using
AbstractModel<RealVector,RealVector>::eval
;
79
SHARK_EXPORT_SYMBOL
void
eval
(
BatchInputType
const
& patterns,
BatchOutputType
& output)
const
;
80
SHARK_EXPORT_SYMBOL
void
eval
(
BatchInputType
const
& patterns,
BatchOutputType
& output,
State
& state)
const
;
81
82
void
weightedParameterDerivative
(
83
BatchInputType
const
& patterns,
BatchOutputType
const
& coefficients,
State
const
& state, RealVector& gradient
84
)
const
{
85
SIZE_CHECK
(patterns.size1()==coefficients.size1());
86
gradient.resize(0);
87
}
88
SHARK_EXPORT_SYMBOL
void
weightedInputDerivative
(
89
BatchInputType
const
& pattern,
BatchOutputType
const
& coefficients,
State
const
& state,
BatchOutputType
& gradient
90
)
const
;
91
92
/// From ISerializable, reads a model from an archive
93
SHARK_EXPORT_SYMBOL
void
read
(
InArchive
& archive );
94
95
/// From ISerializable, writes a model to an archive
96
SHARK_EXPORT_SYMBOL
void
write
(
OutArchive
& archive )
const
;
97
98
protected
:
99
std::size_t
m_inputSize
;
100
};
101
102
}
103
#endif