|
Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Data Structures | |
| struct | kohonen_array_3d |
| to store info regarding 3D arrays More... | |
Macros | |
| #define | max(a, b) (((a) > (b)) ? (a) : (b)) |
| shorthand for maximum value | |
| #define | min(a, b) (((a) < (b)) ? (a) : (b)) |
| shorthand for minimum value | |
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. | |
| double _random | ( | double | a, |
| double | b | ||
| ) |
Helper function to generate a random number in a given interval.
Steps:
r1 = rand() % 100 gets a random number between 0 and 99r2 = r1 / 100 converts random number to be between 0 and 0.99\[ y = (b - a) \times \frac{\text{(random number between 0 and RAND_MAX)} \; \text{mod}\; 100}{100} + a \]
| [in] | a | lower limit |
| [in] | b | upper limit |
| 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.
| [in] | X | matrix to search |
| [in] | N | number of points in the vector |
| [out] | val | minimum value found |
| [out] | x_idx | x-index where minimum value was found |
| [out] | y_idx | y-index where minimum value was found |
| 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:
\[ X_{i,j,k} = i\times M\times N + j\times N + k \]
where \(L\), \(M\) and \(N\) are the 3D matrix dimensions.
| [in] | arr | pointer to kohonen_array_3d structure |
| [in] | x | first index |
| [in] | y | second index |
| [in] | z | third index |
| 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.
| [in] | X | data set |
| [in,out] | W | weights matrix |
| [in] | num_samples | number of output points |
| [in] | num_features | number of features per input sample |
| [in] | num_out | number of output points |
| [in] | alpha_min | terminal value of alpha |
| 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.
| [in] | X | data point |
| [in,out] | W | weights matrix |
| [in,out] | D | temporary vector to store distances |
| [in] | num_out | number of output points |
| [in] | num_features | number of features per input sample |
| [in] | alpha | learning rate \(0<\alpha\le1\) |
| [in] | R | neighborhood range |
| int save_2d_data | ( | const char * | fname, |
| double ** | X, | ||
| int | num_points, | ||
| int | num_features | ||
| ) |
Save a given n-dimensional data martix to file.
| [in] | fname | filename to save in (gets overwritten without confirmation) |
| [in] | X | matrix to save |
| [in] | num_points | rows in the matrix = number of points |
| [in] | num_features | columns in the matrix = dimensions of points |
| 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.
| [in] | fname | filename to save in (gets overwriten without confirmation) |
| [in] | W | model matrix to save |