def test_decorator(self):
        decorator = DistancePerformanceDecorator(accumulated=False)
        algorithm = IncrementalDistanceAlgorithm()
        algorithm.prototypes = [simple_prototype()]
        decorator.wrap_algorithm(algorithm)

        self.assertIsNone(decorator.data())
        decorator.start_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {"distance_performance": [[]]})
        decorator.finish_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {"distance_performance": [[]]})

        decorator.wrap_algorithm(algorithm)
        decorator.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        description = decorator.descriptive_data()
        self.assertEqual(len(description["distance_performance"][0]), 4)
        decorator.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        description = decorator.descriptive_data()
        self.assertEqual(len(description["distance_performance"]), 2)
        self.assertEqual(len(description["distance_performance"][1]), 4)
    def test_signatures(self):
        decorator = SignatureDecorator()
        algorithm = IncrementalDistanceAlgorithm(
            signature=ParentChildByNameTopologySignature())
        algorithm.prototypes = [simple_prototype()]
        decorator.wrap_algorithm(algorithm)

        decorator.start_tree()
        self.assertEqual(decorator.descriptive_data(), {"signature": [[[]]]})
        decorator.finish_tree()
        self.assertEqual(decorator.descriptive_data(), {"signature": [[[]]]})

        decorator.wrap_algorithm(algorithm)
        decorator.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        description = decorator.descriptive_data()
        self.assertEqual(len(description["signature"]), 1)
        self.assertEqual(len(set(description["signature"][0][0])), 3)
        self.assertEqual(len(description["signature"][0][0]), 4)
        self.assertEqual(description["signature"][0][0][0], "root_1")
        self.assertEqual(description["signature"][0][0][1], "test_149160533")
        self.assertEqual(description["signature"][0][0][3], "muh_149160533")

        decorator.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        description = decorator.descriptive_data()
        self.assertEqual(len(description["signature"]), 2)
Esempio n. 3
0
    def test_accumulated_decorator(self):
        decorator = SignaturePerformanceDecorator()
        algorithm = IncrementalDistanceAlgorithm()
        algorithm.prototypes = [simple_prototype()]
        decorator.wrap_algorithm(algorithm)

        decorator.start_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {'accumulated_signature_performance': [[None]]})
        decorator.finish_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {'accumulated_signature_performance': [[None]]})

        decorator.wrap_algorithm(algorithm)
        decorator.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        description = decorator.descriptive_data()
        self.assertEqual(
            type(description["accumulated_signature_performance"][0][0]),
            float)
        decorator.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        description = decorator.descriptive_data()
        print(description)
        self.assertEqual(len(description["accumulated_signature_performance"]),
                         2)
        self.assertEqual(
            type(description["accumulated_signature_performance"][1][0]),
            float)
Esempio n. 4
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])
 def test_ensemble(self):
     def distance(**kwargs):
         distance = StartExitDistance(weight=.5, **kwargs)
         distance.supported[TrafficEvent] = False
         return distance
     signature = EnsembleSignature(
         signatures=[
             ParentChildByNameTopologySignature(), ParentSiblingSignature(width=2)])
     algorithm = IncrementalDistanceAlgorithm(
         signature=signature,
         distance=distance,
         cache_statistics=SetStatistics
     )
     decorator = DistanceMatrixDecorator(normalized=True)
     decorator.wrap_algorithm(algorithm)
     algorithm.prototypes = [simple_prototype()]
     algorithm.start_tree()
     for event in simple_monitoring_tree().event_iter(supported=algorithm.supported):
         try:
             algorithm.add_event(event)
         except EventNotSupportedException:
             pass
     algorithm.finish_tree()
     print(decorator.data())
     self.assertTrue(False)
    def test_normalized_results(self):
        decorator = DistanceDecorator(normalized=True)
        algorithm = IncrementalDistanceAlgorithm(
            signature=EnsembleSignature(
                signatures=[ParentChildByNameTopologySignature(),
                            ParentChildOrderByNameTopologySignature()])
        )
        algorithm.prototypes = [simple_prototype(), simple_monitoring_tree()]
        decorator.wrap_algorithm(algorithm)

        algorithm.start_tree()
        self.assertEqual([[[[], []], [[], []]]], decorator.data())
        for event in Event.from_tree(simple_monitoring_tree(), supported={ProcessStartEvent: True}):
            algorithm.add_event(event)
        algorithm.finish_tree()

        self.assertEqual([[
            [  # ParentChildByNameTopologySignature
                [2 / 3, 1 / 3, 1 / 3, 0.0],  # simple_prototype
                [2 / 3, 1 / 3, 1 / 3, 0.0]   # simple_monitoring_tree
            ],
            [  # ParentChildOrderByNameTopologySignature
                [4 / 5, 3 / 5, 3 / 5, 2 / 5],
                [2 / 3, 1 / 3, 1 / 3, 0.0]
            ]]], decorator.data())
    def test_parameter_distance(self):
        prototype = Prototype()
        root = prototype.add_node("root", tme=0, exit_tme=0, pid=1, ppid=0, param=1)
        for i in range(5):
            root.add_node("child_%d" % i, tme=0, exit_tme=0, pid=i + 2, ppid=1, param=1)
        next(root.children()).add_node("child", tme=0, exit_tme=0, pid=8, ppid=2, param=1)

        tree = Prototype()
        root = tree.add_node("root", tme=0, exit_tme=0, pid=1, ppid=0, param=1)
        for i in range(5):
            root.add_node("child_%d" % i, tme=0, exit_tme=0, pid=i + 2, ppid=1, param=4)
        next(root.children()).add_node("child", tme=0, exit_tme=0, pid=8, ppid=2, param=4)

        for weight, result in [(1, 0), (.5, 6), (0, 12)]:
            def distance(**kwargs):
                distance = StartExitDistance(weight=weight, **kwargs)
                distance.supported = {
                    ProcessStartEvent: True,
                    ProcessExitEvent: True,
                    ParameterEvent: True
                }
                return distance
            signature = EnsembleSignature(signatures=[ParentChildByNameTopologySignature()])
            algorithm = IncrementalDistanceAlgorithm(
                signature=signature,
                distance=distance,
                cache_statistics=SetStatistics
            )
            decorator = DistanceMatrixDecorator(normalized=False)
            decorator.wrap_algorithm(algorithm)
            algorithm.prototypes = [prototype]
            algorithm.start_tree()
            algorithm.add_events(tree.event_iter(supported=algorithm.supported))
            algorithm.finish_tree()
            self.assertEqual(result, decorator.data()[0][0][0])
Esempio n. 8
0
    def test_ensemble_with_prototypes(self):
        decorator = AnomalyDecorator()
        algorithm = IncrementalDistanceAlgorithm(
            signature=EnsembleSignature(
                signatures=[ParentChildByNameTopologySignature(),
                            ParentChildOrderByNameTopologySignature()]))
        algorithm.prototypes = [simple_prototype(), simple_monitoring_tree()]
        decorator.wrap_algorithm(algorithm)

        algorithm.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(), supported={ProcessStartEvent: True}):
            algorithm.add_event(event)
        algorithm.finish_tree()
        self.assertEqual(decorator.data(), [
            [
                [
                    [False, False, False, False, False],
                    [False, False, False, False, False]
                ],
                [
                    [False, False, False, False, True],
                    [False, False, False, False, False]
                ]
            ]
        ])
 def test_external(self):
     def distance(**kwargs):
         distance = StartExitDistance(weight=0, **kwargs)
         distance.supported[TrafficEvent] = True
         return distance
     algorithm = IncrementalDistanceAlgorithm(
         signature=ParentChildByNameTopologySignature(),
         distance=distance,
         cache_statistics=SplittedStatistics)
     decorator = DistanceMatrixDecorator(normalized=False)
     decorator.wrap_algorithm(algorithm)
     the_tree = real_tree(
         path="data/c01-007-102/2/1146-2-process.csv",
         absolute=True
     )
     algorithm.prototypes = [the_tree]
     algorithm.start_tree()
     for event in the_tree.event_iter(supported=algorithm.supported):
         try:
             algorithm.add_event(event)
         except EventNotSupportedException:
             pass
     algorithm.finish_tree()
     print(decorator.data())
     self.assertTrue(False)
Esempio n. 10
0
    def test_default_generator_incremental_distance(self):
        rg = RandomGenerator(seed=1234)
        alg = IncrementalDistanceAlgorithm()
        alg.prototypes = [rg.prototype]

        vector_decorator = DistanceDecorator()
        vector_decorator._algorithm = alg

        vector_decorator.start_tree()
        for event in rg:
            distance = vector_decorator.add_event(event)[0]
        vector_decorator.finish_tree()
        self.assertEqual(distance[0], [110])
Esempio n. 11
0
    def test_maximum_generator_incremental_distance(self):
        rg = RandomGenerator(relative_matching=1)
        alg = IncrementalDistanceAlgorithm()
        alg.prototypes = [rg.prototype]

        decorator = DistanceDecorator(normalized=True)
        decorator.algorithm = alg

        decorator.start_tree()
        for event in rg:
            distance = decorator.add_event(event)[0]
        decorator.finish_tree()
        self.assertEqual(distance[0], [0])
Esempio n. 12
0
    def test_maximum_generator_newerincremental_with_signature_distance(self):
        rg = RandomGenerator(relative_matching=1)
        signature = ParentChildByNameTopologySignature()
        alg = IncrementalDistanceAlgorithm(signature=signature)
        alg.prototypes = [rg.prototype]

        decorator = DistanceDecorator(normalized=True)
        decorator.algorithm = alg

        decorator.start_tree()
        for event in rg:
            decorator.add_event(event)
        decorator.finish_tree()
        self.assertEqual(decorator.data()[-1][-1][-1][-1], 0)
    def test_two_prototypes(self):
        decorator = DistanceDecorator(normalized=False)
        algorithm = IncrementalDistanceAlgorithm()
        algorithm.prototypes = [simple_prototype(), simple_monitoring_tree()]

        decorator.wrap_algorithm(algorithm)

        algorithm.start_tree()
        self.assertEqual([[[[], []]]], decorator.data())
        for event in Event.from_tree(simple_monitoring_tree(), supported={ProcessStartEvent: True}):
            algorithm.add_event(event)
        algorithm.finish_tree()
        self.assertEqual([[[[2, 1, 1, 0], [2, 1, 1, 0]]]], decorator.data())
Esempio n. 14
0
    def test_bigger_tree(self):
        rg = RandomGenerator(prototype_node_count=100,
                             tree_node_count=200,
                             relative_matching=.9,
                             relative_repetition=.5,
                             seed=1234)
        signature = ParentChildByNameTopologySignature()
        alg = IncrementalDistanceAlgorithm(signature=signature)
        alg.prototypes = [rg.prototype]

        decorator = DistanceDecorator(normalized=True)
        decorator.wrap_algorithm(alg)

        decorator.start_tree()
        for event in rg:
            decorator.add_event(event)
        decorator.finish_tree()
        self.assertAlmostEqual(decorator.data()[-1][-1][-1][-1], 0.185, 2)
 def test_compression_with_events(self):
     decorator = CompressionFactorDecorator()
     algorithm = IncrementalDistanceAlgorithm()
     algorithm.prototypes = [simple_prototype(), simple_prototype()]
     decorator.wrap_algorithm(algorithm)
     decorator.start_tree()
     for event in Event.from_tree(simple_monitoring_tree(),
                                  supported={ProcessStartEvent: True}):
         decorator.add_event(event)
     decorator.finish_tree()
     self.assertEqual(
         decorator.descriptive_data(), {
             "compression": {
                 "prototypes": [[.4, .4]],
                 "monitoring": [[.25]],
                 "accumulated": [.7]
             }
         })
    def test_ensemble(self):
        decorator = DistanceDecorator(normalized=False)
        algorithm = IncrementalDistanceAlgorithm(
            signature=EnsembleSignature(
                signatures=[ParentChildByNameTopologySignature(),
                            ParentChildOrderByNameTopologySignature()]))
        algorithm.prototypes = [simple_prototype()]

        decorator.wrap_algorithm(algorithm)

        algorithm.start_tree()
        self.assertEqual([[[[]], [[]]]], decorator.data())
        for event in Event.from_tree(simple_monitoring_tree(), supported={ProcessStartEvent: True}):
            algorithm.add_event(event)
        algorithm.finish_tree()
        self.assertEqual([[[[2, 1, 1, 0]], [[4, 3, 3, 2]]]], decorator.data())
Esempio n. 17
0
    def test_count_signature_for_correct_zero_distance(self):
        signature = ParentCountedChildrenByNameTopologySignature(count=3)
        algorithm = IncrementalDistanceAlgorithm(signature=signature)
        decorator = DistanceMatrixDecorator(normalized=False)
        decorator.wrap_algorithm(algorithm)
        algorithm.prototypes = [real_tree()]

        algorithm.start_tree()
        for event in real_tree().event_iter(include_marker=True, supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        print(algorithm._signature_prototypes._prototype_dict[0]._prototype_dict.keys())
        self.assertEqual([[[0]]], decorator.data())
Esempio n. 18
0
    def test_simple_normalized_matrix(self):
        decorator = DistanceMatrixDecorator(normalized=True)
        algorithm = IncrementalDistanceAlgorithm()
        algorithm.prototypes = [simple_prototype()]
        decorator.wrap_algorithm(algorithm)

        decorator.start_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {"normalized_matrix": [[[None]]]})
        decorator.finish_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {"normalized_matrix": [[[1]]]})

        decorator.wrap_algorithm(algorithm)
        decorator.start_tree()
        for event in Event.from_tree(simple_prototype(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {"normalized_matrix": [[[0]]]})

        algorithm.prototypes = [
            simple_prototype(),
            simple_additional_monitoring_tree()
        ]
        decorator.wrap_algorithm(algorithm)
        decorator.start_tree()
        for event in Event.from_tree(simple_prototype(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {"normalized_matrix": [[[0, .4]]]})
        decorator.start_tree()
        for event in Event.from_tree(simple_additional_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        self.assertEqual(decorator.descriptive_data(),
                         {"normalized_matrix": [[[0.0, .4]], [[.4, 0.0]]]})
        self.assertRaises(MatrixDoesNotMatchBounds, decorator.start_tree)
Esempio n. 19
0
    def test_creation(self):
        decorator = Decorator()
        self.assertIsNone(decorator.algorithm)
        self.assertRaises(NotImplementedError, decorator.data)
        self.assertRaises(NotImplementedError, decorator.descriptive_data)

        algorithm = IncrementalDistanceAlgorithm()
        decorator.wrap_algorithm(algorithm=algorithm)
        self.assertEqual(decorator.algorithm, algorithm)
        self.assertIsNone(decorator.decorator)
        decorator.start_tree()
        decorator.finish_tree()
    def test_empty_nodes(self):
        signature = EnsembleSignature(
            signatures=[ParentChildByNameTopologySignature(),
                        ParentCountedChildrenByNameTopologySignature(count=3)])
        algorithm = IncrementalDistanceAlgorithm(signature=signature)
        algorithm.prototypes = [simple_prototype()]

        algorithm.start_tree()
        for event in simple_monitoring_tree().event_iter(supported=algorithm.supported):
            try:
                distance = algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        self.assertEqual([[0], [7]], distance[-1])
Esempio n. 21
0
    def test_simple(self):
        algorithm = IncrementalDistanceAlgorithm(
            signature=ParentChildByNameTopologySignature(),
            distance=StartDistance)
        algorithm.prototypes = [simple_prototype()]
        distance = algorithm.distance
        distance.init_distance(
            prototypes=algorithm.prototypes,
            signature_prototypes=algorithm.signature_prototypes)

        last_index = 0
        for index, dist in enumerate(
                distance.iter_on_prototypes(algorithm.prototypes)):
            self.assertEqual(dist, [5])
            last_index = index
        self.assertEqual(last_index, 0)
        self.assertTrue(distance.is_prototype_based_on_original())

        for node in simple_monitoring_tree().nodes():
            node_signature = algorithm.signature.get_signature(
                node, node.parent())
            matching_prototypes = algorithm.signature_prototypes.get(
                signature=node_signature)
            distance.update_distance(
                prototypes=algorithm.prototypes,
                signature_prototypes=algorithm.signature_prototypes,
                matches=[{
                    token: matching_prototypes[index]
                } for index, token in enumerate(node_signature)],
                value=float(node.exit_tme) - float(node.tme),
            )
        for result in distance._monitoring_results_dict:
            self.assertEqual(result[algorithm.prototypes[0]], 1)
        result = distance._monitoring_results_dict
        distance.finish_distance(
            prototypes=algorithm.prototypes,
            signature_prototypes=algorithm.signature_prototypes)
        self.assertEqual(result, distance._monitoring_results_dict)
 def test_simple_functionality(self):
     decorator = CompressionFactorDecorator()
     algorithm = IncrementalDistanceAlgorithm()
     decorator.wrap_algorithm(algorithm=algorithm)
     decorator.start_tree()
     self.assertEqual(
         decorator.descriptive_data(), {
             "compression": {
                 "prototypes": [],
                 "monitoring": [None],
                 "accumulated": []
             }
         })
     decorator.finish_tree()
     self.assertEqual(
         decorator.descriptive_data(), {
             "compression": {
                 "prototypes": [],
                 "monitoring": [[0]],
                 "accumulated": []
             }
         })
     algorithm.prototypes = [simple_prototype()]
     decorator.algorithm = algorithm
     decorator.start_tree()
     decorator.finish_tree()
     self.assertEqual(
         decorator.descriptive_data(), {
             "compression": {
                 "prototypes": [[.4]],
                 "monitoring": [[0]],
                 "accumulated": [.4]
             }
         })
     decorator.wrap_algorithm(algorithm)
     self.assertEqual(decorator.descriptive_data(), {"compression": None})
Esempio n. 23
0
    def test_chaining(self):
        decorator = Decorator()
        decorator2 = Decorator()
        decorator.decorator = decorator2
        self.assertIsNotNone(decorator.decorator)
        self.assertIsNone(decorator2.decorator)

        algorithm = IncrementalDistanceAlgorithm()
        decorator.algorithm = algorithm
        self.assertEqual(decorator2.algorithm, algorithm)
        decorator.algorithm = None
        decorator.wrap_algorithm(algorithm=algorithm)
        self.assertEqual(decorator2.algorithm, algorithm)
        decorator.start_tree()
        decorator.finish_tree()
Esempio n. 24
0
    def test_node_count_for_correct_zero_distance(self):
        signature = EnsembleSignature(
            signatures=[ParentChildByNameTopologySignature(),
                        ParentCountedChildrenByNameTopologySignature(count=3)])
        algorithm = IncrementalDistanceAlgorithm(
            signature=signature, distance=SimpleDistance)
        data_decorator = DataDecorator()
        data_decorator.wrap_algorithm(algorithm)
        algorithm.prototypes = [real_tree()]

        algorithm.start_tree()
        for event in real_tree().event_iter(include_marker=True, supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        self.assertEqual([tree_value for values in data_decorator.data().get(
            "prototypes", {}).get("converted", []) for tree_value in values],
            [tree_value for values in data_decorator.data().get(
             "monitoring", {}).get("converted", []) for tree_value in values])
Esempio n. 25
0
    def test_symmetry_optimisation(self):
        tree = CSVTreeBuilder().build(
            os.path.join(os.path.dirname(assess_tests.__file__),
                         "data/c01-007-102/2/1129-2-process.csv"))
        signature = ParentChildByNameTopologySignature()
        algorithm = IncrementalDistanceAlgorithm(
            signature=signature,
            distance=lambda **kwargs: StartExitDistance(weight=0, **kwargs),
            cache_statistics=SplittedStatistics)
        algorithm.prototypes = [tree]
        decorator = DistanceMatrixDecorator(normalized=False)
        decorator.wrap_algorithm(algorithm)

        algorithm.start_tree()
        for event in tree.event_iter(supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        self.assertEqual(0, decorator.data()[0][0][0])
    def test_attributes_nodes_only(self):
        def distance(**kwargs):
            distance = StartExitDistance(weight=1, **kwargs)
            distance.supported[TrafficEvent] = True
            return distance
        algorithm = IncrementalDistanceAlgorithm(
            signature=ParentChildByNameTopologySignature(),
            distance=distance,
            cache_statistics=SetStatistics
        )
        decorator = DistanceMatrixDecorator(normalized=False)
        decorator.wrap_algorithm(algorithm)
        algorithm.prototypes = [real_tree("data/c01-007-102/2/1129-2-process.csv")]

        monitoring_tree = real_tree("data/c01-007-102/2/1129-2-process.csv")
        algorithm.start_tree()
        for event in monitoring_tree.event_iter(supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        self.assertEqual([[[0]]], decorator.data())
Esempio n. 27
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()
Esempio n. 28
0
    def test_decorator(self):
        decorator = DataDecorator()
        algorithm = IncrementalDistanceAlgorithm()
        algorithm.prototypes = [simple_prototype()]
        decorator.wrap_algorithm(algorithm)
        decorator.start_tree()
        self.assertEqual(
            decorator.descriptive_data(), {
                "data": {
                    "prototypes": {
                        "original": [[5]],
                        "converted": [[3]]
                    },
                    "monitoring": {}
                }
            })
        decorator.finish_tree()
        self.assertEqual(
            decorator.descriptive_data(), {
                "data": {
                    "prototypes": {
                        "original": [[5]],
                        "converted": [[3]]
                    },
                    "monitoring": {
                        "original": [[0]],
                        "converted": [[0]]
                    }
                }
            })

        algorithm.prototypes = [simple_prototype(), simple_prototype()]
        decorator.wrap_algorithm(algorithm)

        decorator.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        self.assertEqual(
            decorator.descriptive_data(),
            {
                "data": {
                    "prototypes": {
                        # FIXME: hier bin ich mir nicht sicher, ob dass das sagt,
                        # was ich gern hätte...
                        "original": [[5, 5]],
                        "converted": [[3, 3]]
                    },
                    "monitoring": {
                        "original": [[4]],
                        "converted": [[3]]
                    }
                }
            })

        decorator.start_tree()
        for event in Event.from_tree(simple_monitoring_tree(),
                                     supported={ProcessStartEvent: True}):
            decorator.add_event(event)
        decorator.finish_tree()
        self.assertEqual(
            decorator.descriptive_data(),
            {
                "data": {
                    "prototypes": {
                        "original": [[5, 5]],  # FIXME: please check!
                        "converted": [[3, 3]]
                    },
                    "monitoring": {
                        "original": [[4], [4]],
                        "converted": [[3], [3]]
                    }
                }
            })
Esempio n. 29
0
    def test_same_attributes_different_count(self):
        tree_1 = Prototype()
        root = tree_1.add_node("root", pid=1, ppid=0, tme=0, exit_tme=0)
        for _ in range(5):
            root.add_node("node", pid=2, ppid=1, tme=0, exit_tme=0)
        tree_2 = Prototype()
        root = tree_2.add_node("root", pid=1, ppid=0, tme=0, exit_tme=0)
        for _ in range(35):
            root.add_node("node", pid=2, ppid=1, tme=0, exit_tme=0)

        signature = ParentChildByNameTopologySignature()
        algorithm = IncrementalDistanceAlgorithm(
            signature=signature,
            distance=lambda **kwargs: StartExitDistance(weight=0, **kwargs),
            cache_statistics=SplittedStatistics)
        algorithm.prototypes = [tree_1, tree_2]
        decorator = DistanceMatrixDecorator(normalized=False)
        decorator.wrap_algorithm(algorithm)

        algorithm.start_tree()
        for event in tree_1.event_iter(supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        algorithm.start_tree()
        for event in tree_2.event_iter(supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        data = decorator.data()
        self.assertEqual(data[0][0][1], data[1][0][0])
Esempio n. 30
0
    def test_attribute_distance(self):
        def distance_buidler(**kwargs):
            distance = StartExitDistance(weight=0, **kwargs)
            distance.supported = {
                ProcessStartEvent: True,
                ProcessExitEvent: True,
                TrafficEvent: True
            }
            return distance

        tree_builder = CSVTreeBuilder()
        tree_1 = tree_builder.build(
            os.path.join(os.path.dirname(assess_tests.__file__),
                         "data/c01-007-102/2/1129-2-process.csv"))
        tree_2 = tree_builder.build(
            os.path.join(os.path.dirname(assess_tests.__file__),
                         "data/c01-007-102/2/1136-3-process.csv"))
        signature = ParentChildByNameTopologySignature()
        algorithm = IncrementalDistanceAlgorithm(
            signature=signature,
            distance=distance_buidler,
            cache_statistics=SplittedStatistics)
        algorithm.prototypes = [tree_1, tree_2]
        decorator = DistanceMatrixDecorator(normalized=False)
        decorator.wrap_algorithm(algorithm)

        algorithm.start_tree()
        for event in tree_1.event_iter(supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        algorithm.start_tree()
        for event in tree_2.event_iter(supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        data = decorator.data()
        print(decorator.data())
        self.assertEqual(4, abs(data[0][0][1] - data[1][0][0]))