Spaces:
Sleeping
Sleeping
| 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 | |