def eval_system(g, system=None, paras=None): seeds = [] for i in g.nodes_iter(): if g.node[i]['seed'] == 1: seeds.append(i) if system == 'integro': t = time.clock() ranks = integro.run_integro(g, seeds=seeds) print('eval time total integro {}'.format(time.clock() - t)) elif system == 'votetrust': t = time.clock() votetrust.vote_assignment(g, seeds) ranks = votetrust.vote_combined(g, paras.d) print('eval time total votetrust {}'.format(time.clock() - t)) elif system == 'sybilframe': t = time.clock() sybilframe.inferPosteriorsEdgeImproveNew(g) ranks = sybilframe.getRanks(g) print('eval time total sybilframe {}'.format(time.clock() - t)) real = [g.node[i]['label'] for i in range(len(g.nodes()))] b = benchmarks.Benchmarks(real, ranks) return b
def potential_capacity_per_distance(): seeds = (0, 500, 1000, 1500) results = [] for d in (0.8, 0.9, 0.95, 0.99): per_distance = defaultdict(list) for i in range(10): g = graph_creation.create_directed_smallWorld(2000, 40) votetrust.vote_assignment(g, seeds) votetrust.vote_propagation_mat(g, d) for n in g.nodes_iter(): shortest = 1000 for s in seeds: length = len(nx.shortest_path(g, s, n)) - 1 if length < shortest: shortest = length per_distance[shortest].append(g.node[n]['vote_capacity'] / (len(g.out_edges(n)) + 1)) for key, value in per_distance.items(): per_distance[key] = np.mean(per_distance[key]) result_d = list(per_distance.values()) print(result_d) results.append(result_d) with open('../results/votetrust/seed_attack_turnout.csv', 'w+') as f: w = csv.writer(f, lineterminator='\n') w.writerows(results)
def calc_trust_distribution(): g = graph_creation.create_directed_smallWorld(2000, 40) votetrust.vote_assignment(g, [0, 500, 1000]) d = 1 - 3 / len(g.nodes()) votetrust.vote_propagation_mat(g, d) votetrust.vote_aggregation(g) votes = [x[1]['vote_capacity'] for x in list(g.node.items())] with open('../results/votetrust/trustDist.csv', 'w+') as f: w = csv.writer(f, lineterminator='\n') w.writerow(votes)
def eval_most_common_friends(): results = [] g_0 = graph_creation.create_directed_smallWorld(2000, 40) ATTACKER = len(g_0.nodes()) for i in range(20): n = i * 5 + 1 results.append([n]) print('run') for j in range(10): g = g_0.copy() attacks_votetrust.attack_most_common_friends(g, n) votetrust.vote_assignment(g, [0, 500, 1000]) votetrust.vote_propagation_mat(g, d=0.99) votetrust.vote_aggregation(g) results[i].append(g.node[ATTACKER]['p']) with open('../results/votetrust/mostCommon.csv', 'w+') as f: w = csv.writer(f, lineterminator='\n') w.writerows(results)
def most_common(mode='strict'): results = [] g_0 = graph_creation.create_directed_smallWorld(2000, 40) nx.set_node_attributes(g_0, 'label', 0) for i in range(5): n = i * 5 + 1 results.append([n]) for j in range(1): g = g_0.copy() attacks_votetrust.attack_most_common_friends(g, n, mode=mode, boosting=True, dummies=[50]) ATTACKER = len(g.nodes()) - 1 votetrust.vote_assignment(g, [0, 90, 160]) votetrust.vote_propagation_mat(g, d=0.99) votetrust.vote_aggregation(g) results[i].append(g.node[ATTACKER]['p']) print(results) """