Mike - 1 month ago 10

Python Question

I am looking for **hexagonal** self-organizing map on Python.

- ready module. If one exists.
- way to plot hexagonal cell
- algorithms to work with hexagonal cells as array or smth else

A self-organizing map (SOM) or self-organizing feature map (SOFM) is a type of artificial neural network that is trained using unsupervised learning to produce a low-dimensional (typically two-dimensional)

Answer

I don't have an answer for point 1, but some hints for point 2 and 3. In your context, you're not modelling a physical 2D space but a conceptual space with tiles that have 6 neighbors. This can be modelled with square tiles arranged in columns with the odd colums shifted vertically by half the size of a square. I'll try an ASCII diagram:

```
___ ___ ___
| |___| |___| |___
|___| |___| |___| |
| |___| |___| |___|
|___| |___| |___| |
| |___| |___| |___|
|___| |___| |___| |
|___| |___| |___|
```

You can see easily that each square has 6 neighbors (except the ones on the edges of course). This gets easily modeled as a 2D array of squares, and the rules to compute the coordinates of the square at at position (i, j), i being the row and j the column are quite simple:

if j is even:

```
(i+1, j), (i-1, j), (i, j-1), (i, j+1), (i-1, j-1), (i+1, j-1)
```

if j is odd:

```
(i+1, j), (i-1, j), (i, j-1), (i, j+1), (i+1, j-1), (i+1, j+1)
```

(the 4 first terms are identical)