def experiment_mwu_n_rounds(rounds,
                            g,
                            p, q, epsilon,
                            sampling_method,
                            active_method,
                            reward_method,
                            n1=100,
                            seed=None):
    np.random.seed(seed)
    random.seed(seed)
    results = []
    gvs = get_gvs(g, p, n1)
    for i in tqdm(range(rounds)):
        infection_times, source, obs_nodes = gen_nontrivial_cascade(
            g, p, q)
        r = mwu(g, gvs,
                source, obs_nodes, infection_times, o2src_time=None,
                active_method=active_method,
                reward_method=reward_method,
                eps=0.2,
                max_iter=g.num_vertices(),
                use_uninfected=True,
                debug=False)
        if r > 0:
            results.append(r)
    return results
Example #2
0
def experiment_mwu_n_rounds(rounds,
                            g,
                            p,
                            q,
                            epsilon,
                            sampling_method,
                            active_method,
                            reward_method,
                            n1=100,
                            seed=None):
    np.random.seed(seed)
    random.seed(seed)
    results = []
    gvs = get_gvs(g, p, n1)
    for i in tqdm(range(rounds)):
        infection_times, source, obs_nodes = gen_nontrivial_cascade(g, p, q)
        r = mwu(g,
                gvs,
                source,
                obs_nodes,
                infection_times,
                o2src_time=None,
                active_method=active_method,
                reward_method=reward_method,
                eps=0.2,
                max_iter=g.num_vertices(),
                use_uninfected=True,
                debug=False)
        if r > 0:
            results.append(r)
    return results
def test_full_observation_tree_region_mst(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='region_mst')
        assert get_rank_index(scores, source) == 0
def test_full_observation_grid_region_mst(grid_and_cascade):
    g = grid_and_cascade[0]
    for p in np.arange(0.5, 1.0, 0.1):
        print('p={}'.format(p))
        infection_times, source, obs_nodes = gen_nontrivial_cascade(g, p, 1.0)
        scores = tree_sizes_by_roots(g, obs_nodes, infection_times, source,
                                     method='region_mst')
        assert get_rank_index(scores, source) <= 0
Example #5
0
def test_full_observation_tree_tbfs(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='tbfs')
        assert get_rank_index(scores, source) == 0
Example #6
0
def test_full_observation_grid_tbfs(grid_and_cascade):
    g = grid_and_cascade[0]
    for p in np.arange(0.5, 1.0, 0.1):
        print('p={}'.format(p))
        infection_times, source, obs_nodes = gen_nontrivial_cascade(g, p, 1.0)
        scores = tree_sizes_by_roots(g,
                                     obs_nodes,
                                     infection_times,
                                     source,
                                     method='tbfs')
        assert get_rank_index(scores, source) <= 1.0
def source_likelihood_stat(g,
                           gvs,
                           p,
                           q,
                           N1,
                           estimation_method,
                           precond_method,
                           eps,
                           debug=True):
    sll_array = []
    sources = []
    dist_array = []

    if debug:
        iters = tqdm(range(N1))
    else:
        iters = range(N1)

    for i in iters:
        infection_times, source, obs_nodes = gen_nontrivial_cascade(g, p, q)
        sources.append(source)
        if estimation_method == 'steiner-tree-exact':
            if debug:
                print('using steiner tree exact')
            sll = best_tree_sizes(g, obs_nodes, infection_times)
        else:
            if debug:
                print(
                    'using steiner tree order ({})'.format(estimation_method))
            sll = tree_sizes_by_roots(g,
                                      obs_nodes,
                                      infection_times,
                                      source,
                                      method=estimation_method)

        winner = np.argmax(sll)
        dist_to_max_n = shortest_distance(g, source=source, target=winner)
        dist_array.append(dist_to_max_n)
        sll_array.append(sll)

    source_likelihood_array = np.array(sll_array, dtype=np.float64)
    source_llh = np.array(
        [source_likelihood_array[i, src] for i, src in enumerate(sources)])
    ranks = np.array([
        get_rank_index(source_likelihood_array[i, :], src)
        for i, src in enumerate(sources)
    ])

    return {
        'dist': pd.Series(dist_array).describe(),
        'mu[s]': pd.Series(source_llh).describe(),
        'rank': pd.Series(ranks).describe(),
    }
def source_likelihood_stat(g,
                           gvs, p, q, N1,
                           estimation_method,
                           precond_method,
                           eps,
                           debug=True):
    sll_array = []
    sources = []
    dist_array = []

    if debug:
        iters = tqdm(range(N1))
    else:
        iters = range(N1)

    for i in iters:
        infection_times, source, obs_nodes = gen_nontrivial_cascade(g, p, q)
        sources.append(source)
        if estimation_method == 'steiner-tree-exact':
            if debug:
                print('using steiner tree exact')
            sll = best_tree_sizes(g, obs_nodes, infection_times)
        else:
            if debug:
                print('using steiner tree order ({})'.format(estimation_method))
            sll = tree_sizes_by_roots(g, obs_nodes, infection_times, source,
                                      method=estimation_method)

        winner = np.argmax(sll)
        dist_to_max_n = shortest_distance(g, source=source, target=winner)
        dist_array.append(dist_to_max_n)
        sll_array.append(sll)

    source_likelihood_array = np.array(sll_array, dtype=np.float64)
    source_llh = np.array([source_likelihood_array[i, src]
                           for i, src in enumerate(sources)])
    ranks = np.array([get_rank_index(source_likelihood_array[i, :], src)
                      for i, src in enumerate(sources)])

    return {
        'dist': pd.Series(dist_array).describe(),
        'mu[s]': pd.Series(source_llh).describe(),
        'rank': pd.Series(ranks).describe(),
    }
Example #9
0
def test_full_observation_grid(grid_and_cascade):
    g = grid_and_cascade[0]
    for p in np.arange(0.5, 1.0, 0.1):
        infection_times, source, obs_nodes = gen_nontrivial_cascade(g, p, 1.0)
        scores = best_tree_sizes(g, obs_nodes, infection_times)
        assert get_rank_index(scores, source) == 0
Example #10
0
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, get_gvs(g, 0.5, 100), c, s, o
Example #11
0
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, get_gvs(g, 0.5, 100), c, s, o
def test_full_observation_grid(grid_and_cascade):
    g = grid_and_cascade[0]
    for p in np.arange(0.5, 1.0, 0.1):
        infection_times, source, obs_nodes = gen_nontrivial_cascade(g, p, 1.0)
        scores = best_tree_sizes(g, obs_nodes, infection_times)
        assert get_rank_index(scores, source) == 0