Exemplo n.º 1
0
    def test_real_trees(self):
        def distance_builder(**kwargs):
            distance = StartExitDistance()
            distance.supported[TrafficEvent] = True
            return distance
        tree_one = real_tree()
        tree_two = real_tree(path="data/c01-007-102/2/1129-2-process.csv")
        prototype_names = ["1", "2"]
        prototype_caches = []
        for index, tree in enumerate([tree_one, tree_two]):
            prototype_caches.append(PrototypeSignatureCache.from_signature_caches(
                [tree.to_index(signature=ParentChildByNameTopologySignature(),
                               supported={
                                   ProcessStartEvent: True,
                                   ProcessExitEvent: True,
                                   TrafficEvent: True
                               },
                               statistics_cls=SetStatistics)],
                prototype=prototype_names[index], threshold=0))

        decorator = AnomalyDecorator()
        algorithm = IncrementalDistanceAlgorithm(
            signature=ParentChildByNameTopologySignature(),
            distance=distance_builder,
            cache_statistics=SetStatistics
        )
        prototype_cache = prototype_caches[0]
        for cache in prototype_caches[1:]:
            prototype_cache += cache
        algorithm.cluster_representatives(
            signature_prototypes=[prototype_cache],
            prototypes=prototype_names
        )
        decorator.wrap_algorithm(algorithm)
        for tree in [tree_one, tree_two]:
            algorithm.start_tree()
            for event in tree.event_iter(supported=algorithm.supported):
                try:
                    algorithm.add_event(event)
                except EventNotSupportedException:
                    pass
            algorithm.finish_tree()
        # First tree vs. first is False for start
        self.assertFalse(decorator.data()[0][0][0][0])
        # ... and end
        self.assertFalse(decorator.data()[0][0][0][-1])
        # First tree vs. second is False for start
        self.assertFalse(decorator.data()[0][0][1][0])
        # and True for end
        self.assertTrue(decorator.data()[0][0][1][-1])
        # Second tree vs. first is False for start
        self.assertFalse(decorator.data()[1][0][0][0])
        # ... and True for end
        self.assertTrue(decorator.data()[1][0][0][-1])
        # Second tree vs. second is False for start
        self.assertFalse(decorator.data()[1][0][1][0])
        # ... and False for end
        self.assertFalse(decorator.data()[1][0][1][-1])
Exemplo n.º 2
0
    def test_initialisation_of_cluster_representatitives(self):
        def distance_builder(**kwargs):
            distance = StartExitDistance(weight=.5, **kwargs)
            distance.supported[TrafficEvent] = True
            return distance

        tree_one = real_tree()
        tree_two = real_tree(path="data/c01-007-102/2/1129-2-process.csv")
        tree_three = real_tree(path="data/c01-007-102/2/1136-3-process.csv")
        distance = StartExitDistance(weight=.5)
        distance.supported[TrafficEvent] = True
        signature = ParentChildByNameTopologySignature()
        tree_profiles = [
            tree_one.to_index(signature=signature,
                              supported=distance.supported,
                              statistics_cls=SetStatistics),
            tree_two.to_index(signature=signature,
                              supported=distance.supported,
                              statistics_cls=SetStatistics),
            tree_three.to_index(signature=signature,
                                supported=distance.supported,
                                statistics_cls=SetStatistics)
        ]
        algorithm = IncrementalDistanceAlgorithm(
            signature=ParentChildByNameTopologySignature(),
            distance=distance_builder,
            cache_statistics=SetStatistics)
        cluster_distance = ClusterDistance(distance=distance)
        prototype_names = ["test"]
        prototype_signatures = []
        for prototype in prototype_names:
            prototype_signatures.append(
                cluster_distance.mean(tree_profiles, prototype=prototype))
        algorithm.cluster_representatives(
            signature_prototypes=prototype_signatures,
            prototypes=prototype_names)
        algorithm.start_tree()