def filter(g, traceroutes, filters=['sh', 'loop', 'ex', 'vf', 'lp'], first_edge=True): logger.info('Traceroutes: %d', len(traceroutes)) # remove empty traces traceroutes = [x for x in traceroutes if len(x) > 0] logger.info('Non empty traceroutes: %d', (len(traceroutes))) traceroutes = [x for x in traceroutes if len(x) > 1] logger.info('Larger than one hop traceroutes: %d', (len(traceroutes))) # remove traces with unknown nodes traceroutes, _ = vft.trace_clean(g, traceroutes) logger.info('Ignored: %d', _) traceroutes = vft.trace_in_vertex_id(g, traceroutes) logger.info('Trace count: %d', len(traceroutes)) progress = progressbar1.AnimatedProgressBar(end=len(traceroutes), width=15) good_traceroutes = traceroutes[:] if 'sh' in filters: logger.debug('Remove short traces') good_traceroutes = [x for x in good_traceroutes if len(x) >= 3] logger.debug('Remained: %d', len(good_traceroutes)) if 'loop' in filters: logger.debug('Remove traces with loops') good_traceroutes = [ x for x in good_traceroutes if len(set(x)) == len(x) ] logger.debug('Remained: %d' % len(good_traceroutes)) if 'ex' in filters: logger.debug('Remove non existent traces') good_traceroutes = [ x for x in good_traceroutes if vft.trace_exists(g, x) ] logger.debug('Remained: %d', len(good_traceroutes)) if 'vf' in filters: logger.debug('Remove non vf traces') good_traceroutes = [ x for x in good_traceroutes if vft.is_valley_free(g, x) ] logger.debug('Remained: %d' % len(good_traceroutes)) if 'lp' in filters: logger.debug('Remove non lp traces') good_traceroutes = [ x for x in good_traceroutes if vft.is_local_preferenced(g, x, first_edge=first_edge) ] logger.debug('Remained: %d' % len(good_traceroutes)) # convert back node ids to node names good_traceroutes = [[g.vs[id]["name"] for id in trace] for trace in good_traceroutes] logger.debug(len(good_traceroutes)) return good_traceroutes
def test_trace_conversion(self): traceroutes = [['N0', 'N5', 'N4', 'N6'], ['N5', 'N5', 'N4', 'N5'], ['N5', 'N2', 'N4']] traceroutes_check = [[0, 5, 4, 6], [5, 5, 4, 5], [5, 2, 4]] trace_id = vft.trace_in_vertex_id(self.sample_graph, traceroutes) self.assertEqual(traceroutes_check, trace_id) trace_back = vft.trace_in_vertex_name(self.sample_graph, trace_id) self.assertEqual(traceroutes, trace_back)
def test_trace_conversion_error(self): fake_trace = [ ['FAKE', 'FAKE1'], ] fake_trace_id = [ [2, 4, 55], ] with self.assertRaises(ValueError): _ = vft.trace_in_vertex_id(self.sample_graph, fake_trace) with self.assertRaises(IndexError): _ = vft.trace_in_vertex_name(self.sample_graph, fake_trace_id)
def purify(g, meta, out, count=1000): results = list() results2 = list() results3 = list() all_vf = 0 all_nonvf = 0 all_vf_closeness = 0 all_nonvf_closeness = 0 short_results = list() short_results2 = list() short_results3 = list() all_short_vf = 0 all_short_nonvf = 0 all_short_vf_closeness = 0 all_short_nonvf_closeness = 0 long_results = list() long_results2 = list() long_results3 = list() all_long_vf = 0 all_long_nonvf = 0 all_long_vf_closeness = 0 all_long_nonvf_closeness = 0 # remove traces with already calculated all_path logger.warn('[r]ONLY NOT FILLED PATHS[/]') meta = [x for x in meta if not helpers.ALL_PATH_COUNT in x] # traces with a maximum stretch logger.warn('[r]!!!ONLY WITH LOW STRETCH[/]') meta = [x for x in meta if x[helpers.STRETCH] < 4] # shorter meta records logger.warn('[r]!!!ONLY SHORT TRACES[/]') meta = [x for x in meta if len(x[helpers.TRACE]) < 5] meta_map = {tuple(x[helpers.TRACE]): x for x in meta} # traceroutes = [x for x in meta if x[TRACE_LEN] == x[SH_LEN]] logger.info('All trace count: %d' % len(meta)) tr_count = min(len(meta), count) meta = random.sample(meta, tr_count) logger.info('Chosen trace count: %d' % len(meta)) real_vf = [x for x in meta if x[helpers.IS_VF] == 1] real_nonvf = [x for x in meta if x[helpers.IS_VF] == 0] real_vf_closeness = [x for x in meta if x[helpers.IS_VF_CLOSENESS] == 1] real_nonvf_closeness = [x for x in meta if x[helpers.IS_VF_CLOSENESS] == 0] logger.info('Real vf: %f[%d]' % ((len(real_vf)/float(len(meta)), len(real_vf)))) logger.info('Real nonvf: %f[%d]' % ((len(real_nonvf)/float(len(meta)), len(real_nonvf)))) logger.info('Real vf closeness: %f[%d]' % ((len(real_vf_closeness)/float(len(meta)), len(real_vf_closeness)))) logger.info('Real nonvf closeness: %f[%d]' % ((len(real_nonvf_closeness)/float(len(meta)), len(real_nonvf_closeness)))) logger.info('Remove unknown traces. Trace count before: %d' % len(meta)) traceroutes = [x[helpers.TRACE] for x in meta] traceroutes, ignored = vft.trace_clean(g, traceroutes) logger.info('Traceroutes after: %d. Ignored: %d' % (len(traceroutes), ignored)) traceroutes = vft.trace_in_vertex_id(g, traceroutes) progress = progressbar1.AnimatedProgressBar(end=len(traceroutes), width=15) for trace in traceroutes: progress += 1 progress.show_progress() for x in range(0, g.vcount()): g.vs[x]['traces'] = dict() s, t = trace[0], trace[-1] sh_path = g.get_all_shortest_paths(s, t, mode=i.OUT) all_path = helpers.dfs_mark(copy.deepcopy(g), s, t, len(trace)) # if len(sh_path) != len(all_path): # print len(sh_path) # print len(all_path) # print s, t # sanity check for x in all_path: if x[0] != s or x[-1] != t: logger.error('ALERT') if len(set([tuple(x) for x in all_path])) != len(all_path): logger.error('LENGTH ALERT') logger.error('%s' % len(all_path)) logger.error('%s' % len(set([tuple(x) for x in all_path]))) logger.error('%s' % sorted(all_path)) long_path = [x for x in all_path if len(x) == len(trace)] short_path = [x for x in all_path if len(x) < len(trace)] named_trace = [g.vs[x]['name'] for x in trace] extra_meta = { helpers.ALL_PATH_COUNT: len(all_path), helpers.SAME_LONG_PATH_COUNT: len(long_path), helpers.SHORTER_PATH_COUNT: len(short_path) } meta_map[tuple(named_trace)].update(extra_meta) vf_count = sum([1 if vft.is_valley_free(g, x, vfmode=vft.PRELABELED) else 0 for x in all_path]) nonvf = len(all_path) - vf_count vf_closeness_count = sum([1 if vft.is_valley_free(g, x, vfmode=vft.CLOSENESS) else 0 for x in all_path]) nonvf_closeness = len(all_path) - vf_closeness_count tmp = [1 if vft.is_valley_free(g, x, vfmode=vft.PRELABELED) else 0 for x in short_path] short_vf_count = sum(tmp) short_nonvf = len(tmp) - short_vf_count tmp = [1 if vft.is_valley_free(g, x, vfmode=vft.CLOSENESS) else 0 for x in short_path] short_vf_closeness_count = sum(tmp) short_nonvf_closeness = len(tmp) - short_vf_closeness_count tmp = [1 if vft.is_valley_free(g, x, vfmode=vft.PRELABELED) else 0 for x in long_path] long_vf_count = sum(tmp) long_nonvf = len(tmp) - long_vf_count tmp = [1 if vft.is_valley_free(g, x, vfmode=vft.CLOSENESS) else 0 for x in long_path] long_vf_closeness_count = sum(tmp) long_nonvf_closeness = len(tmp) - long_vf_closeness_count extra_meta = { helpers.ALL_PATH_VF_COUNT: vf_closeness_count, helpers.SAME_LONG_PATH_VF_COUNT: long_vf_closeness_count, helpers.SHORTER_PATH_VF_COUNT: short_vf_closeness_count } meta_map[tuple(named_trace)].update(extra_meta) all_vf += vf_count all_nonvf += nonvf all_vf_closeness += vf_closeness_count all_nonvf_closeness += nonvf_closeness all_long_vf += long_vf_count all_long_nonvf += long_nonvf all_long_vf_closeness += long_vf_closeness_count all_long_nonvf_closeness += long_nonvf_closeness all_short_vf += short_vf_count all_short_nonvf += short_nonvf all_short_vf_closeness += short_vf_closeness_count all_short_nonvf_closeness += short_nonvf_closeness results.append(vf_count / float(len(all_path))) results3.append(vf_closeness_count / float(len(all_path))) if len(all_path) > 1: results2.append(vf_count / float(len(all_path))) long_results.append(long_vf_count / float(len(long_path))) long_results3.append(long_vf_closeness_count / float(len(long_path))) if len(long_path) > 1: long_results2.append(long_vf_count / float(len(long_path))) if len(short_path) > 0: short_results.append(short_vf_count / float(len(short_path))) short_results3.append(short_vf_closeness_count / float(len(short_path))) else: pass # short_results.append(0) # short_results3.append(0) if len(short_path) > 1: short_results2.append(short_vf_count / float(len(short_path))) # save mofified meta meta_mod = [x for x in meta_map.itervalues()] helpers.save_to_json(out, meta_mod) # print results print 'ALL' print 'VF count: %d' % all_vf print 'VF CLOSENESS count: %d' % all_vf_closeness print 'Non vf count: %d' % all_nonvf print 'Non vf CLOSENESS count: %d' % all_nonvf_closeness print 'VF perc: %f' % (all_vf/float(all_vf + all_nonvf)) print 'VF CLOSENESS perc: %f' % (all_vf_closeness/float(all_vf_closeness + all_nonvf_closeness)) print 'Mean VF prob: %f' % np.mean(results) print 'Mean VF CLOSENESS prob: %f' % np.mean(results3) print 'Mean VF2 prob: %f' % np.mean(results2) print '==========' print 'SHORT' print 'VF count: %d' % all_short_vf print 'VF CLOSENESS count: %d' % all_short_vf_closeness print 'Non vf count: %d' % all_short_nonvf print 'Non vf CLOSENESS count: %d' % all_short_nonvf_closeness if all_short_vf + all_short_nonvf > 0: print 'VF perc: %f' % (all_short_vf/float(all_short_vf + all_short_nonvf)) if all_short_vf_closeness + all_short_nonvf_closeness > 0: print 'VF CLOSENESS perc: %f' % (all_short_vf_closeness/float(all_short_vf_closeness + all_short_nonvf_closeness)) print 'Mean VF prob: %f' % np.mean(short_results) print 'Mean VF CLOSENESS prob: %f' % np.mean(short_results3) print 'Mean VF2 prob: %f' % np.mean(short_results2) print '=-----------------' print 'LONG' print 'VF count: %d' % all_long_vf print 'VF CLOSENESS count: %d' % all_long_vf_closeness print 'Non vf count: %d' % all_long_nonvf print 'Non vf CLOSENESS count: %d' % all_long_nonvf_closeness print 'VF perc: %f' % (all_long_vf/float(all_long_vf + all_long_nonvf)) print 'VF CLOSENESS perc: %f' % (all_long_vf_closeness/float(all_long_vf_closeness + all_long_nonvf_closeness)) print 'Mean VF prob: %f' % np.mean(long_results) print 'Mean VF CLOSENESS prob: %f' % np.mean(long_results3) print 'Mean VF2 prob: %f' % np.mean(long_results2)
def filter(g, traceroutes): results = list() # remove traces with unknown nodes traceroutes = vft.trace_in_vertex_id(g, traceroutes) progress = progressbar1.AnimatedProgressBar(end=len(traceroutes), width=15) for trace in traceroutes: progress += 1 progress.show_progress() if not vft.trace_exists(g, trace): print 'BUG?' continue for x in range(0, g.vcount()): g.vs[x]['traces'] = dict() trace = tuple(trace) s, t = trace[0], trace[-1] sh_len = g.shortest_paths(s, t, mode=i.ALL)[0][0] sh_len += 1 # igraph's hop count to node count all_routes = helpers.dfs_mark(g, s, t, sh_len + 1) # all_routes2 = helpers.dfs_simple(g, s, t, sh_len + 1, ()) # if set(all_routes) - set(all_routes2) != set(all_routes2) - set(all_routes): # print 'AJAJAJ' # print all_routes # print '----------' # print all_routes2 sh_routes = [x for x in all_routes if len(x) == sh_len] all_vf_routes = [x for x in all_routes if vft.is_valley_free(g, x)] prediction_set = set(sh_routes) | set(all_vf_routes) result = [ trace, len(trace), sh_len, len(sh_routes), trace in sh_routes, len(all_vf_routes), trace in all_vf_routes, len(all_routes), trace in all_routes, len(prediction_set), trace in prediction_set, vft.is_valley_free(g, trace), # sh_routes, all_vf_routes, all_routes, vft.trace_to_string(g, trace) ] results.append(result) print >> sys.stderr, ( 'TRACE\tTRACE_LEN\tSH_LEN', '\t#SH_ROUTE\tOK', '\t#ALL_VF\tOK', '\t#ALL_ROUTE\tOK', '\t#PREDICTION_SET\tOK', '\tIS_VF', # '\tSH_ROUTES\tALL_VF_ROUTES\tALL_ROUTE', '\tTRACE_STR') for result in results: result = [str(r) for r in result] print >> sys.stderr, '\t'.join(result) return results
def purify(g, meta_original, out, count=1000, try_per_race=1, show_progress=False, with_lp=True): empty = 0 # remove traces with already calculated random paths logger.warn('[r]ONLY NOT FILLED PATHS[/]') meta_filled = [ x for x in meta_original if helpers.RANDOM_WALK_RUN_COUNT not in x ] # Filter if interested only in routes of stretch 1 # meta_filled = [x for x in meta_original # if x[helpers.TRACE_LEN]-x[helpers.SH_LEN] == 1] ## traces with a maximum stretch # logger.warn('[r]!!!ONLY WITH STRETCH[/]') # meta = [x for x in meta if x[helpers.STRETCH] > -1] # # shorter meta records # logger.warn('[r]!!!ONLY SHORT TRACES[/]') # meta = [x for x in meta if len(x[helpers.TRACE]) < 5] # meta_map = {tuple(x[helpers.TRACE]): x for x in meta_filled} logger.info('All trace count: %d' % len(meta_filled)) tr_count = min(len(meta_filled), count) meta_random = random.sample(meta_filled, tr_count) logger.info('Chosen subset count: %d' % len(meta_random)) # real_vf_degree = [x for x in meta_random if x[helpers.IS_VF_DEGREE] == 1] # real_nonvf_degree = [x for x in meta_random if x[helpers.IS_VF_DEGREE] == 0] # assert len(real_nonvf_degree) == tr_count - len(real_vf_degree) # real_vf_prelabeled = [x for x in meta_random if x[helpers.IS_VF_PRELABELED] == 1] # real_nonvf_prelabeled = [x for x in meta_random if x[helpers.IS_VF_PRELABELED] == 0] # assert len(real_nonvf_prelabeled) == tr_count - len(real_vf_prelabeled) # real_vf_closeness = [x for x in meta_random if x[helpers.IS_VF_CLOSENESS] == 1] # real_nonvf_closeness = [x for x in meta_random if x[helpers.IS_VF_CLOSENESS] == 0] # assert len(real_nonvf_closeness) == tr_count - len(real_vf_closeness) # logger.info('Real vf degree: %f[%d]' % ((len(real_vf_degree) / float(tr_count), # len(real_vf_degree)))) # logger.info('Real nonvf degree: %f[%d]' % ((len(real_nonvf_degree) / float(tr_count), # len(real_nonvf_degree)))) # logger.info('Real vf prelabeled: %f[%d]' % ((len(real_vf_prelabeled) / float(tr_count), # len(real_vf_prelabeled)))) # logger.info('Real nonvf prelabeled: %f[%d]' % ((len(real_nonvf_prelabeled) / float(tr_count), # len(real_nonvf_prelabeled)))) # logger.info('Real vf closeness: %f[%d]' % ((len(real_vf_closeness)/float(tr_count), len(real_vf_closeness)))) # logger.info('Real nonvf closeness: %f[%d]' % ((len(real_nonvf_closeness)/float(tr_count), len(real_nonvf_closeness)))) # traceroutes = [x[helpers.TRACE] for x in meta_random] # traceroutes = vft.trace_in_vertex_id(g, traceroutes) try: meta_random[0][helpers.TRACE] except Exception: meta_random = [{helpers.TRACE: x} for x in meta_random] progress = progressbar1.DummyProgressBar(end=10, width=15) if show_progress: progress = progressbar1.AnimatedProgressBar(end=len(meta_random), width=15) stretch_list = [] max_stretch = max( [x[helpers.TRACE_LEN] - x[helpers.SH_LEN] for x in meta_random]) for stretch in range(0, max_stretch + 1): metas = [ x for x in meta_random if x[helpers.TRACE_LEN] - x[helpers.SH_LEN] == stretch ] stretch_list.extend(list(repeat(stretch, len(metas)))) # print(stretch_list) lenghts = random.shuffle(stretch_list) strx_array = [] for idx, trace_meta in enumerate(meta_random): progress += 1 progress.show_progress() # print(trace_meta[helpers.TRACE]) shl = trace_meta[helpers.SH_LEN] trace = vft.trace_in_vertex_id(g, [ trace_meta[helpers.TRACE], ]) if len(trace) != 1: print 'PROBLEM' print trace_meta continue trace = trace[0] # print(trace) random_walk_closeness_route_vf = 0 random_walk_closeness_route_lp_soft = 0 random_walk_closeness_route_lp_hard = 0 random_walk_degree_route_vf = 0 random_walk_degree_route_lp_soft = 0 random_walk_degree_route_lp_hard = 0 random_walk_prelabeled_route_vf = 0 random_walk_prelabeled_route_lp_soft = 0 random_walk_prelabeled_route_lp_hard = 0 s, t = trace[0], trace[-1] for counter in xrange(0, try_per_race): # random_path = helpers.random_route_walk(g, s, t, len(trace)) # Modified random_path = helpers.random_route_walk( g, s, t, shl + stretch_list[idx]) # Modified if len(random_path) == 0: empty += 1 if vft.is_valley_free(g, random_path, vfmode=vft.CLOSENESS): random_walk_closeness_route_vf += 1 if (len(random_path) == shl + 1): strx_array.append(1) if with_lp: lp_soft = vft.is_local_preferenced(g, random_path, first_edge=True, vfmode=vft.CLOSENESS) lp_hard = vft.is_local_preferenced(g, random_path, first_edge=False, vfmode=vft.CLOSENESS) if lp_soft: random_walk_closeness_route_lp_soft += 1 if lp_hard: random_walk_closeness_route_lp_hard += 1 else: if (len(random_path) == shl + 1): strx_array.append(0) # if vft.is_valley_free(g, random_path, vfmode=vft.DEGREE): # random_walk_degree_route_vf += 1 # if with_lp: # lp_soft = vft.is_local_preferenced(g, random_path, # first_edge=True, # vfmode=vft.DEGREE) # lp_hard = vft.is_local_preferenced(g, random_path, # first_edge=False, # vfmode=vft.DEGREE) # if lp_soft: # random_walk_degree_route_lp_soft += 1 # if lp_hard: # random_walk_degree_route_lp_hard += 1 # if vft.is_valley_free(g, random_path, vfmode=vft.PRELABELED): # random_walk_prelabeled_route_vf += 1 # if with_lp: # lp_soft = vft.is_local_preferenced(g, random_path, # first_edge=True, # vfmode=vft.PRELABELED) # lp_hard = vft.is_local_preferenced(g, random_path, # first_edge=False, # vfmode=vft.PRELABELED) # if lp_soft: # random_walk_prelabeled_route_lp_soft += 1 # if lp_hard: # random_walk_prelabeled_route_lp_hard += 1 # sanity check # if random_path[0] != s or random_path[-1] != t: # logger.error('ALERT') if len(random_path) != len(set(random_path)): logger.error('LENGTH ERROR') extra_meta = { helpers.RANDOM_WALK_RUN_COUNT: try_per_race, helpers.RANDOM_WALK_VF_CLOSENESS_ROUTE: random_walk_closeness_route_vf, helpers.RANDOM_WALK_VF_DEGREE_ROUTE: random_walk_degree_route_vf, helpers.RANDOM_WALK_VF_PRELABELED_ROUTE: random_walk_prelabeled_route_vf, } if with_lp: extra_meta.update({ helpers.RANDOM_WALK_LP_SOFT_CLOSENESS_ROUTE: random_walk_closeness_route_lp_soft, helpers.RANDOM_WALK_LP_HARD_CLOSENESS_ROUTE: random_walk_closeness_route_lp_hard, helpers.RANDOM_WALK_LP_SOFT_DEGREE_ROUTE: random_walk_degree_route_lp_soft, helpers.RANDOM_WALK_LP_HARD_DEGREE_ROUTE: random_walk_degree_route_lp_hard, helpers.RANDOM_WALK_LP_SOFT_PRELABELED_ROUTE: random_walk_prelabeled_route_lp_soft, helpers.RANDOM_WALK_LP_HARD_PRELABELED_ROUTE: random_walk_prelabeled_route_lp_hard }) trace_meta.update(extra_meta) ## save modified meta # all meta_* get only references from meta_original helpers.save_to_json(out, meta_random) # meta_mod = [x for x in meta_map.itervalues()] # helpers.save_to_json(out, meta_mod) # calculate results # real_vf = [x[helpers.IS_VF_CLOSENESS] for x in meta_random] # real_vf_ratio = np.mean(real_vf) random_walk_vf_ratio_per_element = [ x[helpers.RANDOM_WALK_VF_CLOSENESS_ROUTE] / x[helpers.RANDOM_WALK_RUN_COUNT] for x in meta_random ] random_walk_vf_ratio = np.mean(random_walk_vf_ratio_per_element) # print results logger.info('') logger.info('Empty: %d' % empty) logger.info('Tested trace count: %d' % len(meta_random)) # logger.info('VF ratio in tested traces: %f' % real_vf_ratio) logger.info('VF ratio in random walks: %f' % random_walk_vf_ratio) logger.info('VF ratio in random walks for path stretch 1: %f' % np.mean(strx_array))
def purify(g, traceroutes, flags, show_progress=False): results = list() # remove traces with unknown nodes traceroutes = vft.trace_in_vertex_id(g, traceroutes) # generate valley-free graph if flags[FLAG_PRELABELED]: logger.info('Generate VF_G_PRE') vf_g_pre = vft.convert_to_vf(g, vfmode=vft.PRELABELED) else: logger.info('Skip prelabeled graph') if flags[FLAG_DEGREE]: logger.info('Generate VF_G_DEGREE') vf_g_degree = vft.convert_to_vf(g, vfmode=vft.DEGREE) else: logger.info('Skip degree graph') if flags[FLAG_CLOSENESS]: logger.info('Generate VF_G_CLOSENESS') vf_g_closeness = vft.convert_to_vf(g, vfmode=vft.CLOSENESS) else: logger.info('Skip closeness graph') progress = progressbar1.DummyProgressBar(end=10, width=15) if show_progress: progress = progressbar1.AnimatedProgressBar(end=len(traceroutes), width=15) for trace in traceroutes: progress += 1 progress.show_progress() logger.debug('Current trace: %s' % ([g.vs[x]['name'] for x in trace])) if len(trace) == 1: continue s, t = trace[0], trace[-1] is_vf_prelabeled = -1 is_lp_prelabeled_hard = -1 is_lp_prelabeled_soft = -1 is_vf_degree = -1 is_lp_degree_hard = -1 is_lp_degree_soft = -1 is_vf_closeness = -1 is_lp_closeness_hard = -1 is_lp_closeness_soft = -1 trace_len = len(trace) sh_len = g.shortest_paths(s, t, mode=i.OUT)[0][0] sh_len += 1 # convert hop count to node Counter if flags[FLAG_PRELABELED]: is_vf_prelabeled = vft.is_valley_free(g, trace, vft.PRELABELED) is_vf_prelabeled = int(is_vf_prelabeled) if is_vf_prelabeled: if flags[FLAG_LP_SOFT]: lp_soft = vft.is_local_preferenced(g, trace, vf_g=vf_g_pre, first_edge=True, vfmode=vft.PRELABELED) is_lp_prelabeled_soft = 1 if lp_soft else 0 else: is_lp_prelabeled_soft = -1 if flags[FLAG_LP_HARD]: lp_hard = vft.is_local_preferenced(g, trace, vf_g=vf_g_pre, first_edge=False, vfmode=vft.PRELABELED) is_lp_prelabeled_hard = 1 if lp_hard else 0 else: is_lp_prelabeled_hard = -1 if flags[FLAG_DEGREE]: is_vf_degree = vft.is_valley_free(g, trace, vft.DEGREE) is_vf_degree = int(is_vf_degree) if is_vf_degree: if flags[FLAG_LP_SOFT]: lp_soft = vft.is_local_preferenced(g, trace, vf_g=vf_g_degree, first_edge=True, vfmode=vft.DEGREE) is_lp_degree_soft = 1 if lp_soft else 0 else: is_lp_degree_soft = -1 if flags[FLAG_LP_HARD]: lp_hard = vft.is_local_preferenced(g, trace, vf_g=vf_g_degree, first_edge=False, vfmode=vft.DEGREE) is_lp_degree_hard = 1 if lp_hard else 0 else: is_lp_degree_hard = -1 if flags[FLAG_CLOSENESS]: is_vf_closeness = vft.is_valley_free(g, trace, vft.CLOSENESS) is_vf_closeness = int(is_vf_closeness) if is_vf_closeness: if flags[FLAG_LP_SOFT]: lp_soft = vft.is_local_preferenced(g, trace, vf_g=vf_g_closeness, first_edge=True, vfmode=vft.CLOSENESS) is_lp_closeness_soft = 1 if lp_soft else 0 else: is_lp_closeness_soft = -1 if flags[FLAG_LP_HARD]: lp_hard = vft.is_local_preferenced(g, trace, vf_g=vf_g_closeness, first_edge=False, vfmode=vft.CLOSENESS) is_lp_closeness_hard = 1 if lp_hard else 0 else: is_lp_closeness_hard = -1 if False: sh_vf_len = vft.get_shortest_vf_route(g, s, t, mode='vf', vf_g=vf_g_pre, _all=True, vfmode=vft.PRELABELED) # ugy tunik, mintha nem mindig lenne pontos? fentartassal kezelendo # ez az ertek azert is kerult bele, hogy ellenorizzuk in_vf_prediction = 1 if sh_vf_len and trace in sh_vf_len else 0 else: sh_vf_len = -1 in_vf_prediction = -1 sh_vf_len = len(sh_vf_len[0]) if isinstance(sh_vf_len, list) else -1 percentage_stretch = trace_len / float(sh_len) named_trace = [g.vs[_id]["name"] for _id in trace] result = { helpers.TRACE: named_trace, helpers.TRACE_LEN: trace_len, helpers.SH_LEN: sh_len, helpers.SH_VF_LEN: sh_vf_len, helpers.IS_VF_PRELABELED: is_vf_prelabeled, helpers.IS_VF_DEGREE: is_vf_degree, helpers.IS_VF_CLOSENESS: is_vf_closeness, helpers.HOP_STRETCH: trace_len - sh_len, helpers.PERC_STRETCH: percentage_stretch, helpers.IN_VF_PRED: in_vf_prediction, helpers.IS_LP_SOFT_PRELABELED: is_lp_prelabeled_soft, helpers.IS_LP_HARD_PRELABELED: is_lp_prelabeled_hard, helpers.IS_LP_SOFT_DEGREE: is_lp_degree_soft, helpers.IS_LP_HARD_DEGREE: is_lp_degree_hard, helpers.IS_LP_SOFT_CLOSENESS: is_lp_closeness_soft, helpers.IS_LP_HARD_CLOSENESS: is_lp_closeness_hard, } results.append(result) # print >> sys.stderr, ('TRACE\tTRACE_LEN\tSH_LEN\tSH_VF_LEN\tIS_VF', # '\tSTRETCH\tIN_VF_PREDICTION\tIS_LP_F\tIS_LP_ALL') # for result in results: # result = [str(r) for r in result] # print >> sys.stderr, '\t'.join(result) # statistic = statistics.purify(g, results, # 'nc+ec+tc+rt+vf+vf_closeness+pred+lp_soft_prelabeled+lp_hard_prelabeled+lp_soft_degree+lp_hard_degree+lp_soft_closeness+lp_hard_closeness'.split('+')) # statistics.stat_printer(statistic) return results
def purify(g, meta, flags, try_per_trace, show_progress=False): # generate valley-free graph if flags[FLAG_PRELABELED]: logger.info('Generate VF_G_PRE') vf_g_pre = vft.convert_to_vf(g, vfmode=vft.PRELABELED) else: logger.info('Skip prelabeled graph') if flags[FLAG_DEGREE]: logger.info('Generate VF_G_DEGREE') vf_g_degree = vft.convert_to_vf(g, vfmode=vft.DEGREE) else: logger.info('Skip degree graph') if flags[FLAG_CLOSENESS]: logger.info('Generate VF_G_CLOSENESS') vf_g_closeness = vft.convert_to_vf(g, vfmode=vft.CLOSENESS) else: logger.info('Skip closeness graph') # Randomize stretch dispersion stretches = [x[helpers.HOP_STRETCH] for x in meta] # a veletlen stretchek az eredeti stretchek veletlen, nem # visszateveses mintavetelezese. Mindez annyiszor, ahany # veletlen utat akarunk generalni minden valos trace vegpontja # kozott. stretch_list = [random.sample(stretches, len(stretches)) for x in xrange(0, try_per_trace)] # A kovetkezo ciklusban minden meta sorhoz rogton kiszamolunk # annyi random utat, amennyit parameterben megadtunk. Ehhez at kell # alakitani a stretch lista strukturat, hogy minden elem egy meta sorhoz # tartalmazza a random stretch ertekeket # # Pelda: elozo lepesnel kijott ez: [ [1,2,3,4], [2,4,1,3], [3,1,4,2] ] # vagyis elso lepesben a metaban tarolt tracek rendre 1,2,3,4 stretchet # kell felvegyenek, a masodikban 2,4,1,3 stb. A ciklusban viszont a meta # elso elemehez rogton ki akarjuk szamolni a veletlen stretchekhez tartozo # random utakat, vagyis [ [1,2,3], [2,4,1], [3,1,4], [4,3,2] ] formaban # van szukseg az ertekekre stretch_list = zip(*stretch_list) progress = progressbar1.DummyProgressBar(end=10, width=15) if show_progress: progress = progressbar1.AnimatedProgressBar(end=len(meta), width=15) for idx, record in enumerate(meta): progress += 1 progress.show_progress() trace = vft.trace_in_vertex_id(g, [record[helpers.TRACE], ]) if len(trace) != 1: print 'PROBLEM' print record continue trace = trace[0] if len(trace) == 1: continue sh_len = record[helpers.SH_LEN] s, t = trace[0], trace[-1] is_vf_prelabeled_l = [] is_lp_prelabeled_hard_l = [] is_lp_prelabeled_soft_l = [] is_vf_degree_l = [] is_lp_degree_hard_l = [] is_lp_degree_soft_l = [] is_vf_closeness_l = [] is_lp_closeness_hard_l = [] is_lp_closeness_soft_l = [] stretch_dist = stretch_list[idx] real_stretch_dist = [] for current_stretch in stretch_dist: random_length = sh_len + current_stretch random_path = helpers.random_route_walk(g, s, t, random_length) real_stretch_dist.append(len(random_path) - sh_len) if len(random_path) == 0: empty += 1 if flags[FLAG_PRELABELED]: (is_vf_prelabeled, is_lp_prelabeled_soft, is_lp_prelabeled_hard) = vf_attributes(g,random_path, vft.PRELABELED, flags[FLAG_LP_SOFT], flags[FLAG_LP_HARD], vf_g_pre) is_vf_prelabeled_l.append(is_vf_prelabeled) is_lp_prelabeled_soft_l.append(is_lp_prelabeled_soft) is_lp_prelabeled_hard_l.append(is_lp_prelabeled_hard) if flags[FLAG_DEGREE]: (is_vf_degree, is_lp_degree_soft, is_lp_degree_hard) = vf_attributes(g, random_path, vft.DEGREE, flags[FLAG_LP_SOFT], flags[FLAG_LP_HARD], vf_g_degree) is_vf_degree_l.append(is_vf_degree) is_lp_degree_soft_l.append(is_lp_degree_soft) is_lp_degree_hard_l.append(is_lp_degree_hard) if flags[FLAG_CLOSENESS]: (is_vf_closeness, is_lp_closeness_soft, is_lp_closeness_hard) = vf_attributes(g, random_path, vft.CLOSENESS, flags[FLAG_LP_SOFT], flags[FLAG_LP_HARD], vf_g_closeness) is_vf_closeness_l.append(is_vf_closeness) is_lp_closeness_soft_l.append(is_lp_closeness_soft) is_lp_closeness_hard_l.append(is_lp_closeness_hard) result = { helpers.RANDOM_GULYAS_WALK_ROUTES_RQ_STRETCH: stretch_dist, helpers.RANDOM_GULYAS_WALK_ROUTES_STRETCH: real_stretch_dist, helpers.RANDOM_GULYAS_WALK_ROUTES_VF_PRELABELED: is_vf_prelabeled_l, helpers.RANDOM_GULYAS_WALK_ROUTES_VF_DEGREE: is_vf_degree_l, helpers.RANDOM_GULYAS_WALK_ROUTES_VF_CLOSENESS: is_vf_closeness_l, helpers.RANDOM_GULYAS_WALK_ROUTES_LP_SOFT_PRELABELED: is_lp_prelabeled_soft_l, helpers.RANDOM_GULYAS_WALK_ROUTES_LP_HARD_PRELABELED: is_lp_prelabeled_hard_l, helpers.RANDOM_GULYAS_WALK_ROUTES_LP_SOFT_DEGREE: is_lp_degree_soft_l, helpers.RANDOM_GULYAS_WALK_ROUTES_LP_HARD_DEGREE: is_lp_degree_hard_l, helpers.RANDOM_GULYAS_WALK_ROUTES_LP_SOFT_CLOSENESS: is_lp_closeness_soft_l, helpers.RANDOM_GULYAS_WALK_ROUTES_LP_HARD_CLOSENESS: is_lp_closeness_hard_l, } record.update(result)
def purify(g, meta, filters): results = dict() traceroutes = [x[helpers.TRACE] for x in meta] if 'cc' in filters: results['cc'] = g.transitivity_undirected(mode=igraph.TRANSITIVITY_ZERO) if 'ad' in filters: results['ad'] = g.average_path_length(directed=False, unconn=True) if 'nc' in filters: results['nc'] = g.vcount() if 'ec' in filters: results['ec'] = g.ecount() if 'rc' in filters: k = 20 scores = g.degree() indices = range(g.vcount()) indices.sort(key=scores.__getitem__) e_k = [x for x in g.es if g.degree(x.source) >= k and g.degree(x.target) >= 50] e_k2 = float(2 * len(e_k)) n_k = float(len([x for x in g.vs if g.degree(x) >= k])) fi_k = e_k2 / (n_k * (n_k - 1)) results['rc'] = fi_k # remove traces with unknown nodes before_caida = len(traceroutes) traceroutes = vft.trace_in_vertex_id(g, traceroutes) if 'tc' in filters: results['tc'] = len(traceroutes) if 'tl' in filters: results['tl'] = np.mean([len(x) for x in traceroutes]) if 'tml' in filters: results['tml'] = max([len(x) for x in traceroutes]) results['tml_sentence'] = vft.trace_in_vertex_name(g, [x for x in traceroutes if len(x) == results['tml']])[0] if 'tsl' in filters: results['tsl'] = min([len(x) for x in traceroutes]) results['tsl_sentence'] = vft.trace_in_vertex_name(g, [x for x in traceroutes if len(x) == results['tsl']])[0] if 'rt' in filters: results['rt'] = before_caida - len(traceroutes) if 'vf_prelabeled' in filters: results['vf_prelabeled'] = len([x for x in meta if x[helpers.IS_VF_PRELABELED] == 1]) if 'vf_degree' in filters: results['vf_degree'] = len([x for x in meta if x[helpers.IS_VF_DEGREE] == 1]) if 'vf_closeness' in filters: results['vf_closeness'] = len([x for x in meta if x[helpers.IS_VF_CLOSENESS] == 1]) if 'random_walk_vf_closeness' in filters: results['random_walk_vf_closeness'] = len([x for x in meta if x[helpers.RANDOM_WALK_VF_CLOSENESS_ROUTE] == 1]) if 'lp_soft_prelabeled' in filters: results['lp_soft_prelabeled'] = len([x for x in meta if x[helpers.IS_LP_SOFT_PRELABELED] == 1]) if 'lp_hard_prelabeled' in filters: results['lp_hard_prelabeled'] = len([x for x in meta if x[helpers.IS_LP_HARD_PRELABELED] == 1]) if 'lp_soft_degree' in filters: results['lp_soft_degree'] = len([x for x in meta if x[helpers.IS_LP_SOFT_DEGREE] == 1]) if 'lp_hard_degree' in filters: results['lp_hard_degree'] = len([x for x in meta if x[helpers.IS_LP_HARD_DEGREE] == 1]) if 'lp_soft_closeness' in filters: results['lp_soft_closeness'] = len([x for x in meta if x[helpers.IS_LP_SOFT_CLOSENESS] == 1]) if 'lp_hard_closeness' in filters: results['lp_hard_closeness'] = len([x for x in meta if x[helpers.IS_LP_HARD_CLOSENESS] == 1]) if 'pred' in filters: # SH prediction sh_pred = len([x for x in meta if x[helpers.SH_LEN] == x[helpers.TRACE_LEN]]) # only VF with 1 extra hop ppvf_pred = len([x for x in meta if x[helpers.TRACE_LEN] <= x[helpers.SH_LEN] + 1 and x[helpers.IS_VF_DEGREE] == 1]) # SH or VF with one extra hop smart_pred = len([x for x in meta if x[helpers.SH_LEN] == x[helpers.TRACE_LEN] or (x[helpers.TRACE_LEN] <= x[helpers.SH_LEN] + 1 and x[helpers.IS_VF_DEGREE] == 1)]) # Brute force prediction all_pred = len([x for x in meta if x[helpers.TRACE_LEN] <= x[helpers.SH_LEN] + 1]) results['sh_pred'] = sh_pred results['ppvf_pred'] = ppvf_pred results['smart_pred'] = smart_pred results['all_pred'] = all_pred return results
def purify(g, meta, top_nodes, show_progress): progress = progressbar1.DummyProgressBar(end=10, width=15) if show_progress: progress = progressbar1.AnimatedProgressBar(end=len(meta), width=15) logger.info('Purify') triplet_count_closeness = 0 top_nodes_triplet_closeness = 0 triplet_count_prelabeled = 0 top_nodes_triplet_prelabeled = 0 triplet_count_degree = 0 top_nodes_triplet_degree = 0 for row in meta: progress += 1 progress.show_progress() trace = row[helpers.TRACE] trace = vft.trace_in_vertex_id(g, [trace, ])[0] if row[helpers.IS_VF_CLOSENESS] == 0: logger.debug('Closeness valley') vt = vft.get_valley_triplets(g, trace, vft.CLOSENESS) triplet_count_closeness += len(vt) for trip in vt: if any([x in top_nodes for x in trip]): top_nodes_triplet_closeness += 1 if row[helpers.IS_VF_PRELABELED] == 0: logger.debug('Prelabeled valley') vt = vft.get_valley_triplets(g, trace, vft.PRELABELED) triplet_count_prelabeled += len(vt) for trip in vt: if any([x in top_nodes for x in trip]): top_nodes_triplet_prelabeled += 1 if row[helpers.IS_VF_DEGREE] == 0: logger.debug('Degree valley') vt = vft.get_valley_triplets(g, trace, vft.DEGREE) triplet_count_degree += len(vt) for trip in vt: if any([x in top_nodes for x in trip]): top_nodes_triplet_degree += 1 print try: ratio_closeness = top_nodes_triplet_closeness / float(triplet_count_closeness) except ZeroDivisionError: ratio_closeness = 0.0 try: ratio_prelabeled = top_nodes_triplet_prelabeled / float(triplet_count_prelabeled) except ZeroDivisionError: ratio_prelabeled = 0.0 try: ratio_degree = top_nodes_triplet_degree / float(triplet_count_degree) except ZeroDivisionError: ratio_degree = 0.0 logger.info('CLOSENESS: %6.3f[%d/%d]' % (ratio_closeness, top_nodes_triplet_closeness, triplet_count_closeness)) logger.info('PRELABELED: %6.3f[%d/%d]' % (ratio_prelabeled, top_nodes_triplet_prelabeled, triplet_count_prelabeled)) logger.info('DEGREE: %6.3f[%d/%d]' % (ratio_degree, top_nodes_triplet_degree, triplet_count_degree))
def purify(g, meta_original, out, count=1000, try_per_race=1, show_progress=False): empty = 0 # remove traces with already calculated random paths logger.warn('[r]ONLY NOT FILLED PATHS[/]') meta_filled = [ x for x in meta_original if helpers.RANDOM_NONVF_WALK_RUN_COUNT not in x ] logger.info('All trace count: %d' % len(meta_filled)) tr_count = min(len(meta_filled), count) meta_random = random.sample(meta_filled, tr_count) logger.info('Chosen subset count: %d' % len(meta_random)) real_vf_degree = [x for x in meta_random if x[helpers.IS_VF_DEGREE] == 1] real_nonvf_degree = [ x for x in meta_random if x[helpers.IS_VF_DEGREE] == 0 ] assert len(real_nonvf_degree) == tr_count - len(real_vf_degree) real_vf_prelabeled = [ x for x in meta_random if x[helpers.IS_VF_PRELABELED] == 1 ] real_nonvf_prelabeled = [ x for x in meta_random if x[helpers.IS_VF_PRELABELED] == 0 ] assert len(real_nonvf_prelabeled) == tr_count - len(real_vf_prelabeled) real_vf_closeness = [ x for x in meta_random if x[helpers.IS_VF_CLOSENESS] == 1 ] real_nonvf_closeness = [ x for x in meta_random if x[helpers.IS_VF_CLOSENESS] == 0 ] assert len(real_nonvf_closeness) == tr_count - len(real_vf_closeness) logger.info('Real vf degree: %f[%d]' % ((len(real_vf_degree) / float(tr_count), len(real_vf_degree)))) logger.info( 'Real nonvf degree: %f[%d]' % ((len(real_nonvf_degree) / float(tr_count), len(real_nonvf_degree)))) logger.info( 'Real vf prelabeled: %f[%d]' % ((len(real_vf_prelabeled) / float(tr_count), len(real_vf_prelabeled)))) logger.info('Real nonvf prelabeled: %f[%d]' % ((len(real_nonvf_prelabeled) / float(tr_count), len(real_nonvf_prelabeled)))) logger.info( 'Real vf closeness: %f[%d]' % ((len(real_vf_closeness) / float(tr_count), len(real_vf_closeness)))) logger.info('Real nonvf closeness: %f[%d]' % ((len(real_nonvf_closeness) / float(tr_count), len(real_nonvf_closeness)))) progress = progressbar1.DummyProgressBar(end=10, width=15) if show_progress: progress = progressbar1.AnimatedProgressBar(end=len(meta_random), width=15) for trace_meta in meta_random: progress += 1 progress.show_progress() trace = vft.trace_in_vertex_id(g, [ trace_meta[helpers.TRACE], ]) if len(trace) != 1: logger.error('PROBLEM') logger.error('%s' % trace_meta) continue trace = trace[0] random_nonvf_walk_closeness_route_count = 0 random_nonvf_walk_closeness_route_len = [] random_nonvf_walk_degree_route_count = 0 random_nonvf_walk_degree_route_len = [] random_nonvf_walk_prelabeled_route_count = 0 random_nonvf_walk_prelabeled_route_len = [] random_nonvf_walk_lp_soft_closeness_route_count = 0 random_nonvf_walk_lp_soft_degree_route_count = 0 random_nonvf_walk_lp_soft_prelabeled_route_count = 0 random_nonvf_walk_lp_hard_closeness_route_count = 0 random_nonvf_walk_lp_hard_degree_route_count = 0 random_nonvf_walk_lp_hard_prelabeled_route_count = 0 s, t = trace[0], trace[-1] for counter in xrange(0, try_per_race): isvf, random_path = helpers.random_nonvf_route( g, s, t, len(trace), vfmode=vft.CLOSENESS) assert len(random_path) > 0 if isvf: random_nonvf_walk_closeness_route_count += 1 lp_soft = vft.is_local_preferenced(g, trace, first_edge=True, vfmode=vft.CLOSENESS) lp_hard = vft.is_local_preferenced(g, trace, first_edge=False, vfmode=vft.CLOSENESS) if lp_soft: random_nonvf_walk_lp_soft_closeness_route_count += 1 if lp_hard: random_nonvf_walk_lp_hard_closeness_route_count += 1 random_nonvf_walk_closeness_route_len.append(len(random_path)) isvf, random_path = helpers.random_nonvf_route(g, s, t, len(trace), vfmode=vft.DEGREE) assert len(random_path) > 0 if isvf: random_nonvf_walk_degree_route_count += 1 lp_soft = vft.is_local_preferenced(g, trace, first_edge=True, vfmode=vft.DEGREE) lp_hard = vft.is_local_preferenced(g, trace, first_edge=False, vfmode=vft.DEGREE) if lp_soft: random_nonvf_walk_lp_soft_degree_route_count += 1 if lp_hard: random_nonvf_walk_lp_hard_degree_route_count += 1 random_nonvf_walk_degree_route_len.append(len(random_path)) isvf, random_path = helpers.random_nonvf_route( g, s, t, len(trace), vfmode=vft.PRELABELED) assert len(random_path) > 0 if isvf: random_nonvf_walk_prelabeled_route_count += 1 lp_soft = vft.is_local_preferenced(g, trace, first_edge=True, vfmode=vft.PRELABELED) lp_hard = vft.is_local_preferenced(g, trace, first_edge=False, vfmode=vft.PRELABELED) if lp_soft: random_nonvf_walk_lp_soft_prelabeled_route_count += 1 if lp_hard: random_nonvf_walk_lp_hard_prelabeled_route_count += 1 random_nonvf_walk_prelabeled_route_len.append(len(random_path)) # sanity check # if random_path[0] != s or random_path[-1] != t: # logger.error('ALERT') if len(random_path) != len(set(random_path)): logger.error('LENGTH ERROR') extra_meta = { helpers.RANDOM_NONVF_WALK_RUN_COUNT: try_per_race, helpers.RANDOM_NONVF_WALK_VF_CLOSENESS_ROUTE: random_nonvf_walk_closeness_route_count, helpers.RANDOM_NONVF_WALK_VF_CLOSENESS_ROUTE_LEN: random_nonvf_walk_closeness_route_len, helpers.RANDOM_NONVF_WALK_VF_DEGREE_ROUTE: random_nonvf_walk_degree_route_count, helpers.RANDOM_NONVF_WALK_VF_DEGREE_ROUTE_LEN: random_nonvf_walk_degree_route_len, helpers.RANDOM_NONVF_WALK_VF_PRELABELED_ROUTE: random_nonvf_walk_prelabeled_route_count, helpers.RANDOM_NONVF_WALK_VF_PRELABELED_ROUTE_LEN: random_nonvf_walk_prelabeled_route_len, helpers.RANDOM_NONVF_WALK_LP_SOFT_DEGREE_ROUTE: random_nonvf_walk_lp_soft_degree_route_count, helpers.RANDOM_NONVF_WALK_LP_SOFT_CLOSENESS_ROUTE: random_nonvf_walk_lp_soft_closeness_route_count, helpers.RANDOM_NONVF_WALK_LP_SOFT_PRELABELED_ROUTE: random_nonvf_walk_lp_soft_prelabeled_route_count, helpers.RANDOM_NONVF_WALK_LP_HARD_DEGREE_ROUTE: random_nonvf_walk_lp_hard_degree_route_count, helpers.RANDOM_NONVF_WALK_LP_HARD_CLOSENESS_ROUTE: random_nonvf_walk_lp_hard_closeness_route_count, helpers.RANDOM_NONVF_WALK_LP_HARD_PRELABELED_ROUTE: random_nonvf_walk_lp_hard_prelabeled_route_count } trace_meta.update(extra_meta) ## save modified meta # all meta_* get only references from meta_original helpers.save_to_json(out, meta_original) # calculate results real_vf = [x[helpers.IS_VF_CLOSENESS] for x in meta_random] real_vf_ratio = np.mean(real_vf) random_nonvf_walk_vf_ratio_per_element = [ x[helpers.RANDOM_NONVF_WALK_VF_CLOSENESS_ROUTE] / x[helpers.RANDOM_NONVF_WALK_RUN_COUNT] for x in meta_random ] random_nonvf_walk_vf_ratio = np.mean( random_nonvf_walk_vf_ratio_per_element) # print results logger.info('') logger.info('Empty: %d' % empty) logger.info('Tested trace count: %d' % len(meta_random)) logger.info('VF ratio in tested traces: %f' % real_vf_ratio) logger.info('VF ratio in random walks: %f' % random_nonvf_walk_vf_ratio)