def run (self, clustering):
        max_partitions = self.refinement_parameters["max_partitions"]
        try_step = int(max(1, float(max_partitions) / self.refinement_parameters["tries_per_cluster"]))
        matrix = self.matrixHandler.distance_matrix

        new_clusters = []
        for cluster in clustering.clusters:
            base_id = cluster.id
            # The initial clustering is added to the list of new clusters.
            # With this 'trick' the initial cluster also enters the competition for the best clustering price.
            clusterings = {base_id:{"type":"refined_base",
                                    "clustering": Clustering([cluster]),
                                    "parameters": {}}}

            submatrix = get_submatrix(matrix, cluster.all_elements)

            # Proceed with some K Medoids partitions
            # TODO: Generate parameters with parameter generator
            for k in range(2,max_partitions,try_step):
                clustering = self.repartition_with_kmedoids(cluster, k, submatrix)
                clusterings["%s_%d"%(base_id,k)] = {"type":"refined",
                                                     "clustering": clustering,
                                                     "parameters": {"k":k}}

            # Evaluate all clusterings and pick the best one
            AnalysisRunner(scheduling_tools.build_scheduler(
                                                       self.clustering_parameters["clustering"]["control"],
                                                       self.observer),
                                          clusterings,
                                          AnalysisPopulator(self.matrixHandler,
                                                            self.trajectoryHandler,
                                                            self.clustering_parameters)).evaluate()

            best_clustering_id, all_scores = BestClusteringSelector(self.clustering_parameters).choose_best(clusterings)  # @UnusedVariable
            new_clusters.extend(clusterings[best_clustering_id]["clustering"].clusters)

        # Convert all new clusters in the new clustering
        return {"type":"refined_clustering",
                "clustering": Clustering(new_clusters),
                "parameters": self.refinement_parameters}
Refine a clustering recursively using a k-means over each cluster.
dataset/ETHPy150Open victor-gil-sepulveda/pyProCT/pyproct/clustering/protocol/refinement/Refiner.py/Refiner.run