Topologies

City topology

In the City topology distance is calculated as sum of the distances for every value. On picture below is shown the neighborhood with radius 1.
City topology
In the code can be define as:
neural_net::City_topology < size_t > city_top();

Maximum topology

In the Maximum topology distance is calculated as maximum of the distances for every value. On picture below is shown the neighborhood with radius 1.
Maximum topology
In the code can be define as:
neural_net::Max_topology < size_t > max_top();

Hexagonal topology

In the Hexagonal topology distance is calculated in the way shown below,
index_1_1 - is row number of the first neuron,
index_1_2 - is column number of the first neuron,
index_1_1 - is row number of the first neuron,
index_1_2 - is column number of the first neuron,
hex_offset - is a integer number - its optimal value can be set as number of rows in neural network (matrix).
// recalculate indexes to the better indexes used in hexagonal space
hex_index_1_1 = ( index_1_1 + 1 ) / 2 + index_1_2;
hex_index_1_2 = ( hex_offset / 2 + index_1_2 ) - index_1_1 / 2;

hex_index_2_1 = ( index_2_1 + 1 ) / 2 + index_2_2;
hex_index_2_2 = ( hex_offset / 2 + index_2_2 ) - index_2_1 / 2;

// calculate difference between points in hexagonal space
tmp_hex_index_1 = std::max ( hex_index_1_1, hex_index_2_1 )
                 - std::min ( hex_index_1_1, hex_index_2_1 );
tmp_hex_index_2 = std::max ( hex_index_1_2, hex_index_2_2 )
                 - std::min ( hex_index_1_2, hex_index_2_2 );

// here we have special algebra to calculate distance,
// bacause of special basis in this space:
// ( 1, 1 ); ( -1, -1 ) have distance 1 the same as
// ( -1, 0 ); ( 0, -1 ); ( 1, 0 ); ( 0, 1 ).
if ( tmp_hex_index_1 == 0 && tmp_hex_index_2 == 0 )
{
  return 0;
}

// check if values have the same direction
// if yes it means that we have to use
// reasoning based on assumption
// that ( -1, -1 ) and ( 1, 1 ) have distance 1.
if ( ( ( hex_index_1_1 > hex_index_2_1 )
        && ( hex_index_1_2 > hex_index_2_2 ) )
    || ( ( hex_index_1_1 < hex_index_2_1 )
        && ( hex_index_1_2 < hex_index_2_2 ) )
)
{
  return max ( tmp_hex_index_1, tmp_hex_index_2 );
}
else
{
  return abs ( tmp_hex_index_1 ) + abs ( tmp_hex_index_2 );
}
On picture below is shown the neighborhood with radius 1.
Hexagonal topology
In the code can be define as below, but with respect that there is no default constructor.
typedef neural_net::Hexagonal_topology < size_t > Hex_top;
Hex_top hex_top ( kohonen_network.get_no_rows() );
Valid HTML 4.01 Transitional Valid CSS!