def t_selection_pipeline_directed_wiki(G,ts,num_partitions,fraction_t_to_keep=0.25):
    
    mis = []
    coups = []
    d_gws = []
    rt = []
    
    for t in ts:
        start = time.time()
        cost = sgw.directed_heat_kernel(G,t)
        mutual_info, d_gw, coup = process_sgwl_wiki(cost,database,num_nodes,num_partitions)
        mis.append(mutual_info)
        coups.append(coup)
        d_gws.append(d_gw)
        end = time.time()
        rt.append(end-start)

    print('Couplings Computed')
    
    coverages = []

    for j in range(len(ts)):
        coup = coups[j]
        partition = get_partition(coup)
        coverages.append(coverage(G,partition))
        
    num_to_keep = int(np.round(fraction_t_to_keep*len(ts)))
    
    good_t_max = ts[np.argsort(coverages)][-num_to_keep:]
    good_t_grad = ts[np.argsort(np.abs(np.gradient(coverages)))][:num_to_keep]
    
    return mis, coups, d_gws, good_t_max, good_t_grad, rt
# print('--- Noisy data | Symmetrized | SpecGWL | Best mutual information score: {:3.3f} | @t = {:3.3f} | average runtime per iteration = {:3.3f}'.format(max(mis), ts[np.argmax(mis)], np.mean(rt)))
scores['specgwl-symmetrized-noisy'] = max(mis)
runtimes['specgwl-symmetrized-noisy'] = sum(rt)
# avetimes['specgwl-symmetrized-noisy'] = np.mean(rt)

###########################################################
###########################################################
# Proposed method: SpecGWL (asymmetric)
########################################################### 
# Raw
mis = []
rt = []
ts = [10] #np.logspace(-3,1,10)
for t in ts:
    start = time.time()
    cost = sgw.directed_heat_kernel(dG,t)
    mutual_info = process_sgwl_wiki(cost,database,num_nodes,num_partitions);
    mis.append(mutual_info)
    end = time.time()
    rt.append(end-start)

# print('--- Raw data | Asymmetric | SpecGWL | Best mutual information score: {:3.3f} | @t = {:3.3f} | average runtime per iteration = {:3.3f}'.format(max(mis), ts[np.argmax(mis)], np.mean(rt)))
scores['specgwl-asymmetric-raw'] = max(mis)
runtimes['specgwl-asymmetric-raw'] = sum(rt)
# avetimes['specgwl-asymmetric-raw'] = np.mean(rt)

# Noisy
mis = []
rt = []
ts = [10] #np.logspace(-3,1,10)
for t in ts:
示例#3
0
    ##############################################
    # Training specGW
    ##############################################

    G = nx.gaussian_random_partition_graph(n=num_nodes, s=clique_size, v=8,
                                                   p_in=p_in, p_out=ps_out[pn], directed=True)

    p_s, cost_s, idx2node = DataIO.extract_graph_info(G)
    p_s = (p_s + 1) ** 0.01
    p_s /= np.sum(p_s)

    start = time.time()

    t = 10
    cost = sgw.directed_heat_kernel(G,t)

    modularities = []

    for j in num_clusts:
        p_t = GwGt.estimate_target_distribution({0: p_s}, dim_t=j)
        sub_costs, sub_probs, sub_idx2nodes, coup, d_gw = graph_partition_gd2(cost,
                                                                      p_s,
                                                                      p_t,
                                                                      idx2node,
                                                                      ot_dict)
        partition = get_partition(coup)
        modularities.append(modularity(G,partition))

    est_num_clust = num_clusts[np.argmax(modularities)]
# print('--- Noisy data | Symmetrized | SpecGWL | Best mutual information score: {:3.3f} | @t = {:3.3f} | average runtime per iteration = {:3.3f}'.format(max(mis), ts[np.argmax(mis)], np.mean(rt)))
scores['specgwl-symmetrized-noisy'] = max(mis)
runtimes['specgwl-symmetrized-noisy'] = sum(rt)
# avetimes['specgwl-symmetrized-noisy'] = np.mean(rt)

###########################################################
###########################################################
# Proposed method: SpecGWL (asymmetric)
###########################################################
# Raw
mis = []
rt = []
ts = [4]  #np.logspace(-1,2,100)
for t in ts:
    start = time.time()
    cost = sgw.directed_heat_kernel(dG, t).astype(np.float64)
    mutual_info = process_sgwl_wiki(cost,
                                    database,
                                    num_nodes,
                                    num_partitions,
                                    beta=2e-5)
    mis.append(mutual_info)
    end = time.time()
    rt.append(end - start)

# print('--- Raw data | Asymmetric | SpecGWL | Best mutual information score: {:3.3f} | @t = {:3.3f} | average runtime per iteration = {:3.3f}'.format(max(mis), ts[np.argmax(mis)], np.mean(rt)))
scores['specgwl-asymmetric-raw'] = max(mis)
runtimes['specgwl-asymmetric-raw'] = sum(rt)
# avetimes['specgwl-asymmetric-raw'] = np.mean(rt)

# Noisy