def findThresholds()

in core/src/main/scala/com/spotify/featran/transformers/mdl/ThresholdFinder.scala [80:103]


  def findThresholds(candidates: Seq[(Float, Array[Long])]): Seq[Float] = {
    val queue = new mutable.Queue[((Float, Float), Option[Float])]
    // Insert first in the queue (recursive iteration)
    queue.enqueue(((Float.NegativeInfinity, Float.PositiveInfinity), None))
    var result = List(Float.NegativeInfinity) // # points = # bins - 1

    while (queue.nonEmpty && result.length < maxBins) {
      val (bounds, lastThresh) = queue.dequeue()
      // Filter the candidates between the last limits added to the queue
      val newCandidates = candidates.filter { case (th, _) =>
        th > bounds._1 && th < bounds._2
      }
      if (newCandidates.length > 0) {
        evalThresholds(newCandidates, lastThresh, nLabels) match {
          case Some(th) =>
            result = th :: result
            queue.enqueue(((bounds._1, th), Some(th)))
            queue.enqueue(((th, bounds._2), Some(th)))
          case None => /* criteria not fulfilled, finish */
        }
      }
    }
    (Float.PositiveInfinity :: result).sorted
  }