1 /*
2  * Copyright (C) 2018 Emeric Poupon
3  *
4  * This file is part of LMS.
5  *
6  * LMS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * LMS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with LMS.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include <vector>
23 #include <ostream>
24 
25 #include "Network.hpp"
26 
27 namespace SOM
28 {
29 
30 class DataNormalizer
31 {
32 	public:
33 
34 		struct MinMax
35 		{
36 			InputVector::value_type min;
37 			InputVector::value_type max;
38 		};
39 
40 		DataNormalizer(std::size_t inputDimCount);
41 
getInputDimCount() const42 		std::size_t getInputDimCount() const { return _inputDimCount; }
43 		const MinMax& getValue(std::size_t index) const;
44 
45 		void setValue(std::size_t index, const MinMax& minMax);
46 
47 		void computeNormalizationFactors(const std::vector<InputVector>& dataSamples);
48 
49 		void normalizeData(InputVector& data) const;
50 
51 		void dump(std::ostream& os) const;
52 
53 	private:
54 		InputVector::value_type normalizeValue(InputVector::value_type value, std::size_t dimensionId) const;
55 
56 		const std::size_t _inputDimCount;
57 
58 		std::vector<MinMax> _minmax; // Indexed min/max used to normalize data
59 };
60 
61 } // namespace SOM
62