def _mergeCluster(self, cluster, clusters):
    """
    Merge cluster if it is close enough to a cluster in the list and return 
    True. Otherwise, don't merge the cluster and return False.
    :param cluster: (Cluster) cluster to merge w/ one of the existing clusters. 
    :param clusters: (list of Clusters) list of clusters to compare the first 
    cluster to.
    :return: (bool) Wether or not the cluster was merged.
    """

    clusterDistPairs = computeClusterDistances(cluster, 
                                               clusters, 
                                               self._numCells)
    clusterMerged = False
    if len(clusterDistPairs) > 0:
      for clusterDistPair in clusterDistPairs:
        closestClusterDist, closestCluster = clusterDistPair

        if closestClusterDist < self._mergeThreshold:
          _LOGGER.debug("MERGE: Cluster %s merged with cluster %s. "
                        "Inter-cluster distance: %s" % (cluster.getId(),
                                                        closestCluster.getId(),
                                                        closestClusterDist))
          closestCluster.merge(cluster, self._numIterations)
          self._removeCluster(cluster)
          clusterMerged = True

    return clusterMerged
    def _mergeCluster(self, cluster, clusters):
        """
    Merge cluster if it is close enough to a cluster in the list and return 
    True. Otherwise, don't merge the cluster and return False.
    :param cluster: (Cluster) cluster to merge w/ one of the existing clusters. 
    :param clusters: (list of Clusters) list of clusters to compare the first 
    cluster to.
    :return: (bool) Wether or not the cluster was merged.
    """

        clusterDistPairs = computeClusterDistances(cluster, clusters,
                                                   self._numCells)
        clusterMerged = False
        if len(clusterDistPairs) > 0:
            for clusterDistPair in clusterDistPairs:
                closestClusterDist, closestCluster = clusterDistPair

                if closestClusterDist < self._mergeThreshold:
                    _LOGGER.debug("MERGE: Cluster %s merged with cluster %s. "
                                  "Inter-cluster distance: %s" %
                                  (cluster.getId(), closestCluster.getId(),
                                   closestClusterDist))
                    closestCluster.merge(cluster, self._numIterations)
                    self._removeCluster(cluster)
                    clusterMerged = True

        return clusterMerged
    def _mergeNewCluster(self):

        clusterDistPairs = computeClusterDistances(self._newCluster,
                                                   self.getClusters(),
                                                   self._numCells)
        clusterMerged = False
        if len(clusterDistPairs) > 0:
            closestClusterDist, closestCluster = clusterDistPairs[0]
            if closestClusterDist < self._mergeThreshold:
                _LOGGER.debug("MERGE: Cluster %s merged with cluster %s. "
                              "Inter-cluster distance: %s" %
                              (self._newCluster.getId(),
                               closestCluster.getId(), closestClusterDist))
                updateTime = self._numIterations
                closestCluster.merge(self._newCluster, updateTime)
                clusterMerged = True

        return clusterMerged
  def _mergeNewCluster(self):

    clusterDistPairs = computeClusterDistances(self._newCluster,
                                               self.getClusters(),
                                               self._numCells)
    clusterMerged = False
    if len(clusterDistPairs) > 0:
      closestClusterDist, closestCluster = clusterDistPairs[0]
      if closestClusterDist < self._mergeThreshold:
        _LOGGER.debug("MERGE: Cluster %s merged with cluster %s. "
                      "Inter-cluster distance: %s"
                      % (self._newCluster.getId(),
                         closestCluster.getId(),
                         closestClusterDist))
        updateTime = self._numIterations
        closestCluster.merge(self._newCluster, updateTime)
        clusterMerged = True

    return clusterMerged
  def infer(self):
    """
    Inference: find the closest cluster to the new cluster.
    """
    clusterDistPairs = computeClusterDistances(self._newCluster,
                                               self.getClusters(),
                                               self._numCells)
    if len(clusterDistPairs) > 0:
      distToCluster, predictedCluster = clusterDistPairs[0]
      # Confidence of inference
      meanClusterDist = np.mean([p[0] for p in clusterDistPairs])
      if meanClusterDist > 0:
        confidence = 1 - (distToCluster / meanClusterDist)
      else:
        confidence = 1
    else:
      predictedCluster = None
      confidence = -1

    return predictedCluster, confidence
    def infer(self):
        """
    Inference: find the closest cluster to the new cluster.
    """
        clusterDistPairs = computeClusterDistances(self._newCluster,
                                                   self.getClusters(),
                                                   self._numCells)
        if len(clusterDistPairs) > 0:
            distToCluster, predictedCluster = clusterDistPairs[0]
            # Confidence of inference
            meanClusterDist = np.mean([p[0] for p in clusterDistPairs])
            if meanClusterDist > 0:
                confidence = 1 - (distToCluster / meanClusterDist)
            else:
                confidence = 1
        else:
            predictedCluster = None
            confidence = -1

        return predictedCluster, confidence