Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
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 | _random (double a, double b) |
Helper function to generate a random number in a given interval. | |
int | save_nd_data (const char *fname, double **X, int num_points, int num_features) |
Save a given n-dimensional data martix to file. | |
void | kohonen_get_min_1d (double const *X, int N, double *val, int *idx) |
Get minimum value and index of the value in a vector. | |
void | kohonen_update_weights (double const *x, double *const *W, double *D, int num_out, int num_features, double alpha, int R) |
Update weights of the SOM using Kohonen algorithm. | |
void | kohonen_som_tracer (double **X, double *const *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 \]
a | lower limit |
b | upper limit |
void kohonen_get_min_1d | ( | double const * | X, |
int | N, | ||
double * | val, | ||
int * | idx | ||
) |
Get minimum value and index of the value in a vector.
[in] | X | vector to search |
[in] | N | number of points in the vector |
[out] | val | minimum value found |
[out] | idx | index where minimum value was found |
void kohonen_som_tracer | ( | double ** | X, |
double *const * | 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 |
void kohonen_update_weights | ( | double const * | x, |
double *const * | 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_nd_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 overwriten 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 |