Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Kohonen self organizing map (topological map) More...
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Data Structures | |
struct | kohonen_array_3d |
to store info regarding 3D arrays More... | |
Functions | |
double * | kohonen_data_3d (const struct kohonen_array_3d *arr, int x, int y, int z) |
Function that returns the pointer to (x, y, z) ^th location in the linear 3D array given by: | |
double | _random (double a, double b) |
Helper function to generate a random number in a given interval. | |
int | save_2d_data (const char *fname, double **X, int num_points, int num_features) |
Save a given n-dimensional data martix to file. | |
int | save_u_matrix (const char *fname, struct kohonen_array_3d *W) |
Create the distance matrix or U-matrix from the trained weights and save to disk. | |
void | get_min_2d (double **X, int N, double *val, int *x_idx, int *y_idx) |
Get minimum value and index of the value in a matrix. | |
double | kohonen_update_weights (const double *X, struct kohonen_array_3d *W, double **D, int num_out, int num_features, double alpha, int R) |
Update weights of the SOM using Kohonen algorithm. | |
void | kohonen_som (double **X, struct kohonen_array_3d *W, int num_samples, int num_features, int num_out, double alpha_min) |
Apply incremental algorithm with updating neighborhood and learning rates on all samples in the given datset. | |
void | test_2d_classes (double *const *data, int N) |
Creates a random set of points distributed in four clusters in 3D space with centroids at the points. | |
void | test1 () |
Test that creates a random set of points distributed in four clusters in 2D space and trains an SOM that finds the topological pattern. | |
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. | |
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. | |
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. | |
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. | |
double | get_clock_diff (clock_t start_t, clock_t end_t) |
Convert clock cycle difference to time in seconds. | |
int | main (int argc, char **argv) |
Main function. | |
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.
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 |
int main | ( | int | argc, |
char ** | argv | ||
) |
Main function.
void test1 | ( | ) |
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:
test1.csv
: random test samples points with a circular patternw11.csv
: initial random U-matrixw12.csv
: trained SOM U-matrix 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 pointsw21.csv
: initial random U-matrixw22.csv
: trained SOM U-matrix 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 pointsw31.csv
: initial random U-matrixw32.csv
: trained SOM U-matrix void test_2d_classes | ( | double *const * | data, |
int | N | ||
) |
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 |
[in] | N | number of points required |
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.
[out] | data | matrix to store data in |
[in] | N | number of points required |
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.
[out] | data | matrix to store data in |
[in] | N | number of points required |