def _break_big_blocks(self, dist_maker: DistanceMetric) -> None: block_copy = self.blocks.copy() for block_id, block_members in enumerate(block_copy): if len(block_members) <= (2 * (self.k + 1)): continue distances = dist_maker.pairwise(self.Xt[block_members, :]) max_dist = np.max(distances) loc_i, loc_j = np.where(distances == max_dist) seed_i = block_members[loc_i[0]] seed_j = block_members[loc_j[0]] members_i = self.knn[seed_i] members_j = [k for k in self.knn[seed_j] if k not in members_i] loners = [ ind for ind, k in enumerate(block_members) if k not in members_i and k not in members_j ] loner_i_dist = distances[loners, loc_i[0]].reshape(-1) loner_j_dist = distances[loners, loc_j[0]].reshape(-1) for i_loner, loner in enumerate(loners): if loner_i_dist[i_loner] <= loner_j_dist[i_loner]: members_i = np.append(members_i, block_members[loner]) else: members_j = np.append(members_j, block_members[loner]) if len(members_j) == 1: neighbor = self.knn[seed_j][1] members_j = np.array([seed_j, neighbor]) members_i = [m for m in members_i if m != neighbor] self.blocks[block_id] = members_i for member in members_i: self.block_membership[member] = block_id self.blocks.append(members_j) for member in members_j: self.block_membership[member] = len(self.blocks) - 1
def cdf_comparison(rerouting_experiment): # Load pre-processed data for path control data3, paco_hist3, rero_hist3, pc3 = load_all_runs(rerouting_experiment) # Load geo information altitude = 1300 min_elev = 40 orbits = 32 sat_per_orbit = 50 inclination = 53 GST_FILE = "data/raw/ixp_geolocation.csv" SRC_FILE = "data/raw/WUP2018-F22-Cities_Over_300K_Annual.csv" sat_pos, gst_pos, src_pos = load_locations(altitude, orbits, sat_per_orbit, inclination, GST_FILE, SRC_FILE) # Distance between cities pairwise_src = DistanceMetric.pairwise( DistanceMetric.get_metric("haversine"), src_pos, src_pos) pairwise_src = haversine_to_km(pairwise_src) terr_only = pairwise_src * FIBER_PATH_STRETCH / LIGHT_IN_FIBER gclatency = pairwise_src / LIGHT_IN_FIBER gcbound = pairwise_src / LIGHT_IN_VACUUM gc_hist, buckets = np.histogram(gclatency * 1000, bins=100, range=(0, 120)) gcb_hist, _ = np.histogram(gcbound * 1000, bins=100, range=(0, 120)) terr_hist, _ = np.histogram(terr_only * 1000, bins=100, range=(0, 120)) plt.figure(figsize=(8, 6)) plt.plot(buckets[1:], np.cumsum(gc_hist) / np.sum(gcb_hist), ":", markersize=4, markevery=[50], label="Great-circle fiber-speed", linewidth=3) plt.plot(buckets[1:], np.cumsum(gcb_hist) / np.sum(gcb_hist), ':', markersize=4, markevery=[40], label="Great-circle c-speed", linewidth=3) plt.plot(buckets[1:], np.cumsum(terr_hist) / np.sum(gcb_hist), ':', markersize=4, markevery=[30], label="Great-circle path", linewidth=3) plt.xlabel("One-way latency (ms)") plt.ylabel("CDF") x_axis = data3[10]['paco']['hist'][0][1][:-1] * 1000 paco_avg = np.asarray(paco_hist3) paco_avg = np.average(paco_avg, axis=0) rero_avg = np.asarray(rero_hist3) rero_avg = np.average(rero_avg, axis=0) plt.plot(x_axis, np.cumsum(paco_avg) / np.sum(paco_avg), '-', markersize=4, markevery=[40], label="PaCo avg.", linewidth=3) plt.plot(x_axis, np.cumsum(rero_avg) / np.sum(rero_avg), '-.', markersize=4, markevery=[30], label="ReRo avg.", linewidth=3) plt.legend() plt.xlim(0, 120) plt.ylim(0, 1) # Save figure plt.savefig("figures/paco-rero-cdf.png")
def _shortest_dist_between_cluster(X: DataFrame, dist: DistanceMetric, labels: np.ndarray, label_i: int, label_j: int) -> float: return np.min( dist.pairwise(X[labels == label_i], X[labels == label_j]))
def _cluster_diameter(X: DataFrame, dist: DistanceMetric, labels: np.ndarray, label: int) -> float: return np.max(dist.pairwise(X[labels == label]))
def _sum_distance_in_cluster(X: DataFrame, dist: DistanceMetric, labels: np.ndarray, label: int) -> float: return np.sum(dist.pairwise(X[labels == label]))