TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Kohonen self organizing map (data tracing) More...
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iostream>
#include <valarray>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | machine_learning |
A* search algorithm | |
Functions | |
double | _random (double a, double b) |
int | save_nd_data (const char *fname, const std::vector< std::valarray< double > > &X) |
void | machine_learning::update_weights (const std::valarray< double > &x, std::vector< std::valarray< double > > *W, std::valarray< double > *D, double alpha, int R) |
void | machine_learning::kohonen_som_tracer (const std::vector< std::valarray< double > > &X, std::vector< std::valarray< double > > *W, double alpha_min) |
void | test_circle (std::vector< std::valarray< double > > *data) |
void | test1 () |
void | test_lamniscate (std::vector< std::valarray< double > > *data) |
void | test2 () |
void | test_3d_classes (std::vector< std::valarray< double > > *data) |
void | test3 () |
double | get_clock_diff (clock_t start_t, clock_t end_t) |
int | main (int argc, char **argv) |
Kohonen self organizing map (data tracing)
This example implements a powerful self organizing map algorithm. The algorithm creates a connected network of weights that closely follows the given data points. This this creates a chain of nodes that resembles the given input shape.
Definition in file kohonen_som_trace.cpp.
double get_clock_diff | ( | clock_t | start_t, |
clock_t | end_t ) |
Convert clock cycle difference to time in seconds
[in] | start_t | start clock |
[in] | end_t | end clock |
Definition at line 452 of file kohonen_som_trace.cpp.
int main | ( | int | argc, |
char ** | argv ) |
Main function
Definition at line 457 of file kohonen_som_trace.cpp.
void test1 | ( | ) |
Test that creates a random set of points distributed near the circumference of a circle and trains an SOM that finds that circular pattern. The following CSV files are created to validate the execution:
test1.csv
: random test samples points with a circular patternw11.csv
: initial random mapw12.csv
: trained SOM mapThe outputs can be readily plotted in gnuplot using the following snippet
Definition at line 233 of file kohonen_som_trace.cpp.
void test2 | ( | ) |
Test that creates a random set of points distributed near the locus of the Lamniscate of Gerono and trains an SOM that finds that circular pattern. The following CSV files are created to validate the execution:
test2.csv
: random test samples points with a lamniscate patternw21.csv
: initial random mapw22.csv
: trained SOM mapThe outputs can be readily plotted in gnuplot using the following snippet
Definition at line 315 of file kohonen_som_trace.cpp.
void test3 | ( | ) |
Test that creates a random set of points distributed in six clusters in 3D space. The following CSV files are created to validate the execution:
test3.csv
: random test samples points with a circular patternw31.csv
: initial random mapw32.csv
: trained SOM mapThe outputs can be readily plotted in gnuplot using the following snippet
Definition at line 414 of file kohonen_som_trace.cpp.
void test_3d_classes | ( | std::vector< std::valarray< double > > * | data | ) |
Creates a random set of points distributed in six clusters in 3D space with centroids at the points
[out] | data | matrix to store data in |
Definition at line 359 of file kohonen_som_trace.cpp.
void test_circle | ( | std::vector< std::valarray< double > > * | data | ) |
Creates a random set of points distributed near the circumference of a circle and trains an SOM that finds that circular pattern. The generating function is
\begin{eqnarray*} r &\in& [1-\delta r, 1+\delta r)\\ \theta &\in& [0, 2\pi)\\ x &=& r\cos\theta\\ y &=& r\sin\theta \end{eqnarray*}
[out] | data | matrix to store data in |
Definition at line 196 of file kohonen_som_trace.cpp.
void test_lamniscate | ( | std::vector< std::valarray< double > > * | data | ) |
Creates a random set of points distributed near the locus of the Lamniscate of Gerono.
\begin{eqnarray*} \delta r &=& 0.2\\ \delta x &\in& [-\delta r, \delta r)\\ \delta y &\in& [-\delta r, \delta r)\\ \theta &\in& [0, \pi)\\ x &=& \delta x + \cos\theta\\ y &=& \delta y + \frac{\sin(2\theta)}{2} \end{eqnarray*}
[out] | data | matrix to store data in |
Definition at line 277 of file kohonen_som_trace.cpp.