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_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())
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())
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)