## Function to identify local minima (in 2D output space) of distance matrix (in high-dimensional input space)

### Description

`sDmatMinima` is supposed to identify local minima of distance matrix (resulting from `sDmat`). The criterion of being local minima is that the distance associated with a hexagon/rectangle is always smaller than its direct neighbors (i.e., 1-neighborhood)

### Usage

`sDmatMinima(sMap, which_neigh = 1, distMeasure = c("median", "mean", "min", "max"))`

### Arguments

sMap
an object of class "sMap"
which_neigh
which neighbors in 2D output space are used for the calculation. By default, it sets to "1" for direct neighbors, and "2" for neighbors within neighbors no more than 2, and so on
distMeasure
distance measure used to calculate distances in high-dimensional input space. It can be one of "median", "mean", "min" and "max" measures

### Value

• `minima`: a vector to store a list of local minima (represented by the indexes of hexogans/rectangles

### Note

Do not get confused by "which_neigh" and the criteria of being local minima. Both of them deal with 2D output space. However, "which_neigh" is used to assist in the calculation of distance matrix (so can be 1-neighborhood or more); instead, the criterion of being local minima is only 1-neighborhood in the strictest sense

### Examples

```# 1) generate an iid normal random matrix of 100x10
data <- matrix( rnorm(100*10,mean=0,sd=1), nrow=100, ncol=10)

# 2) get trained using by default setup
sMap <- sPipeline(data=data)

Start at 2018-01-18 16:56:05

First, define topology of a map grid (2018-01-18 16:56:05)...
Second, initialise the codebook matrix (61 X 10) using 'linear' initialisation, given a topology and input data (2018-01-18 16:56:05)...
Third, get training at the rough stage (2018-01-18 16:56:05)...
1 out of 7 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
2 out of 7 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
3 out of 7 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
4 out of 7 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
5 out of 7 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
6 out of 7 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
7 out of 7 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
Fourth, get training at the finetune stage (2018-01-18 16:56:05)...
1 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
2 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
3 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
4 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
5 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
6 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
7 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
8 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
9 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
10 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
11 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
12 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
13 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
14 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
15 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
16 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
17 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
18 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
19 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
20 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
21 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
22 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
23 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
24 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
25 out of 25 (2018-01-18 16:56:05)
updated (2018-01-18 16:56:05)
Next, identify the best-matching hexagon/rectangle for the input data (2018-01-18 16:56:05)...
Finally, append the response data (hits and mqe) into the sMap object (2018-01-18 16:56:05)...

Below are the summaries of the training results:
dimension of input data: 100x10
xy-dimension of map grid: xdim=9, ydim=9, r=5
grid lattice: hexa
grid shape: suprahex
dimension of grid coord: 61x2
initialisation method: linear
dimension of codebook matrix: 61x10
mean quantization error: 4.9630432442287

Below are the details of trainology:
training algorithm: batch
alpha type: invert
training neighborhood kernel: gaussian
trainlength (x input data length): 7 at rough stage; 25 at finetune stage
radius (at rough stage): from 3 to 1
radius (at finetune stage): from 1 to 1

End at 2018-01-18 16:56:05
Runtime in total is: 0 secs

# 3) identify local minima of distance matrix based on "median" distances and direct neighbors
minima <- sDmatMinima(sMap=sMap, which_neigh=1, distMeasure="median")
```

## Source code

`sDmatMinima.r`

## Source man

`sDmatMinima.Rd` `sDmatMinima.pdf`

`sDmat`, `sNeighAny`