Пример #1
0
 def test_calculate_distance_stats(self):
     calc_mean, calc_std, calc_radius = calculate_distance_stats(self.decomposed_cluster["traj_A"], self.matrix)
     distances = [1.4142135381698608, 1.4142135381698608, 1.4142135381698608, 1.4142135381698608, 0.0]
     expected_mean = numpy.mean(distances)
     expected_std = numpy.std(distances)
     expected_radius = numpy.max(distances)
     self.assertItemsEqual((expected_mean,expected_std,expected_radius),(calc_mean, calc_std, calc_radius))
Пример #2
0
    def analyze_clusters(cls, separated_decomposed_clusters, distance_matrix,
                         analysis):
        """
        Performs the overlap analysis of separated clusters.
        """
        for cluster_type in separated_decomposed_clusters:
            for cluster_id in separated_decomposed_clusters[cluster_type]:
                decomposed_cluster = separated_decomposed_clusters[
                    cluster_type][cluster_id]
                analysis[cluster_id] = {
                    "components": decomposed_cluster.keys(),
                    "global": {}
                }
                analysis[cluster_id]["global"]["mean"], analysis[cluster_id][
                    "global"]["std"], analysis[cluster_id]["global"][
                        "max"] = calculate_distance_stats(
                            getAllElements(decomposed_cluster),
                            distance_matrix)
                analysis[cluster_id]["global"]["num_elements"] = len(
                    getAllElements(decomposed_cluster))

                for traj_id in decomposed_cluster:
                    analysis[cluster_id]["global"][traj_id] = {}
                    analysis[cluster_id]["global"][traj_id]["mean"], analysis[
                        cluster_id]["global"][traj_id]["std"], analysis[
                            cluster_id]["global"][traj_id][
                                "max"] = calculate_distance_stats(
                                    decomposed_cluster[traj_id],
                                    distance_matrix)
                    analysis[cluster_id]["global"][traj_id][
                        "num_elements"] = len(decomposed_cluster[traj_id])

                if cluster_type == "mixed":
                    analysis[cluster_id][
                        "centers_mean_diff"] = calculate_mean_center_differences(
                            decomposed_cluster, distance_matrix)
                    # The overlap ranges between 0 and 1, being 0 the best value. We invert it in order to
                    # to get a more understandable range (1 is the best value and 0 the worst).
                    analysis[cluster_id]["global"][
                        "overlap"] = 1 - OverlapCalculator.calculate_cluster_overlap(
                            decomposed_cluster, distance_matrix)
Пример #3
0
    def analyze_clusters(cls, separated_decomposed_clusters, distance_matrix,
                         analysis):
        for cluster_type in separated_decomposed_clusters:
            for cluster_id in separated_decomposed_clusters[cluster_type]:
                decomposed_cluster = separated_decomposed_clusters[
                    cluster_type][cluster_id]
                analysis[cluster_id] = {
                    "components": decomposed_cluster.keys(),
                    "global": {}
                }
                analysis[cluster_id]["global"]["mean"], analysis[cluster_id][
                    "global"]["std"], analysis[cluster_id]["global"][
                        "max"] = calculate_distance_stats(
                            getAllElements(decomposed_cluster),
                            distance_matrix)
                analysis[cluster_id]["global"]["num_elements"] = len(
                    getAllElements(decomposed_cluster))

                for traj_id in decomposed_cluster:
                    analysis[cluster_id]["global"][traj_id] = {}
                    analysis[cluster_id]["global"][traj_id]["mean"], analysis[
                        cluster_id]["global"][traj_id]["std"], analysis[
                            cluster_id]["global"][traj_id][
                                "max"] = calculate_distance_stats(
                                    decomposed_cluster[traj_id],
                                    distance_matrix)
                    analysis[cluster_id]["global"][traj_id][
                        "num_elements"] = len(decomposed_cluster[traj_id])

                if cluster_type == "mixed":
                    analysis[cluster_id][
                        "centers_mean_diff"] = calculate_mean_center_differences(
                            decomposed_cluster, distance_matrix)
                    analysis[cluster_id]["global"][
                        "overlap"] = OverlapCalculator.calculate_cluster_overlap(
                            2, decomposed_cluster, distance_matrix)
Пример #4
0
    def analyze_clusters(cls, separated_decomposed_clusters, distance_matrix, analysis):
        for cluster_type in separated_decomposed_clusters:
            for cluster_id in separated_decomposed_clusters[cluster_type]:
                decomposed_cluster = separated_decomposed_clusters[cluster_type][cluster_id]
                analysis[cluster_id] = {"components":decomposed_cluster.keys(),"global":{}}
                analysis[cluster_id]["global"]["mean"], analysis[cluster_id]["global"]["std"], analysis[cluster_id]["global"]["max"] = calculate_distance_stats(getAllElements(decomposed_cluster), distance_matrix)
                analysis[cluster_id]["global"]["num_elements"] = len(getAllElements(decomposed_cluster))

                for traj_id in decomposed_cluster:
                    analysis[cluster_id]["global"][traj_id] = {}
                    analysis[cluster_id]["global"][traj_id]["mean"], analysis[cluster_id]["global"][traj_id]["std"], analysis[cluster_id]["global"][traj_id]["max"] = calculate_distance_stats(decomposed_cluster[traj_id], distance_matrix)
                    analysis[cluster_id]["global"][traj_id]["num_elements"] = len(decomposed_cluster[traj_id])

                if cluster_type == "mixed":
                    analysis[cluster_id]["centers_mean_diff"] = calculate_mean_center_differences(decomposed_cluster, distance_matrix)
                    analysis[cluster_id]["global"]["overlap"] = OverlapCalculator.calculate_cluster_overlap(2, decomposed_cluster, distance_matrix)
Пример #5
0
    def analyze_clusters(cls, separated_decomposed_clusters, distance_matrix, analysis):
        """
        Performs the overlap analysis of separated clusters.
        """
        for cluster_type in separated_decomposed_clusters:
            for cluster_id in separated_decomposed_clusters[cluster_type]:
                decomposed_cluster = separated_decomposed_clusters[cluster_type][cluster_id]
                analysis[cluster_id] = {"components":decomposed_cluster.keys(),"global":{}}
                analysis[cluster_id]["global"]["mean"], analysis[cluster_id]["global"]["std"], analysis[cluster_id]["global"]["max"] = calculate_distance_stats(getAllElements(decomposed_cluster), distance_matrix)
                analysis[cluster_id]["global"]["num_elements"] = len(getAllElements(decomposed_cluster))

                for traj_id in decomposed_cluster:
                    analysis[cluster_id]["global"][traj_id] = {}
                    analysis[cluster_id]["global"][traj_id]["mean"], analysis[cluster_id]["global"][traj_id]["std"], analysis[cluster_id]["global"][traj_id]["max"] = calculate_distance_stats(decomposed_cluster[traj_id], distance_matrix)
                    analysis[cluster_id]["global"][traj_id]["num_elements"] = len(decomposed_cluster[traj_id])

                if cluster_type == "mixed":
                    analysis[cluster_id]["centers_mean_diff"] = calculate_mean_center_differences(decomposed_cluster, distance_matrix)
                    # The overlap ranges between 0 and 1, being 0 the best value. We invert it in order to
                    # to get a more understandable range (1 is the best value and 0 the worst). 
                    analysis[cluster_id]["global"]["overlap"] = 1 - OverlapCalculator.calculate_cluster_overlap( decomposed_cluster, distance_matrix)