class_docstr: Class for training and visualizing a self-organizing map.
  
  Attributes:
  
      codebook     The codebook of the self-organizing map.
  
      bmus         The BMUs corresponding to the data points.
  
  :param n_columns: The number of columns in the map.
  :type n_columns: int.
  :param n_rows: The number of rows in the map.
  :type n_rows: int.
  :param initialcodebook: Optional parameter to start the training with a
                          given codebook.
  :type initialcodebook: 2D numpy.array of float32.
  :param kerneltype: Optional parameter to specify which kernel to use:
  
                         * 0: dense CPU kernel (default)
                         * 1: dense GPU kernel (if compiled with it)
  :type kerneltype: int.
  :param maptype: Optional parameter to specify the map topology:
  
                         * "planar": Planar map (default)
                         * "toroid": Toroid map
  :type maptype: str.
  :param gridtype: Optional parameter to specify the grid form of the nodes:
  
                         * "rectangular": rectangular neurons (default)
                         * "hexagonal": hexagonal neurons
  :type gridtype: str.
  :param compactsupport: Optional parameter to cut off map updates beyond the
                         training radius with the Gaussian neighborhood.
                         Default: True.
  :type compactsupport: bool.
  :param neighborhood: Optional parameter to specify the neighborhood:
  
                         * "gaussian": Gaussian neighborhood (default)
                         * "bubble": bubble neighborhood function
  :type neighborhood: str.
  :param vect_distance: Optional parameter to specify the vector distance function:
  
                         * "euclidean": Euclidean (default)
                         * "norm-inf": infinite norm (max absolute distance among components)
                         * "norm-p": p-th root of sum of absolute differences ^ p (only supported by kerneltype 0)
  :type vect_distance: str.
  :param std_coeff: Optional parameter to set the coefficient in the Gaussian
                    neighborhood function exp(-||x-y||^2/(2*(coeff*radius)^2))
                    Default: 0.5
  :type std_coeff: float.
  :param initialization: Optional parameter to specify the initalization:
  
                         * "random": random weights in the codebook
                         * "pca": codebook is initialized from the first
                           subspace spanned by the first two eigenvectors of
                           the correlation matrix
  :type initialization: str.
  :param verbose: Optional parameter to specify verbosity (0, 1, or 2).
  :type verbose: int.
class_docstr_tok: ["Class","for","training","and","visualizing","a","self-organizing","map",".","Attributes",":","codebook","The","codebook","of","the","self-organizing","map",".","bmus","The","BMUs","corresponding","to","the","data","points",".",":","param","n_columns",":","The","number","of","columns","in","the","map",".",":","type","n_columns",":","int",".",":","param","n_rows",":","The","number","of","rows","in","the","map",".",":","type","n_rows",":","int",".",":","param","initialcodebook",":","Optional","parameter","to","start","the","training","with","a","given","codebook",".",":","type","initialcodebook",":","2D","numpy.array","of","float32",".",":","param","kerneltype",":","Optional","parameter","to","specify","which","kernel","to","use",":","*","0",":","dense","CPU","kernel","(","default",")","*","1",":","dense","GPU","kernel","(","if","compiled","with","it",")",":","type","kerneltype",":","int",".",":","param","maptype",":","Optional","parameter","to","specify","the","map","topology",":","*","``","planar","''",":","Planar","map","(","default",")","*","``","toroid","''",":","Toroid","map",":","type","maptype",":","str",".",":","param","gridtype",":","Optional","parameter","to","specify","the","grid","form","of","the","nodes",":","*","``","rectangular","''",":","rectangular","neurons","(","default",")","*","``","hexagonal","''",":","hexagonal","neurons",":","type","gridtype",":","str",".",":","param","compactsupport",":","Optional","parameter","to","cut","off","map","updates","beyond","the","training","radius","with","the","Gaussian","neighborhood",".","Default",":","True",".",":","type","compactsupport",":","bool",".",":","param","neighborhood",":","Optional","parameter","to","specify","the","neighborhood",":","*","``","gaussian","''",":","Gaussian","neighborhood","(","default",")","*","``","bubble","''",":","bubble","neighborhood","function",":","type","neighborhood",":","str",".",":","param","vect_distance",":","Optional","parameter","to","specify","the","vector","distance","function",":","*","``","euclidean","''",":","Euclidean","(","default",")","*","``","norm-inf","''",":","infinite","norm","(","max","absolute","distance","among","components",")","*","``","norm-p","''",":","p-th","root","of","sum","of","absolute","differences","^","p","(","only","supported","by","kerneltype","0",")",":","type","vect_distance",":","str",".",":","param","std_coeff",":","Optional","parameter","to","set","the","coefficient","in","the","Gaussian","neighborhood","function","exp","(","-||x-y||^2\/","(","2","*","(","coeff","*","radius",")","^2",")",")","Default",":","0.5",":","type","std_coeff",":","float",".",":","param","initialization",":","Optional","parameter","to","specify","the","initalization",":","*","``","random","''",":","random","weights","in","the","codebook","*","``","pca","''",":","codebook","is","initialized","from","the","first","subspace","spanned","by","the","first","two","eigenvectors","of","the","correlation","matrix",":","type","initialization",":","str",".",":","param","verbose",":","Optional","parameter","to","specify","verbosity","(","0",",","1",",","or","2",")",".",":","type","verbose",":","int","."]
docstr: Internal function to set the codebook or to indicate it to the C++
  code that it should be randomly initialized.
docstr_tok: ["Internal","function","to","set","the","codebook","or","to","indicate","it","to","the","C++","code","that","it","should","be","randomly","initialized","."]
code: def _init_codebook(self):
      """Internal function to set the codebook or to indicate it to the C++
      code that it should be randomly initialized.
      """
      codebook_size = self._n_columns * self._n_rows * self.n_dim
      if self.codebook is None:
          if self._initialization == "random":
              self.codebook = np.zeros(codebook_size, dtype=np.float32)
              self.codebook[0:2] = [1000, 2000]
          else:
              self._pca_init()
      elif self.codebook.size != codebook_size:
          raise Exception("Invalid size for initial codebook")
      else:
          if self.codebook.dtype != np.float32:
              print(
                  "Warning: initialcodebook was not float32. A 32-bit "
                  "copy was made"
              )
              self.codebook = np.float32(self.codebook)
      self.codebook.shape = (codebook_size,)
  
imports: from __future__ import division, print_function
  import sys
  import matplotlib.cm
  import matplotlib.pyplot
  import matplotlib.collections
  import numpy
  from scipy.spatial.distance import cdist
label_desc: Use image node_id 14 for calling the Somoclu obj's underlying member method code with example usage: obj._init_codebook() without return types