Example #1
0
    def test_random_events_with_taboo(self):
        self.adjust_params()
        events, taboos = random_events(taboo_topics=range(9),
                                       accumulate_taboo=False,
                                       **self.params)
        for e in events:
            for i in e.nodes_iter():
                assert_equal(9, e.node[i]['topics'].argmax())

        assert_equal(set(range(9)), taboos)
Example #2
0
 def test_random_events_with_taboo_and_accumulation(self):
     self.adjust_params()
     events, taboos = random_events(
         taboo_topics=range(5),
         accumulate_taboo=True,
         **self.params
     )
     new_topics = set([e.node[n]['topics'].argmax()
                       for e in events
                       for n in e.nodes_iter()])
     
     assert_equal(set(range(5, 10)), set(new_topics))
     assert_equal(set(range(10)), taboos)
Example #3
0
    def test_random_events(self):
        self.adjust_params()

        events, _ = random_events(**self.params)
        assert_equal(self.params['n_events'], len(events))

        sizes = np.array([e.number_of_nodes() for e in events])
        np.testing.assert_almost_equal(
            self.params['event_size_mu'],
            np.mean(sizes)
        )

        times = lambda e: [e.node[n]['timestamp'] for n in e.nodes_iter()]
        mean_duration = np.mean([max(times(e)) - min(times(e))
                                 for e in events])
        np.testing.assert_almost_equal(
            510,
            mean_duration,
            decimal=-1
        )
        
        unique_participants = lambda e: set(itertools.chain(
            *[[e.node[n]['sender_id']] + e.node[n]['recipient_ids']
              for n in e.nodes_iter()]
        ))
        mean_n_participants = np.mean(
            [len(unique_participants(e))
             for e in events]
        )
        np.testing.assert_almost_equal(
            5,
            mean_n_participants,
            decimal=0
        )
        
        for e in events:
            topic_mean = np.mean([e.node[n]['topics']
                                  for n in e.nodes_iter()],
                                 axis=0)
            topic_2nd, topic_1st = np.sort(topic_mean)[-2:]
            assert_true((topic_1st / topic_2nd) > 10000)