TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Kohonen self organizing map (topological map) More...
#include <algorithm>
#include <array>
#include <cerrno>
#include <cmath>
#include <cstdlib>
#include <cstring>
#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_2d_data (const char *fname, const std::vector< std::valarray< double > > &X) |
void | get_min_2d (const std::vector< std::valarray< double > > &X, double *val, int *x_idx, int *y_idx) |
int | machine_learning::save_u_matrix (const char *fname, const std::vector< std::vector< std::valarray< double > > > &W) |
double | machine_learning::update_weights (const std::valarray< double > &X, std::vector< std::vector< std::valarray< double > > > *W, std::vector< std::valarray< double > > *D, double alpha, int R) |
void | machine_learning::kohonen_som (const std::vector< std::valarray< double > > &X, std::vector< std::vector< std::valarray< double > > > *W, double alpha_min) |
void | test_2d_classes (std::vector< std::valarray< double > > *data) |
void | test1 () |
void | test_3d_classes1 (std::vector< std::valarray< double > > *data) |
void | test2 () |
void | test_3d_classes2 (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) |
Variables | |
constexpr double | machine_learning::MIN_DISTANCE = 1e-4 |
Kohonen self organizing map (topological map)
This example implements a powerful unsupervised learning algorithm called as a self organizing map. The algorithm creates a connected network of weights that closely follows the given data points. This thus creates a topological map of the given data i.e., it maintains the relationship between varipus data points in a much higher dimesional space by creating an equivalent in a 2-dimensional space.
Definition in file kohonen_som_topology.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 577 of file kohonen_som_topology.cpp.
int main | ( | int | argc, |
char ** | argv ) |
Main function
Definition at line 582 of file kohonen_som_topology.cpp.
void test1 | ( | ) |
Test that creates a random set of points distributed in four clusters in 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 map Definition at line 369 of file kohonen_som_topology.cpp.
void test2 | ( | ) |
Test that creates a random set of points distributed in 4 clusters in 3D space and trains an SOM that finds the topological 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 map Definition at line 451 of file kohonen_som_topology.cpp.
void test3 | ( | ) |
Test that creates a random set of points distributed in eight clusters in 3D space and trains an SOM that finds the topological pattern. 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 map Definition at line 537 of file kohonen_som_topology.cpp.
void test_2d_classes | ( | std::vector< std::valarray< double > > * | data | ) |
Creates a random set of points distributed in four clusters in 3D space with centroids at the points
[out] | data | matrix to store data in |
Definition at line 330 of file kohonen_som_topology.cpp.
void test_3d_classes1 | ( | std::vector< std::valarray< double > > * | data | ) |
Creates a random set of points distributed in four clusters in 3D space with centroids at the points
[out] | data | matrix to store data in |
Definition at line 411 of file kohonen_som_topology.cpp.
void test_3d_classes2 | ( | std::vector< std::valarray< double > > * | data | ) |
Creates a random set of points distributed in four clusters in 3D space with centroids at the points
[out] | data | matrix to store data in |
Definition at line 493 of file kohonen_som_topology.cpp.