Calculate the topographic error.

        The topographic error is a measure of the spatial organization of the
        map. Maps in which the most similar neurons are also close on the
        grid have low topographic error and indicate that a problem has been
        learned correctly.

        Formally, the topographic error is the proportion of units for which
        the two most similar neurons are not direct neighbors on the map.

        Parameters
        ----------
        X : numpy array.
            The input data.
        batch_size : int
            The batch size to use when calculating the topographic error.

        Returns
        -------
        error : numpy array
            A vector of numbers, representing the topographic error
            for each data point.

def topographic_error(self, X, batch_size=1):
        """
        Calculate the topographic error.

        The topographic error is a measure of the spatial organization of the
        map. Maps in which the most similar neurons are also close on the
        grid have low topographic error and indicate that a problem has been
        learned correctly.

        Formally, the topographic error is the proportion of units for which
        the two most similar neurons are not direct neighbors on the map.

        Parameters
        ----------
        X : numpy array.
            The input data.
        batch_size : int
            The batch size to use when calculating the topographic error.

        Returns
        -------
        error : numpy array
            A vector of numbers, representing the topographic error
            for each data point.

        """
        dist = self.transform(X, batch_size)
        # Sort the distances and get the indices of the two smallest distances
        # for each datapoint.
        res = dist.argsort(1)[:, :2]
        # Lookup the euclidean distance between these points in the distance
        # grid
        dgrid = self.distance_grid.reshape(self.num_neurons, self.num_neurons)
        res = np.asarray([dgrid[x, y] for x, y in res])
        # Subtract 1.0 because 1.0 is the smallest distance.
        return np.sum(res > 1.0) / len(res)