# Common functions

## Winner searching

These functions find the winning codebook entrys (*knn* nearest
neighbours of *sample*) in codebook *codes* using euclidean
distance. Information about the winning entry is saved in the
winner_info structures (*win*) provided by the caller. *Win*
should be an array of *knn* winner_info structures. When
successful the functions return the number of neighbours found which
should be the same as *knn* and 0 when winner could not be found
(for example, all components of data vector have been masked off).
- int
**find_winner_euc**(struct entries **codes*, struct data_entry **sample*, struct winner_info **win*, int *knn*)
- Finds the winning entry (nearest neighbour of
*sample*). This function only finds one best matching unit
and should be called with *knn* as one.

- int
**find_winner_knn**(struct entries **codes*, struct data_entry **sample*, struct winner_info **win*, int *knn*)
- Finds the winning entrys (
*knn* nearest neighbours of
*sample*).

## Vector operations

- float
**vector_dist_euc**(struct data_entry **v1*, struct data_entry **v2*, int *dim*)
- Computes the distance between two vectors
*v1*and *v2*
in euclidean metric. Returns < 0 if distance couldn't be
calculated (all components were masked off). *Dim* is the
dimension of the vectors. Note that the winner searching
functions don't use this function.

- void
**adapt_vector**(struct data_entry **codetmp*, struct data_entry **sample*, int *dim*, float *alpha*)
- Adapts a codebook vector
*codetmp* by moving it towards the
*sample* vector by a small amount
(*alpha*). *Dim* is the dimension of the vectors.

## Alpha functions

These functions return the alpha value for some number of iterations
(*iter*) out of the maximum number of iterations
(*length*). *Alpha* is the initial value when *iter* is
0.
- float
**linear_alpha**(long *iter*, long *length*, float *alpha*)
- Linearly decreasing alpha.

- float
**inverse_t_alpha**(long *iter*, long *length*, float *alpha*)
- Alpha that decreases proportional to the inverse of iterations
done so far.

## Other functions

- int
**global_options**(int *argc*, char ***argv*)
- Handles some options that are common to all programs. Also read
some environment variables. Takes care of the options
*-compress_cmd*, *-uncompress_cmd*, *-mask_str*,
*-version*, *-v* and environment variables
*LVQSOM_COMPRESS_COMMAND*,
*LVQSOM_UNCOMPRESS_COMMAND*, and
*LVQSOM_MASK_STR*. See the package document or the
new features page for more details
about them. This function should be called in the start of all
programs. *Argc* and *argv* are the arguments that
were passed to the *main* function.

**SOM/LVQ Programming info** /
**SOM/LVQ Home Page** /
**Neural Networks Research Centre**