Spaces:
Sleeping
Sleeping
File size: 390 Bytes
8972ad7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import numpy as np
def apply_randomized_response(bits: np.ndarray, epsilon: float) -> np.ndarray:
keep_prob = np.exp(epsilon) / (1 + np.exp(epsilon)) # sigmoid fn
# Generate random decisions for each bit
keep_mask = np.random.random(bits.shape) < keep_prob
# For bits we don't keep, flip them
noisy_bits = np.where(keep_mask, bits, 1 - bits)
return noisy_bits
|