1 # Implementations of common functions across these privacy notebooks
3 from random import getrandbits, randint
8 def create_neighbour(x, verbose=False):
9 """ Creates a neighbouring dataset
14 neighbouring dataset to x with 1 random value added or removed
18 np.random.default_rng().shuffle(x2)
20 # Randomly chose whether to add or subtract a value
23 if verbose: print("Subtracting value")
25 x2 = np.append(x2, randint(min(x), max(x)))
26 if verbose: print("Adding value")
30 def print_hline(length):
31 """ Prints a horizontal line
33 length: length of the line in characters
36 Unicode horizontal line printed to console
39 print(u'\u2500' * length)
41 def get_epsilons(max_epsilon, epsilon_step):
42 """ Create array of epsilon values to test using given parameters
44 max_epsilon: maximum epsilon value
45 epsilon_step: step size between epsilons
48 Array of epsilon values to test
51 epsilon_div = 1 / epsilon_step
52 return [i / epsilon_div for i in range(1, int(max_epsilon * epsilon_div))]