class_docstr: Density-based centroids initialisation.
  
  This initialisation means that we build a cumulative distribution
  function(CDF), then linearly space y-axis of this function then find the
  corresponding x-axis points.
  
  In order to simplify the implementation, here is
  a plan how it is achieved:
  1. Calculate CDF values at points spaced linearly between weight_min and
  weight_max(e.g. 20 points)
  2. Build an array of values linearly spaced between 0 and 1(probability)
  3. Go through the second array and find segment of CDF that contains this
  y-axis value, \hat{y}
  4. interpolate linearly between those two points, get a line equation y=ax+b
  5. solve equation \hat{y}=ax+b for x. The found x value is a new cluster
  centroid.
class_docstr_tok: ["Density-based","centroids","initialisation",".","This","initialisation","means","that","we","build","a","cumulative","distribution","function","(","CDF",")",",","then","linearly","space","y-axis","of","this","function","then","find","the","corresponding","x-axis","points",".","In","order","to","simplify","the","implementation",",","here","is","a","plan","how","it","is","achieved",":","1",".","Calculate","CDF","values","at","points","spaced","linearly","between","weight_min","and","weight_max","(","e.g",".","20","points",")","2",".","Build","an","array","of","values","linearly","spaced","between","0","and","1","(","probability",")","3",".","Go","through","the","second","array","and","find","segment","of","CDF","that","contains","this","y-axis","value",",","\\hat","{","y","}","4.","interpolate","linearly","between","those","two","points",",","get","a","line","equation","y=ax+b","5.","solve","equation","\\hat","{","y","}","=ax+b","for","x",".","The","found","x","value","is","a","new","cluster","centroid","."]
docstr: Interpolates linearly.
  
  Between every found index using 'i' as the current position and 'i-1' as
  a second point. The value of 'x' is a new cluster centroid.
  
  Args:
    cdf_x_grid: grid of x values.
    cdf_values: cdf values at grid.
    matching_indices: indices of each
  
  Returns:
    centroids.
docstr_tok: ["Interpolates","linearly",".","Between","every","found","index","using","'","i","'","as","the","current","position","and","'","i-1","'","as","a","second","point",".","The","value","of","'","x","'","is","a","new","cluster","centroid",".","Args",":","cdf_x_grid",":","grid","of","x","values",".","cdf_values",":","cdf","values","at","grid",".","matching_indices",":","indices","of","each","Returns",":","centroids","."]
code: def _get_centroids(self, cdf_x_grid, cdf_values, matching_indices):
      """Interpolates linearly.
  
      Between every found index using 'i' as the current position and 'i-1' as
      a second point. The value of 'x' is a new cluster centroid.
  
      Args:
        cdf_x_grid: grid of x values.
        cdf_values: cdf values at grid.
        matching_indices: indices of each
  
      Returns:
        centroids.
      """
  
      def get_single_centroid(i):
          i_clipped = tf.minimum(i, tf.size(cdf_values) - 1)
          i_previous = tf.maximum(0, i_clipped - 1)
  
          x1 = cdf_x_grid[i_clipped]
          x2 = cdf_x_grid[i_previous]
          y1 = cdf_values[i_clipped]
          y2 = cdf_values[i_previous]
  
          # Check whether interpolation is possible
          if y2 == y1:
              # If there's no delta y it doesn't make sense to try to interpolate
              # the value of x, so just take the lower bound instead
              single_centroid = x1
          else:
              # Interpolate linearly
              s = TFLinearEquationSolver(x1=x1, y1=y1, x2=x2, y2=y2)
              single_centroid = s.solve_for_x(y1)
  
          return single_centroid
  
      centroids = k.map_fn(
          get_single_centroid, matching_indices, dtype=tf.float32
      )
      return centroids
  
imports: import abc
  import six
  import tensorflow
  from tensorflow.python.ops import clustering_ops
  from tensorflow_model_optimization.python.core.clustering.keras import cluster_config
label_desc: Use image node_id 1 for calling the DensityBasedCentroidsInitialisation obj's underlying member method code with example usage: obj._get_centroids(cdf_x_grid, cdf_values, matching_indices) and returns: centroids, single_centroid