-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTomographySystem.py
More file actions
57 lines (40 loc) · 2.27 KB
/
TomographySystem.py
File metadata and controls
57 lines (40 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import numpy as np
import pandas as pd
from scipy.stats import pearsonr
from MeasurementsHelper import *
ROUTING_MATRIX = np.array([[1, 1, 0], [1, 0, 1], [1, 1, 1]])
def get_perf_object(metric):
if metric is PerfMetric.THROUGHPUT: return ThroughputPerf
if metric is PerfMetric.LOSS_RATIO: return LossPerf
if metric is PerfMetric.RETRANSMISSION_RATIO: return RetransmissionPerf
if metric is PerfMetric.DELAY: return DelayPerf
def get_good_state(perf, threshold, metric):
return get_perf_object(metric).is_state_good(perf, threshold)
def solve_system(y_vals):
return 10 ** np.linalg.solve(ROUTING_MATRIX, np.log10(y_vals))
# V.I.P Note: a tomography system consists of only two paths and not more
class TomographySystem:
def __init__(self, path_pair_perf, metric, interval_size, threshold):
self.path_pair_perf = path_pair_perf
self.interval_size = interval_size
self.threshold = threshold
self.metric = metric
# compute performances at valid intervals
self.sys_perf = path_pair_perf.compute_perfs(interval_size)
self.sys_perf = self.sys_perf[(self.sys_perf.perf_p1 != 0) | (self.sys_perf.perf_p2 != 0)]
# get the path-sets good states
self.sys_perf['state_p1'] = self.sys_perf['perf_p1'].apply(lambda val: get_good_state(val, self.threshold, self.metric))*1
self.sys_perf['state_p2'] = self.sys_perf['perf_p2'].apply(lambda val: get_good_state(val, self.threshold, self.metric))*1
self.sys_perf['state_p1p2'] = self.sys_perf['state_p1'] * self.sys_perf['state_p2']
# compute the correlation coefficient
self.corr_coef = pearsonr(self.sys_perf['state_p1'], self.sys_perf['state_p2'])[0]
# compute the paths probabilities
y_vals = [self.sys_perf['state_p1'].mean(), self.sys_perf['state_p2'].mean(), self.sys_perf['state_p1p2'].mean()]
self.pathsets_probs = {
'prob_p1': to_pct(y_vals[0]), 'prob_p2': to_pct(y_vals[1]), 'prob_p1p2': to_pct(y_vals[2])
}
# solve for link probabilities
x_vals = solve_system(y_vals)
self.links_inferred_probs = {
'prob_lc': to_pct(x_vals[0]), 'prob_lnc1': to_pct(x_vals[1]), 'prob_lnc2': to_pct(x_vals[2])
}