trasgodp.numerical package¶
Module contents¶
DP mechanisms for numerical columns with clipped results.
- trasgodp.numerical.dp_clip_gaussian(df: DataFrame, column: str, epsilon: float, delta=0.001, lower_bound=None, upper_bound=None, new_column=False) DataFrame¶
Apply the Gaussian mechanism to a dataframe numeric column and clip the result.
- Parameters:
df (pandas dataframe) – dataframe with the data under study.
columm (string) – column to which the DP mechanism will be applied.
epsilon (float) – privacy budget.
delta (float) – probability of exceeding the privacy budget.
lower_bound (float) – lower bound for clipping and calculating the sensitivity.
upper_bound (float) – upper bound for clipping and calculating the sensitivity.
new_column (boolean) – boolean, default to False. If False, the new values obtained with the mechanims applied are stored in the same column. If True, a new column ‘dp_{column}’ is created with the new values.
- Returns:
dataframe with the column transformed applying the mechanism.
- Return type:
pandas dataframe.
- trasgodp.numerical.dp_clip_gaussian_array(data: List | ndarray, epsilon: float, delta=0.001, lower_bound=None, upper_bound=None) ndarray¶
Apply the Gaussian mechanism to a list or numpy array.
- Parameters:
data (list or numpy array) – dataset with the data under study.
epsilon (float) – privacy budget.
delta (float) – probability of exceeding the privacy budget.
lower_bound (float) – lower bound for clipping and calculating the sensitivity.
upper_bound (float) – upper bound for clipping and calculating the sensitivity.
- Returns:
array with the data transformed applying the Gaussian mechanism.
- Return type:
numpy array.
- trasgodp.numerical.dp_clip_laplace(df: DataFrame, column: str, epsilon: float, lower_bound=None, upper_bound=None, new_column=False) DataFrame¶
Apply the Laplace mechanism to a dataframe numeric column and clip the result.
- Parameters:
df (pandas dataframe) – dataframe with the data under study.
columm (string) – column to which the DP mechanism will be applied.
epsilon (float) – privacy budget.
lower_bound (float) – lower bound for clipping and calculating the sensitivity.
upper_bound (float) – upper bound for clipping and calculating the sensitivity.
new_column (boolean) – boolean, default to False. If False, the new values obtained with the mechanims applied are stored in the same column. If True, a new column “dp_{column}” is created with the new values.
- Returns:
dataframe with the column transformed applying the mechanism.
- Return type:
pandas dataframe.
- trasgodp.numerical.dp_clip_laplace_array(data: List | ndarray, epsilon: float, lower_bound=None, upper_bound=None) ndarray¶
Apply the Laplace mechanism to a list or numpy array.
- Parameters:
data (list or numpy array) – dataset with the data under study.
epsilon (float) – privacy budget.
lower_bound (float) – lower bound for clipping and calculating the sensitivity.
upper_bound (float) – upper bound for clipping and calculating the sensitivity.
- Returns:
array with the data transformed applying the Laplace mechanism.
- Return type:
numpy array.