def random_graph_compare_LTM_analyse(n=100,
                                     p_edge=0.1,
                                     alpha=0.5,
                                     mc_greedy=100,
                                     k=5,
                                     is_random_weights=True):
    G = nx.erdos_renyi_graph(n, p_edge, directed=True)
    if is_random_weights:
        w_matrix = weight_matrix(G, alpha)
    else:
        w_matrix = degree_matrix(G, alpha)

    LTM = Live_Blocked_Model(G, w_matrix, from_model="LTM")

    random_a0 = random_active_set(LTM, k)
    degree_a0 = highest_degree_active_set(LTM, k)
    greedy_a0 = greedy_active_set(LTM, k, mc=mc_greedy)

    sets = [random_a0, degree_a0, greedy_a0]
    influences = list(map(lambda x: LTM.run_model(x, mc=1000), sets))

    print(sets)
    print(influences)

    return sets, G, w_matrix
Example #2
0
def config_compare_ICM(n=100, degree_dist=[], alpha=0.5, mc_greedy=100, k=5):

    G = nx.configuration_model(degree_dist)
    p_matrix = np.random.uniform(low=0, high=alpha, size=(n, n))

    ICM = Independent_Cascade_Model(G, p_matrix)

    random_a0 = random_active_set(ICM, k)
    degree_a0 = highest_degree_active_set(ICM, k)
    greedy_a0 = greedy_active_set(ICM, k, mc=mc_greedy)

    sets = [random_a0, degree_a0, greedy_a0]
    influences = map(lambda x: ICM.run_model(x, mc=1000), sets)

    return list(influences)
def compare_new_algorithms(n=100, p_edge=0.1, alpha=0.0, mc_greedy=1000, k=5):
    G = nx.erdos_renyi_graph(n, p_edge, directed=True)
    w_matrix = weight_matrix(G, alpha)

    LTM = Live_Blocked_Model(G, w_matrix, from_model="LTM")

    random_a0 = random_active_set(LTM, k)
    degree_a0 = highest_degree_active_set(LTM, k)
    greedy_a0 = greedy_active_set(LTM, k, mc=mc_greedy)
    avg_weight_a0 = highest_avg_weight_active_set(LTM, k)
    tot_weight_a0 = highest_total_weight_active_set(LTM, k)

    sets = [random_a0, degree_a0, greedy_a0, avg_weight_a0, tot_weight_a0]
    influences = map(lambda x: LTM.run_model(x, mc=1000), sets)

    return list(influences)
Example #4
0
def random_graph_compare_ICM_analyse(n=100, p_edge=0.1, alpha=0.5, mc_greedy=100, k=5, is_random_weights=True):
    G = nx.erdos_renyi_graph(n, p_edge, directed=True)
    if is_random_weights:
        p_matrix = np.random.uniform(low=0, high=alpha, size=(n, n))
    else:
        p_matrix = degree_matrix(G, alpha)

    ICM = Independent_Cascade_Model(G, p_matrix)

    random_a0 = random_active_set(ICM, k)
    degree_a0 = highest_degree_active_set(ICM, k)
    greedy_a0 = greedy_active_set(ICM, k, mc=mc_greedy)

    sets = [random_a0, degree_a0, greedy_a0]
    influences = list(map(lambda x: ICM.run_model(x, mc=1000), sets))

    print(sets)
    print(influences)

    return sets, G , p_matrix
Example #5
0
from model_objects.ICM import *
from model_objects.LBEM import *
from model_objects.LTM import *
from Active_Set_Selection.highest_degree import highest_degree_active_set

import time

p_edge = 0.2
n = 100
G = nx.erdos_renyi_graph(n, p_edge, directed=True)
w_matrix = degree_matrix(G, 1)

icm = Independent_Cascade_Model(G, w_matrix)
lbem_icm = Live_Blocked_Model(G, w_matrix, from_model="ICM")
lbem_ltm = Live_Blocked_Model(G, w_matrix, from_model="LTM")
ltm = Linear_Threshold_Model(G, w_matrix)
models = [icm, lbem_icm, lbem_ltm, ltm]

active_set = highest_degree_active_set(icm, 5)

for m in models:
    t0 = time.time()
    m.run_model(active_set, mc=100)
    t = time.time() - t0
    print(t, m.influence)
    print()