update ML documentation and add grouping

This commit is contained in:
Krishna Vedala 2020-07-02 20:09:49 -04:00
parent b33bd37623
commit b863518ceb
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
3 changed files with 23 additions and 13 deletions

View File

@ -2,9 +2,7 @@
* \file
* \brief [Adaptive Linear Neuron
* (ADALINE)](https://en.wikipedia.org/wiki/ADALINE) implementation
*
* \author [Krishna Vedala](https://github.com/kvedala)
*
* \details
* <img
* src="https://upload.wikimedia.org/wikipedia/commons/b/be/Adaline_flow_chart.gif"
* width="200px">
@ -20,6 +18,7 @@
* computed. Computing the \f$w_j\f$ is a supervised learning algorithm wherein
* a set of features and their corresponding outputs are given and weights are
* computed using stochastic gradient descent method.
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <assert.h>

View File

@ -1,6 +1,5 @@
/**
* \file
* \author [Krishna Vedala](https://github.com/kvedala)
* \brief [Kohonen self organizing
* map](https://en.wikipedia.org/wiki/Self-organizing_map) (topological map)
*
@ -13,6 +12,7 @@
* <img alt="Trained topological maps for the test cases in the program"
* src="https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/machine_learning/kohonen/2D_Kohonen_SOM.svg"
* />
* \author [Krishna Vedala](https://github.com/kvedala)
* \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.

View File

@ -3,13 +3,12 @@
* \brief [Kohonen self organizing
* map](https://en.wikipedia.org/wiki/Self-organizing_map) (data tracing)
*
* \author [Krishna Vedala](https://github.com/kvedala)
*
* \details
* This example implements a powerful self organizing map algorithm.
* The algorithm creates a connected network of weights that closely
* follows the given data points. This this creates a chain of nodes that
* resembles the given input shape.
* \author [Krishna Vedala](https://github.com/kvedala)
* \see kohonen_som_topology.c
*/
#define _USE_MATH_DEFINES /**< required for MS Visual C */
@ -21,6 +20,13 @@
#include <omp.h>
#endif
/**
* @addtogroup machine_learning Machine learning algorithms
* @{
* @addtogroup kohonen_1d Kohonen SOM trace/chain algorithm
* @{
*/
#ifndef max
/** shorthand for maximum value */
#define max(a, b) (((a) > (b)) ? (a) : (b))
@ -95,7 +101,7 @@ int save_nd_data(const char *fname, double **X, int num_points,
* \param[out] val minimum value found
* \param[out] idx index where minimum value was found
*/
void get_min_1d(double const *X, int N, double *val, int *idx)
void kohonen_get_min_1d(double const *X, int N, double *val, int *idx)
{
val[0] = INFINITY; // initial min value
@ -120,8 +126,8 @@ void get_min_1d(double const *X, int N, double *val, int *idx)
* \param[in] alpha learning rate \f$0<\alpha\le1\f$
* \param[in] R neighborhood range
*/
void update_weights(double const *x, double *const *W, double *D, int num_out,
int num_features, double alpha, int R)
void kohonen_update_weights(double const *x, double *const *W, double *D,
int num_out, int num_features, double alpha, int R)
{
int j, k;
@ -138,11 +144,11 @@ void update_weights(double const *x, double *const *W, double *D, int num_out,
D[j] += (W[j][k] - x[k]) * (W[j][k] - x[k]);
}
// step 2: get closest node i.e., node with snallest Euclidian distance to
// step 2: get closest node i.e., node with smallest Euclidian distance to
// the current pattern
int d_min_idx;
double d_min;
get_min_1d(D, num_out, &d_min, &d_min_idx);
kohonen_get_min_1d(D, num_out, &d_min, &d_min_idx);
// step 3a: get the neighborhood range
int from_node = max(0, d_min_idx - R);
@ -177,7 +183,7 @@ void kohonen_som_tracer(double **X, double *const *W, int num_samples,
double alpha = 1.f;
double *D = (double *)malloc(num_out * sizeof(double));
// Loop alpha from 1 to slpha_min
// Loop alpha from 1 to alpha_min
for (; alpha > alpha_min; alpha -= 0.01, iter++)
{
// Loop for each sample pattern in the data set
@ -185,7 +191,7 @@ void kohonen_som_tracer(double **X, double *const *W, int num_samples,
{
const double *x = X[sample];
// update weights for the current input pattern sample
update_weights(x, W, D, num_out, num_features, alpha, R);
kohonen_update_weights(x, W, D, num_out, num_features, alpha, R);
}
// every 10th iteration, reduce the neighborhood range
@ -196,6 +202,11 @@ void kohonen_som_tracer(double **X, double *const *W, int num_samples,
free(D);
}
/**
* @}
* @}
*/
/** Creates a random set of points distributed *near* the circumference
* of a circle and trains an SOM that finds that circular pattern. The
* generating function is