openGPMP
Open Source Mathematics Package
kohonen_net.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file. As this is an Open Source effort, all implementations
25  * must be of the same methodology.
26  *
27  *
28  *
29  * This software is distributed on an AS IS basis, WITHOUT
30  * WARRANTY OF ANY KIND, either express or implied.
31  *
32  ************************************************************************/
33 
39 #ifndef KOHONEN_NETWORK_HPP
40 #define KOHONEN_NETWORK_HPP
41 #include <vector>
42 
43 namespace gpmp {
44 
45 namespace ml {
46 
52 class KohonenNet {
53  public:
59  KohonenNet(int inputSize, int mapSize);
60 
64  ~KohonenNet();
70  void train(const std::vector<std::vector<double>> &inputData,
71  int epochs = 1000);
72 
79  int classify(const std::vector<double> &inputVector);
80 
81  private:
82  int input_size;
83  int map_size;
84  std::vector<std::vector<double>>
90  void initialize_weights();
91 
98  int best_matching_unit(const std::vector<double> &input_vector);
99 
107  void update_weights(int bmu,
108  const std::vector<double> &input_vector,
109  double learning_rate);
110 
117  double euclidean_distance(const std::vector<double> &vec1,
118  const std::vector<double> &vec2);
119 };
120 
121 } // namespace ml
122 
123 } // namespace gpmp
124 
125 #endif
Kohonen Neural Network Cluster Class.
Definition: kohonen_net.hpp:52
KohonenNet(int inputSize, int mapSize)
Constructor for the KohonenNet class.
Definition: kohonen_net.cpp:38
void update_weights(int bmu, const std::vector< double > &input_vector, double learning_rate)
Updates the weights of the Kohonen network based on the best matching unit and input vector.
Definition: kohonen_net.cpp:90
~KohonenNet()
Destructor for the KohonenNet class.
Definition: kohonen_net.cpp:43
int classify(const std::vector< double > &inputVector)
Classifies a given input vector and returns the index of the best matching unit.
Definition: kohonen_net.cpp:70
void initialize_weights()
Initializes the weights of the Kohonen network.
Definition: kohonen_net.cpp:46
double euclidean_distance(const std::vector< double > &vec1, const std::vector< double > &vec2)
Calculates the Euclidean distance between two vectors.
std::vector< std::vector< double > > weights
Definition: kohonen_net.hpp:85
void train(const std::vector< std::vector< double >> &inputData, int epochs=1000)
Trains the Kohonen network using input data.
Definition: kohonen_net.cpp:58
int best_matching_unit(const std::vector< double > &input_vector)
Finds the index of the best matching unit (BMU) for a given input vector.
Definition: kohonen_net.cpp:74
The source C++ openGPMP namespace.