Algorithms_in_C++
1.0.0
Set of 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>
Namespaces | |
machine_learning | |
Machine learning algorithms. | |
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.
double get_clock_diff | ( | clock_t | start_t, |
clock_t | end_t | ||
) |
int main | ( | int | argc, |
char ** | argv | ||
) |
Main function
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
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
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
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 |
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 |
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 |