diffprivlib.mechanisms.transforms
¶
Transform wrappers for differential privacy mechanisms to extend their use to alternative data types.
Notes
The naming convention for new transforms is to describe the pre-transform action, i.e. the action performed on the data to be ingested by the mechanism. For transforms without a pre-transform, the post-transform action should be described.
Base class¶
- class diffprivlib.mechanisms.transforms.DPTransformer(parent)[source]¶
Base class for DP transformers. DP Transformers are simple wrappers for DP Mechanisms to allow mechanisms to be used with data types and structures outside their scope.
A
DPTransformer
must be initiated with aDPMachine
(either anotherDPTransformer
, or aDPMechanism
). This allows many instances ofDPTransformer
to be chained together, but the chain must terminate with aDPMechanism
.- copy()¶
Produces a copy of the class.
- Returns
self – Returns the copy.
- Return type
class
- post_transform(value)[source]¶
Performs no transformation on the output of the mechanism, and is returned as-is.
Type casting transforms¶
- class diffprivlib.mechanisms.transforms.IntToString(parent)[source]¶
IntToString DP transformer, for using integer-valued data with string-valued mechanisms.
Useful when using integer-valued data with
Binary
orExponential
.
- class diffprivlib.mechanisms.transforms.StringToInt(parent)[source]¶
StringToInt DP transformer, for using string-valued data with integer-valued mechanisms.
Useful when using ordered, string-valued data with
Geometric
.- post_transform(value)[source]¶
Transforms the output of the mechanism to be string-valued.
- Parameters
value (float or string) – Mechanism output to be transformed.
- Returns
Transformed output value.
- Return type
string
Other transforms¶
- class diffprivlib.mechanisms.transforms.RoundedInteger(parent)[source]¶
Rounded integer transform. Rounds the (float) output of the given mechanism to the nearest integer.
- post_transform(value)[source]¶
Transforms the (float) output of the mechanism to be a rounded integer.
- pre_transform(value)¶
Performs no transformation on the input data, and is ingested by the mechanism as-is.