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 various data points in a much higher dimensional space by creating an equivalent in a 2-dimensional space.
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 various data points in a much higher dimensional space by creating an equivalent in a 2-dimensional space.
- Author
- Krishna Vedala
- Warning
- MSVC 2019 compiler generates code that does not execute as expected. However, MinGW, Clang for GCC and Clang for MSVC compilers on windows perform as expected. Any insights and suggestions should be directed to the author.
- See also
- kohonen_som_trace.c
@@ -223,13 +221,82 @@ int
Returnstime difference in seconds
-
- 665 return ( double)(end_t - start_t) / ( double)CLOCKS_PER_SEC;
-
+
+ 665 return ( double)(end_t - start_t) / ( double)CLOCKS_PER_SEC;
+
-
+
+◆ main()
+
+
+
+
+
+ | int main |
+ ( |
+ int |
+ argc, |
+
+
+ |
+ |
+ char ** |
+ argv |
+
+
+ |
+ ) |
+ | |
+
+
+
+
+ Main function.
+
+
+ 672 printf( "Using OpenMP based parallelization\n");
+
+ 674 printf( "NOT using OpenMP based parallelization\n");
+
+ 676 clock_t start_clk, end_clk;
+
+
+
+
+ 681 printf( "Test 1 completed in %.4g sec\n",
+
+
+
+
+
+ 687 printf( "Test 2 completed in %.4g sec\n",
+
+
+
+
+
+ 693 printf( "Test 3 completed in %.4g sec\n",
+
+
+ 696 printf( "(Note: Calculated times include: writing files to disk.)\n\n");
+
+
+ void test2() Test that creates a random set of points distributed in 4 clusters in 3D space and trains an SOM that... Definition: kohonen_som_topology.c:506
+ void test1() Test that creates a random set of points distributed in four clusters in 2D space and trains an SOM t... Definition: kohonen_som_topology.c:406
+ double get_clock_diff(clock_t start_t, clock_t end_t) Convert clock cycle difference to time in seconds. Definition: kohonen_som_topology.c:663
+ void test3() Test that creates a random set of points distributed in eight clusters in 3D space and trains an SOM ... Definition: kohonen_som_topology.c:609
+
+
+
+
+
+
◆ test1()
@@ -245,61 +312,61 @@ int |
Test that creates a random set of points distributed in four clusters in 2D space and trains an SOM that finds the topological pattern.
-The following CSV files are created to validate the execution: |
Here is the call graph for this function:
-
+
◆ test2()
@@ -333,68 +400,68 @@ Here is the call graph for this function:
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:
+The following CSV files are created to validate the execution:
test2.csv: random test samples points
w21.csv: initial random U-matrix
w22.csv: trained SOM U-matrix
-
-
-
-
-
-
- 513 double **X = ( double **) malloc(N * sizeof( double *));
-
-
-
-
-
-
- 520 W.data = ( double *) malloc(num_out * num_out * features *
-
-
- 523 for ( int i = 0; i < max(num_out, N); i++)
-
-
- 526 X[i] = ( double *) malloc(features * sizeof( double));
-
-
- 529 for ( int k = 0; k < num_out; k++)
-
-
-
-
- 534 for (j = 0; j < features; j++)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 549 for ( int i = 0; i < N; i++) free(X[i]);
-
-
-
+
+
+
+
+
+
+ 513 double **X = ( double **) malloc(N * sizeof( double *));
+
+
+
+
+
+
+ 520 W.data = ( double *) malloc(num_out * num_out * features *
+
+
+ 523 for ( int i = 0; i < max(num_out, N); i++)
+
+
+ 526 X[i] = ( double *) malloc(features * sizeof( double));
+
+
+ 529 for ( int k = 0; k < num_out; k++)
+
+
+
+
+ 534 for (j = 0; j < features; j++)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 549 for ( int i = 0; i < N; i++) free(X[i]);
+
+
+
void test_3d_classes1(double *const *data, int N) Creates a random set of points distributed in four clusters in 3D space with centroids at the points. Definition: kohonen_som_topology.c:465
-
+
◆ test3()
@@ -410,67 +477,67 @@ Here is the call graph for this function:
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:
+The following CSV files are created to validate the execution:
test3.csv: random test samples points
w31.csv: initial random U-matrix
w32.csv: trained SOM U-matrix
-
-
-
-
- 614 double **X = ( double **) malloc(N * sizeof( double *));
-
-
-
-
-
-
- 621 W.data = ( double *) malloc(num_out * num_out * features *
-
-
- 624 for ( int i = 0; i < max(num_out, N); i++)
-
-
- 627 X[i] = ( double *) malloc(features * sizeof( double));
-
-
- 630 for ( int k = 0; k < num_out; k++)
-
-
-
-
-
- 636 for (j = 0; j < features; j++)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 651 for ( int i = 0; i < N; i++) free(X[i]);
-
-
-
+
+
+
+
+ 614 double **X = ( double **) malloc(N * sizeof( double *));
+
+
+
+
+
+
+ 621 W.data = ( double *) malloc(num_out * num_out * features *
+
+
+ 624 for ( int i = 0; i < max(num_out, N); i++)
+
+
+ 627 X[i] = ( double *) malloc(features * sizeof( double));
+
+
+ 630 for ( int k = 0; k < num_out; k++)
+
+
+
+
+
+ 636 for (j = 0; j < features; j++)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 651 for ( int i = 0; i < N; i++) free(X[i]);
+
+
+
void test_3d_classes2(double *const *data, int N) Creates a random set of points distributed in four clusters in 3D space with centroids at the points. Definition: kohonen_som_topology.c:564
-
+
◆ test_2d_classes()
@@ -510,47 +577,47 @@ Here is the call graph for this function:
|