SOM Toolbox Online documentation http://www.cis.hut.fi/projects/somtoolbox/

# som_neighborhood

### Purpose

``` Calculate to which neighborhood each map unit belongs to relative to
each other map unit, given the units in 1-neighborhood of each unit.

```

### Syntax

```  Ne = som_neighborhood(Ne1);
Ne = som_neighborhood(Ne1,n);

```

### Description

``` For each map unit, finds the minimum neighborhood to which it belongs
to relative to each other map unit. Or, equivalently, for each map
unit, finds which units form its k-neighborhood, where k goes from
0 to n.

The neighborhood is calculated iteratively using the reflexivity of
neighborhood.
let  N1i  be the 1-neighborhood set a unit i
and let  N11i be the set of units in the 1-neighborhood of any unit j in N1i
then N2i  (the 2-neighborhood set of unit i) is N11i \ N1i

Consider, for example, the case of a 5x5 map. The neighborhood in case of
'rect' and 'hexa' lattices (and 'sheet' shape) for the unit at the
center of the map are depicted below:

'rect' lattice           'hexa' lattice
--------------           --------------
4  3  2  3  4            3  2  2  2  3
3  2  1  2  3             2  1  1  2  3
2  1  0  1  2            2  1  0  1  2
3  2  1  2  3             2  1  1  2  3
4  3  2  3  4            3  2  2  2  3

Because the iterative procedure is rather slow, the neighborhoods
are calculated upto given maximal value. The uncalculated values
in the returned matrix are Inf:s.

```

### Required input arguments

```  Ne1   (matrix) Each row contains 1, if the corresponding unit is adjacent
for that map unit, 0 otherwise. This can be calculated
using SOM_UNIT_NEIGHS. The matrix can be sparse.
Size munits x munits.

```

### Optional input arguments

```  n     (scalar) Maximal neighborhood value which is calculated,
Inf by default (all neighborhoods).

```

### Output arguments

```  Ne    (matrix) neighborhood values for each map unit, size is
[munits, munits]. The matrix contains the minimum
neighborhood of unit i, to which unit j belongs,
or Inf, if the neighborhood was bigger than n.

```

### Examples

```  Ne = som_neighborhood(Ne1,1);    % upto 1-neighborhood
Ne = som_neighborhood(Ne1,Inf);  % all neighborhoods
Ne = som_neighborhood(som_unit_neighs(topol),4);

```