code: public int[] partition(int k) {
          int n = width * height;
          double[][] units = new double[n][d];
          for (int i = 0, l = 0; i < height; i++) {
              for (int j = 0; j < width; j++, l++) {
                  units[l] = neurons[i][j];
              }
          }
  
          double[][] proximity = new double[n][];
          for (int i = 0; i < n; i++) {
              proximity[i] = new double[i + 1];
              for (int j = 0; j < i; j++) {
                  proximity[i][j] = Math.distance(units[i], units[j]);
              }
          }
  
          Linkage linkage = new UPGMALinkage(proximity);
          HierarchicalClustering hc = new HierarchicalClustering(linkage);
          y = hc.partition(k);
  
          int[] cluster = new int[bmu.length];
          for (int i = 0; i < cluster.length; i++) {
              cluster[i] = y[bmu[i][0] * width + bmu[i][1]];
          }
          
          return cluster;
      }
docs: Clustering the neurons into k groups. And then assigns the samples in
  each neuron to the corresponding cluster.
  @param k the number of clusters.
  @return the cluster label of samples.