예제 #1
0
def test_gen_event_with_known_tree_structure():
    event_size = 100
    participants_n = 10
    event = gen_event_with_known_tree_structure(
        event_size=event_size,
        participants=range(participants_n),
        start_time=10, end_time=110,
        event_topic_param=random_topic(10, topic_noise=0.0001)[0],
        topic_noise=1,
        alpha=1.0, tau=0.8,
        forward_proba=0.3,
        reply_proba=0.5,
        create_new_proba=0.2
    )

    for n in event.nodes_iter():
        sid, rid = event.node[n]['sender_id'], event.node[n]['recipient_ids'][0]
        assert_true(sid != rid)

    for s, t in event.edges_iter():
        sid1, rid1 = event.node[s]['sender_id'], event.node[s]['recipient_ids'][0]
        sid2, rid2 = event.node[t]['sender_id'], event.node[t]['recipient_ids'][0]
        c_type = event[s][t]['c_type']
        if c_type == 'r':
            assert_equal(sid1, rid2)
            assert_equal(sid2, rid1)
        elif c_type == 'f':
            assert_equal(rid1, sid2)
            assert_true(rid2 != sid1)
        else:
            assert_equal(sid1, sid2)

    interactions = [event.node[n] for n in event.nodes_iter()]
    g = IU.get_meta_graph(
        interactions,
        decompose_interactions=False,
        remove_singleton=True,
        given_topics=True,
        convert_time=False
    )
    assert_equal(1, len(get_roots(g)))
    assert_equal(event_size, len(interactions))
    
    assert_true(nx.is_arborescence(event))
예제 #2
0
def test_get_gen_cand_tree_params():
    event_size = 100
    participants_n = 10
    event = gen_event_with_known_tree_structure(
        event_size=event_size,
        participants=range(participants_n),
        start_time=10, end_time=110,
        event_topic_param=random_topic(10, topic_noise=0.1)[0],
        topic_noise=1,
        alpha=1.0, tau=0.8,
        forward_proba=0.3,
        reply_proba=0.5,
        create_new_proba=0.2
    )
    event = IU.assign_edge_weights(event, cosine)
    params = get_gen_cand_tree_params(event)

    assert_true(params['U'] > 0)
    assert_equal(99, params['preprune_secs'])
    assert_equal([0], params['roots'])
예제 #3
0
 def test_uniform_topic(self):
     topic, _ = random_topic(10, 1)
     self.seems_like_uniform_distribution(topic)
예제 #4
0
 def test_random_topic_with_taboo(self):
     topic, main_topic = random_topic(10, 0.00001, taboo_topics=range(9))
     np.testing.assert_almost_equal(1, topic.sum())
     self.seems_like_skewed_distribution(topic)
     assert_equal(9, topic.argmax())
     assert_equal(9, main_topic)
예제 #5
0
 def test_random_topic(self):
     topic, _ = random_topic(10, 0.00001)
     np.testing.assert_almost_equal(1, topic.sum())
     self.seems_like_skewed_distribution(topic)