def lap(packets, lap_list, eps): g = 0 r = 0 num = -1 i = len(lap_list) g = su.cal_g(i) if i == 1 or i == su.cal_d(i): r = int(laplace.rvs(0, 1 / eps)) else: num = int(log(i, 2)) r = int(laplace.rvs(0, num / eps)) x = lap_list[g][1] + (packets[i][1] - packets[g][1]) + r # print(g, i) if x > 1500: x = 1500 if x < 0: x = 0 n = [packets[-1][0], x, packets[-1][2]] return n, x - packets[-1][1]
def lap_trace(packets, lap_list, eps): # lap_list = [] g = 0 r = 0 num = -1 i = len(lap_list) g = su.cal_g(i) if i == 1 or i == su.cal_d(i): # r = int(np.random.laplace(0, 1/eps)) r = int(laplace.rvs(0, 1 / eps)) else: num = int(log(i, 2)) # r = int(np.random.laplace(0, num/eps)) r = int(laplace.rvs(0, num / eps)) x = lap_list[g] + (packets[i] - packets[g]) + r # print(g, i) # if x > 1500: # x = 1500 if x < 0: x = 0 n = x return n, x - packets[i]