som/basic_som.py
def distance_map(self):
        """Shows a plot of how far the vector of a node is from its
        neighbours. A warmer color means it's further away.
        """
        distances = []
        for row, nodes in enumerate(self.codebook.data):
            distance_row = []
            for col, node in enumerate(nodes):
                node_distances = []
                for drow, dcol in ((-1, 0), (1, 0), (0, -1), (0, 1)):
                    if (row + drow < 0 or row + drow >= len(self.codebook) or
                            col + dcol < 0 or col + dcol >= len(nodes)):
                        continue
                    neighbour = self.codebook[row + drow][col + dcol].vector
                    node_distances.append(node.distance(neighbour))
                distance_row.append(sum(node_distances) / len(node_distances))
            distances.append(distance_row)

        plt.imshow(distances, interpolation='none')
        plt.title('Distance map / U-matrix')
        plt.show()
Shows a plot of how far the vector of a node is from its
        neighbours. A warmer color means it's further away.
        
Shows a plot of how far the vector of a node is from its
neighbours. A warmer color means it's further away.
Shows a plot of how far the vector of a node is from its neighbours . A warmer color means it ' s further away .
def distance_map(self):
        distances = []
        for row, nodes in enumerate(self.codebook.data):
            distance_row = []
            for col, node in enumerate(nodes):
                node_distances = []
                for drow, dcol in ((-1, 0), (1, 0), (0, -1), (0, 1)):
                    if (row + drow < 0 or row + drow >= len(self.codebook) or
                            col + dcol < 0 or col + dcol >= len(nodes)):
                        continue
                    neighbour = self.codebook[row + drow][col + dcol].vector
                    node_distances.append(node.distance(neighbour))
                distance_row.append(sum(node_distances) / len(node_distances))
            distances.append(distance_row)
        plt.imshow(distances, interpolation='none')
        plt.title('Distance map / U-matrix')
        plt.show()
def distance_map ( self ) : distances = [ ] for row , nodes in enumerate ( self . codebook . data ) : distance_row = [ ] for col , node in enumerate ( nodes ) : node_distances = [ ] for drow , dcol in ( ( - 1 , 0 ) , ( 1 , 0 ) , ( 0 , - 1 ) , ( 0 , 1 ) ) : if ( row + drow < 0 or row + drow >= len ( self . codebook ) or col + dcol < 0 or col + dcol >= len ( nodes ) ) : continue neighbour = self . codebook [ row + drow ] [ col + dcol ] . vector node_distances . append ( node . distance ( neighbour ) ) distance_row . append ( sum ( node_distances ) / len ( node_distances ) ) distances . append ( distance_row ) plt . imshow ( distances , interpolation = 'none' ) plt . title ( 'Distance map / U-matrix' ) plt . show ( )
Shows a plot of how far the vector of a node is from its
neighbours.
Shows a plot of how far the vector of a node is from its neighbours .
"""Shows a plot of how far the vector of a node is from its
        neighbours. A warmer color means it's further away.
        """
self