## Function to calculate distance matrix in high-dimensional input space but according to neighborhood relationships in 2D output space

### Description

`sDmat` is supposed to calculate distance (measured in high-dimensional input space) to neighbors (defined by based on 2D output space) for each of hexagons/rectangles

### Usage

`sDmat(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

### Value

• `dMat`: a vector with the length of nHex. It stores the distance a hexaon/rectangle is away from its output-space-defined neighbors in high-dimensional input space

### Note

"which_neigh" is defined in output 2D space, but "distMeasure" is defined in high-dimensional input space

### 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:03

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

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.87294660591056

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:03
Runtime in total is: 0 secs

# 3) calculate "median" distances in INPUT space to different neighbors in 2D OUTPUT space
# 3a) using direct neighbors in 2D OUTPUT space
dMat <- sDmat(sMap=sMap, which_neigh=1, distMeasure="median")
# 3b) using no more than 2-topological neighbors in 2D OUTPUT space
# dMat <- sDmat(sMap=sMap, which_neigh=2, distMeasure="median")
```

## Source code

`sDmat.r`

## Source man

`sDmat.Rd` `sDmat.pdf`

`sNeighAny`