Search code examples
matlabneural-networkself-organizing-maps

Get hextop self-organizing map neuron connections


How do I get a n-by-2 vector that contains the connections of the neurons in an SOM? For example, if I have a simple 2x2 hextop SOM, the connections vector should look like:

[ 1 2 1 3 1 4 ]

This vector indicates that the neuron 1 is connected to neuron 2, neuron 1 is connected to neuron 3, etc.

How can this connections vector be retrieved from any given SOM?


Solution

  • Assuming the SOM is defined with neighbourhood distance 1 (i.e., for each neuron, edges to all neurons within an Euclidian distance of 1), the default option for Matlabs hextop(...) command, you can create your connections vector as follows:

    pos = hextop(2,2);
    
    % Find neurons within a Euclidean distance of 1, for each neuron.
    
    % option A: count edges only once
    distMat = triu(dist(pos));
    [I, J] = find(distMat > 0 & distMat <= 1);
    connectionsVectorA = [I J]
    
    % option B: count edges in both directions
    distMat = dist(pos);
    [I, J] = find(distMat > 0 & distMat <= 1);
    connectionsVectorB = sortrows([I J])
    
    % verify graphically
    plotsom(pos)
    

    The output from the above follows:

    connectionsVectorA =
    
         1     2
         1     3
         2     3
         2     4
         3     4
    
    
    connectionsVectorB =
    
         1     2
         1     3
         2     1
         2     3
         2     4
         3     1
         3     2
         3     4
         4     2
         4     3
    

    If you have a SOM with a non-default neighbourhood distance (!= 1), say nDist, just replace the find(..) commands above with

    ... find(distMat > 0 & distMat <= nDist);