def test_full_observation_tree_closure(tree_and_cascade):
    g = tree_and_cascade[0]
    for p in np.arange(0.2, 1.0, 0.1):
        infection_times, source, obs_nodes = gen_nontrivial_cascade(g, p, 1.0)
        scores = tree_sizes_by_roots(g,
                                     obs_nodes,
                                     infection_times,
                                     source,
                                     method='closure')
        assert get_rank_index(scores, source) == 0
def one_run(g, p, q, model, result_dir, i, verbose, debug):
    infection_times, source, obs_nodes, true_tree = gen_nontrivial_cascade(
        g, p, q, model=model,
        return_tree=True, source_includable=True)
    stime = time.time()
    tree = get_tree(g, infection_times, source, obs_nodes, method,
                    verbose=verbose,
                    debug=debug)

    # pickle cascade and pred_tree
    true_edges = extract_edges(true_tree)
    pred_edges = extract_edges(tree)
    pkl.dump((infection_times, source, obs_nodes, true_edges, pred_edges),
             open(result_dir + '/{}.pkl'.format(i), 'wb'))
    return time.time() - stime
def cascades_on_grid():
    cascades = []
    g = load_graph('data/grid/2-6/graph.gt')
    for model in MODELS:
        for q in QS:
            for i in range(K):
                ret = gen_nontrivial_cascade(g,
                                             P,
                                             q,
                                             model=model,
                                             return_tree=True,
                                             source_includable=True)
                ret = (g, ) + ret + (model, q, i)
                cascades.append(
                    ret)  # g, infection_times, source, obs_nodes, true_tree
    return cascades
Exemple #4
0
def one_run(g, p, q, model, result_dir, i, verbose, debug):
    infection_times, source, obs_nodes, true_tree = gen_nontrivial_cascade(
        g, p, q, model=model, return_tree=True, source_includable=True)
    stime = time.time()
    tree = get_tree(g,
                    infection_times,
                    source,
                    obs_nodes,
                    method,
                    verbose=verbose,
                    debug=debug)

    # pickle cascade and pred_tree
    true_edges = extract_edges(true_tree)
    pred_edges = extract_edges(tree)
    pkl.dump((infection_times, source, obs_nodes, true_edges, pred_edges),
             open(result_dir + '/{}.pkl'.format(i), 'wb'))
    return time.time() - stime
def grid_and_cascade():
    g = load_graph('data/grid/2-6/graph.gt')
    c, s, o = gen_nontrivial_cascade(g, 0.8, 0.5)
    return g, c, s, o
def tree_and_cascade():
    g = load_graph('data/balanced-tree/2-6/graph.gt')
    c, s, o = gen_nontrivial_cascade(g, 0.8, 0.5)
    return g, c, s, o