Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
examples
Data
Normalization.cpp
Go to the documentation of this file.
1
//===========================================================================
2
/*!
3
*
4
*
5
* \brief Data Normalization
6
*
7
* This file is part of the tutorial "Normalization of Input Data".
8
* By itself, it does not do anything particularly useful.
9
*
10
* \author T. Glasmachers
11
* \date 2014
12
*
13
*
14
* \par Copyright 1995-2017 Shark Development Team
15
*
16
* <BR><HR>
17
* This file is part of Shark.
18
* <https://shark-ml.github.io/Shark/>
19
*
20
* Shark is free software: you can redistribute it and/or modify
21
* it under the terms of the GNU Lesser General Public License as published
22
* by the Free Software Foundation, either version 3 of the License, or
23
* (at your option) any later version.
24
*
25
* Shark is distributed in the hope that it will be useful,
26
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
* GNU Lesser General Public License for more details.
29
*
30
* You should have received a copy of the GNU Lesser General Public License
31
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
32
*
33
*/
34
//===========================================================================
35
36
#include <
shark/Data/Csv.h
>
37
38
#include <
shark/Models/Normalizer.h
>
39
#include <
shark/Algorithms/Trainers/NormalizeComponentsUnitVariance.h
>
40
using namespace
shark
;
41
42
#include <
shark/Models/LinearModel.h
>
43
#include <
shark/Algorithms/Trainers/NormalizeComponentsWhitening.h
>
44
45
int
main
()
46
{
47
// data container
48
UnlabeledData<RealVector>
data;
49
50
// create and train data normalizer
51
bool
removeMean =
true
;
52
Normalizer<RealVector>
normalizer;
53
NormalizeComponentsUnitVariance<RealVector>
normalizingTrainer(removeMean);
54
normalizingTrainer.
train
(normalizer, data);
55
56
// transform data
57
UnlabeledData<RealVector>
normalizedData =
transform
(data, normalizer);
58
59
// create and train data normalizer
60
LinearModel<RealVector>
whitener;
61
NormalizeComponentsWhitening
whiteningTrainer;
62
whiteningTrainer.
train
(whitener, data);
63
64
// transform data
65
UnlabeledData<RealVector>
whitenedData =
transform
(data, whitener);
66
}